mirror of https://github.com/logseq/logseq
perf: remove editor esc-save
parent
2e29918478
commit
c752e2964b
|
@ -715,6 +715,26 @@
|
||||||
:else
|
:else
|
||||||
nil)))
|
nil)))
|
||||||
|
|
||||||
|
(defn- editor-on-blur
|
||||||
|
[_e]
|
||||||
|
(cond
|
||||||
|
(contains?
|
||||||
|
#{:commands :block-commands
|
||||||
|
:page-search :page-search-hashtag :block-search :template-search
|
||||||
|
:property-search :property-value-search
|
||||||
|
:datepicker}
|
||||||
|
(state/get-editor-action))
|
||||||
|
(state/clear-editor-action!) ;; FIXME: This should probably be handled as a keydown handler in editor, but this handler intercepts Esc first
|
||||||
|
|
||||||
|
;; editor/input component handles Escape directly, so just prevent handling it here
|
||||||
|
(= :input (state/get-editor-action))
|
||||||
|
nil
|
||||||
|
|
||||||
|
:else
|
||||||
|
(let [{:keys [on-hide value]} (editor-handler/get-state)]
|
||||||
|
(when on-hide
|
||||||
|
(on-hide value nil)))))
|
||||||
|
|
||||||
(rum/defcs box < rum/reactive
|
(rum/defcs box < rum/reactive
|
||||||
{:init (fn [state]
|
{:init (fn [state]
|
||||||
(assoc state ::id (str (random-uuid))))
|
(assoc state ::id (str (random-uuid))))
|
||||||
|
@ -724,7 +744,7 @@
|
||||||
(mixins/event-mixin setup-key-listener!)
|
(mixins/event-mixin setup-key-listener!)
|
||||||
(shortcut/mixin :shortcut.handler/block-editing-only)
|
(shortcut/mixin :shortcut.handler/block-editing-only)
|
||||||
lifecycle/lifecycle
|
lifecycle/lifecycle
|
||||||
[state {:keys [format block parent-block]} id config]
|
[state {:keys [format block parent-block on-hide]} id config]
|
||||||
(let [content (state/sub-edit-content (:block/uuid block))
|
(let [content (state/sub-edit-content (:block/uuid block))
|
||||||
heading-class (get-editor-style-class block content format)
|
heading-class (get-editor-style-class block content format)
|
||||||
opts (cond->
|
opts (cond->
|
||||||
|
@ -735,7 +755,16 @@
|
||||||
:on-click (editor-handler/editor-on-click! id)
|
:on-click (editor-handler/editor-on-click! id)
|
||||||
:on-change (editor-handler/editor-on-change! block id search-timeout)
|
:on-change (editor-handler/editor-on-change! block id search-timeout)
|
||||||
:on-paste (paste-handler/editor-on-paste! id)
|
:on-paste (paste-handler/editor-on-paste! id)
|
||||||
:auto-focus false
|
:on-blur (fn [e]
|
||||||
|
(if-let [on-blur (:on-blur config)]
|
||||||
|
(on-blur e)
|
||||||
|
(editor-on-blur e)))
|
||||||
|
:on-key-down (fn [e]
|
||||||
|
(if-let [on-key-down (:on-key-down config)]
|
||||||
|
(on-key-down e)
|
||||||
|
(when (and (= (util/ekey e) "Escape") on-hide)
|
||||||
|
(on-hide content :esc))))
|
||||||
|
:auto-focus true
|
||||||
:class heading-class}
|
:class heading-class}
|
||||||
(some? parent-block)
|
(some? parent-block)
|
||||||
(assoc :parentblockid (str (:block/uuid parent-block)))
|
(assoc :parentblockid (str (:block/uuid parent-block)))
|
||||||
|
|
|
@ -1,38 +0,0 @@
|
||||||
(ns ^:no-doc frontend.handler.editor.keyboards
|
|
||||||
(:require [frontend.handler.editor :as editor-handler]
|
|
||||||
[frontend.mixins :as mixins]
|
|
||||||
[frontend.state :as state]
|
|
||||||
[goog.dom :as gdom]))
|
|
||||||
|
|
||||||
;; TODO: don't depend on handler.editor
|
|
||||||
|
|
||||||
(defn esc-save! [state]
|
|
||||||
(let [id (nth (:rum/args state) 1)]
|
|
||||||
(mixins/hide-when-esc-or-outside
|
|
||||||
state
|
|
||||||
:on-hide
|
|
||||||
(fn [_state e event]
|
|
||||||
(cond
|
|
||||||
(contains?
|
|
||||||
#{:commands :block-commands
|
|
||||||
:page-search :page-search-hashtag :block-search :template-search
|
|
||||||
:property-search :property-value-search
|
|
||||||
:datepicker}
|
|
||||||
(state/get-editor-action))
|
|
||||||
(state/clear-editor-action!) ;; FIXME: This should probably be handled as a keydown handler in editor, but this handler intercepts Esc first
|
|
||||||
|
|
||||||
;; editor/input component handles Escape directly, so just prevent handling it here
|
|
||||||
(= :input (state/get-editor-action))
|
|
||||||
nil
|
|
||||||
|
|
||||||
(some-> (.-target e)
|
|
||||||
(.closest ".ls-keep-editing-when-outside-click"))
|
|
||||||
nil
|
|
||||||
|
|
||||||
:else
|
|
||||||
(let [{:keys [on-hide value]} (editor-handler/get-state)]
|
|
||||||
(when on-hide
|
|
||||||
(on-hide value event)))))
|
|
||||||
:node (gdom/getElement id)
|
|
||||||
;; :visibilitychange? true
|
|
||||||
)))
|
|
|
@ -1,6 +1,5 @@
|
||||||
(ns ^:no-doc frontend.handler.editor.lifecycle
|
(ns ^:no-doc frontend.handler.editor.lifecycle
|
||||||
(:require [frontend.handler.editor :as editor-handler]
|
(:require [frontend.handler.editor :as editor-handler]
|
||||||
[frontend.handler.editor.keyboards :as keyboards-handler]
|
|
||||||
[frontend.state :as state]
|
[frontend.state :as state]
|
||||||
[frontend.util :as util]
|
[frontend.util :as util]
|
||||||
[frontend.util.cursor :as cursor]
|
[frontend.util.cursor :as cursor]
|
||||||
|
@ -24,10 +23,8 @@
|
||||||
(when content
|
(when content
|
||||||
(editor-handler/restore-cursor-pos! id content)))
|
(editor-handler/restore-cursor-pos! id content)))
|
||||||
|
|
||||||
(keyboards-handler/esc-save! state)
|
|
||||||
|
|
||||||
(when-let [element (gdom/getElement id)]
|
(when-let [element (gdom/getElement id)]
|
||||||
(.focus element)
|
;; TODO: check whether editor is visible, do less work
|
||||||
(js/setTimeout #(util/scroll-editor-cursor element) 50)))
|
(js/setTimeout #(util/scroll-editor-cursor element) 50)))
|
||||||
state)
|
state)
|
||||||
|
|
||||||
|
@ -40,7 +37,6 @@
|
||||||
(when-let [input (state/get-input)]
|
(when-let [input (state/get-input)]
|
||||||
(util/set-change-value input
|
(util/set-change-value input
|
||||||
(block-handler/sanity-block-content repo (get new-block :block/format :markdown) (:block/content new-block))))))
|
(block-handler/sanity-block-content repo (get new-block :block/format :markdown) (:block/content new-block))))))
|
||||||
(keyboards-handler/esc-save! state)
|
|
||||||
state)
|
state)
|
||||||
|
|
||||||
(defn will-unmount
|
(defn will-unmount
|
||||||
|
|
Loading…
Reference in New Issue