From be9654da948cfce2b1bd060a50c6cdc67db0a51e Mon Sep 17 00:00:00 2001 From: Giuseppe D'Andrea Date: Sun, 21 May 2023 11:45:15 +0200 Subject: [PATCH] enhance: delete selected text when pressing enter --- src/main/frontend/handler/editor.cljs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/frontend/handler/editor.cljs b/src/main/frontend/handler/editor.cljs index fe254dc6c0..cc4555e536 100644 --- a/src/main/frontend/handler/editor.cljs +++ b/src/main/frontend/handler/editor.cljs @@ -407,10 +407,10 @@ (save-block-inner! block value opts))))))) (defn- compute-fst-snd-block-text - [value pos] + [value selection-start selection-end] (when (string? value) - (let [fst-block-text (subs value 0 pos) - snd-block-text (string/triml (subs value pos))] + (let [fst-block-text (subs value 0 selection-start) + snd-block-text (string/triml (subs value selection-end))] [fst-block-text snd-block-text]))) (declare save-current-block!) @@ -471,8 +471,9 @@ :as _opts}] (let [block-self? (block-self-alone-when-insert? config uuid) input (gdom/getElement (state/get-edit-input-id)) - pos (cursor/pos input) - [fst-block-text snd-block-text] (compute-fst-snd-block-text value pos) + selection-start (util/get-selection-start input) + selection-end (util/get-selection-end input) + [fst-block-text snd-block-text] (compute-fst-snd-block-text value selection-start selection-end) current-block (assoc block :block/content fst-block-text) current-block (apply dissoc current-block db-schema/retract-attributes) current-block (wrap-parse-block current-block) @@ -526,8 +527,9 @@ block) block-self? (block-self-alone-when-insert? config block-id) input (gdom/getElement (state/get-edit-input-id)) - pos (cursor/pos input) - [fst-block-text snd-block-text] (compute-fst-snd-block-text value pos) + selection-start (util/get-selection-start input) + selection-end (util/get-selection-end input) + [fst-block-text snd-block-text] (compute-fst-snd-block-text value selection-start selection-end) insert-fn (cond block-self? insert-new-block-aux!