From 5a0ceea018d493dd622991cfcbefac63f1c81435 Mon Sep 17 00:00:00 2001 From: Andelf Date: Mon, 15 May 2023 17:53:04 +0800 Subject: [PATCH] enhance(editor): restore scroll position new paste in a long block --- src/main/frontend/commands.cljs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/frontend/commands.cljs b/src/main/frontend/commands.cljs index 0559ed94d5..370375f9ed 100644 --- a/src/main/frontend/commands.cljs +++ b/src/main/frontend/commands.cljs @@ -403,17 +403,23 @@ edit-content (gobj/get input "value") current-pos (cursor/pos input) prefix (subs edit-content 0 current-pos) + surfix (subs edit-content current-pos) new-value (str prefix value - (subs edit-content current-pos)) + surfix) new-pos (- (+ (count prefix) (count value) (or forward-pos 0)) (or backward-pos 0))] - (state/set-block-content-and-last-pos! id new-value new-pos) - (cursor/move-cursor-to input new-pos) - (when check-fn - (check-fn new-value (dec (count prefix)) new-pos)))) + (state/set-edit-content! (state/get-edit-input-id) + (str prefix value)) + ;; HACK: save scroll-pos of current pos, then add trailing content + (let [scroll-pos (.-scrollTop (gdom/getElement "main-content-container"))] + (state/set-block-content-and-last-pos! id new-value new-pos) + (cursor/move-cursor-to input new-pos) + (set! (.-scrollTop (gdom/getElement "main-content-container")) scroll-pos) + (when check-fn + (check-fn new-value (dec (count prefix)) new-pos))))) (defn simple-replace! [id value selected