Explorar o código

enhance(editor): restore scroll position new adding newline in a block

Andelf %!s(int64=2) %!d(string=hai) anos
pai
achega
812f8ac8ba
Modificáronse 1 ficheiros con 8 adicións e 2 borrados
  1. 8 2
      src/main/frontend/handler/editor.cljs

+ 8 - 2
src/main/frontend/handler/editor.cljs

@@ -2224,10 +2224,16 @@
            s1 (subs value 0 selected-start)
            s2 (subs value selected-end)]
        (state/set-edit-content! (state/get-edit-input-id)
-                                (str s1 insertion s2))
-       (cursor/move-cursor-to input (+ selected-start (count insertion)))))))
+                                (str s1 insertion))
+       ;; HACK: save scroll-pos of current pos, then add trailing content
+       (let [scroll-pos (.-scrollTop (gdom/getElement "main-content-container"))]
+         (state/set-edit-content! (state/get-edit-input-id)
+                                  (str s1 insertion s2))
+         (cursor/move-cursor-to input (+ selected-start (count insertion)))
+         (set! (.-scrollTop (gdom/getElement "main-content-container")) scroll-pos))))))
 
 (defn- keydown-new-line
+  "Insert newline to current cursor position"
   []
   (insert "\n"))