fix: cursor moved to the beginning of the editing block when indent

Resolved #924
pull/927/head
Tienson Qin 2020-12-15 11:03:04 +08:00
parent 9de1f01db8
commit 97239cde65
2 changed files with 17 additions and 11 deletions

View File

@ -607,12 +607,17 @@
(editor-handler/close-autocomplete-if-outside input)))))))) (editor-handler/close-autocomplete-if-outside input))))))))
{:did-mount (fn [state] {:did-mount (fn [state]
(let [[{:keys [dummy? format block-parent-id]} id] (:rum/args state) (let [[{:keys [dummy? format block-parent-id]} id] (:rum/args state)
content (get-in @state/state [:editor/content id])] content (get-in @state/state [:editor/content id])
input (gdom/getElement id)]
(when block-parent-id (when block-parent-id
(state/set-editing-block-dom-id! block-parent-id)) (state/set-editing-block-dom-id! block-parent-id))
(editor-handler/restore-cursor-pos! id content dummy?) (if (= :indent-outdent (state/get-editor-op))
(when input
(when-let [pos (state/get-edit-pos)]
(util/set-caret-pos! input pos)))
(editor-handler/restore-cursor-pos! id content dummy?))
(when-let [input (gdom/getElement id)] (when input
(dnd/subscribe! (dnd/subscribe!
input input
:upload-images :upload-images

View File

@ -2433,14 +2433,15 @@
;; block/uuid and block/content ;; block/uuid and block/content
(defn get-all-block-contents (defn get-all-block-contents
[] []
(->> (d/datoms (get-conn) :avet :block/uuid) (when-let [conn (get-conn)]
(map :v) (->> (d/datoms conn :avet :block/uuid)
(map (fn [id] (map :v)
(let [e (entity [:block/uuid id])] (map (fn [id]
{:db/id (:db/id e) (let [e (entity [:block/uuid id])]
:block/uuid id {:db/id (:db/id e)
:block/content (:block/content e) :block/uuid id
:block/format (:block/format e)}))))) :block/content (:block/content e)
:block/format (:block/format e)}))))))
(defn get-all-templates (defn get-all-templates
[] []