fix: only restore last editor's position if it's the same block

This commit is contained in:
Tienson Qin
2022-04-21 20:41:38 +08:00
parent dd92e10b96
commit 4eec369740
3 changed files with 12 additions and 9 deletions

View File

@@ -175,12 +175,15 @@
(defn restore-cursor-pos!
[id markup]
(when-let [node (gdom/getElement (str id))]
(when-let [cursor-range (state/get-cursor-range)]
(when-let [range cursor-range]
(let [pos (state/get-editor-last-pos)
pos (or pos (diff/find-position markup range))]
(cursor/move-cursor-to node pos)
(state/clear-editor-last-pos!))))))
(let [last-edit-block (state/get-last-edit-block)
current-edit-block (state/get-edit-block)]
(when-let [cursor-range (state/get-cursor-range)]
(when-let [range cursor-range]
(let [pos (when (= (:db/id last-edit-block) (:db/id current-edit-block))
(state/get-editor-last-pos))
pos (or pos (diff/find-position markup range))]
(cursor/move-cursor-to node pos)
(state/clear-editor-last-pos!)))))))
(defn highlight-block!
[block-uuid]