fix: lost editor cursor when pressing Enter to undent

experiment/tanstack-table
Tienson Qin 2024-06-17 15:18:51 +08:00
parent 39c4a160c2
commit b67035bc9b
3 changed files with 9 additions and 7 deletions

View File

@ -2491,15 +2491,16 @@
:block-id uuid
:block-parent-id block-id
:format format
:on-hide (fn [value event]
:on-hide (fn [value event ^js e]
(let [select? (and (= event :esc)
(not (string/includes? value "```")))
edit-next-block? (and @*next-editing-block (not= @*next-editing-block (:block/uuid block)))]
edit-next-block? (and @*next-editing-block (not= @*next-editing-block (:block/uuid block)))
blur-editing? (and (= event :blur) (when e (util/input? (.-relatedTarget e))))]
(when-let [container (gdom/getElement "app-container")]
(dom/remove-class! container "blocks-selection-mode"))
(p/do!
(editor-handler/save-block! repo (:block/uuid block) value)
(when-not (and edit-next-block? (not select?))
(editor-handler/save-block! repo (:block/uuid block) value)
(when-not (and (or edit-next-block? blur-editing?) (not select?))
(editor-handler/escape-editing select?))
(some-> config :on-escape-editing
(apply [(str uuid) (= event :esc)]))

View File

@ -832,7 +832,7 @@
(let [{:keys [on-hide value]} (editor-handler/get-state)]
(when on-hide
(when *blur? (reset! *blur? true))
(on-hide value :blur))))))
(on-hide value :blur e))))))
(rum/defcs box < rum/reactive
{:init (fn [state]
@ -872,7 +872,7 @@
(when (and (= (util/ekey e) "Escape") on-hide)
(when-not (exist-editor-commands-popup?)
(reset! *blur? true)
(on-hide content :esc)))))
(on-hide content :esc e)))))
:auto-focus true
:class heading-class}
(some? parent-block)

View File

@ -173,7 +173,8 @@
(defn- edit-block-aux
[repo block content text-range {:keys [container-id]}]
(when block
(state/clear-edit!)
(when (not= (:db/id block) (:db/id (state/get-edit-block)))
(state/clear-edit!))
(let [container-id (or container-id
(state/get-current-editor-container-id)
:unknown-container)]