From 8f7f6e212bfb72ea204b2b5e5ca06870095dfa51 Mon Sep 17 00:00:00 2001 From: datokrat Date: Thu, 20 May 2021 02:18:13 +0200 Subject: [PATCH] fix(undo): undo after pair character input (#1194) * fix #559: undo after pair character input * add comments: execCommand is obsolete * replace "or" clause with "some" to remove duplication Co-authored-by: jeff --- .../athens/views/blocks/textarea_keydown.cljs | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/cljs/athens/views/blocks/textarea_keydown.cljs b/src/cljs/athens/views/blocks/textarea_keydown.cljs index a2c0d04a5e..4ff59cbab5 100644 --- a/src/cljs/athens/views/blocks/textarea_keydown.cljs +++ b/src/cljs/athens/views/blocks/textarea_keydown.cljs @@ -566,19 +566,23 @@ close-pair (get PAIR-CHARS key) lookbehind-char (nth value start nil)] (.. e preventDefault) - + (cond ;; when close char, increment caret index without writing more - (or (= ")" key lookbehind-char) - (= "}" key lookbehind-char) - (= "\"" key lookbehind-char) - (= "]" key lookbehind-char)) (do (setStart target (inc start)) - (swap! state assoc :search/type nil)) + (some #(= % key lookbehind-char) + [")" "}" "\"" "]"]) (do (setStart target (inc start)) + (swap! state assoc :search/type nil)) (= selection "") (let [new-str (str head key close-pair tail) new-idx (inc start)] (swap! state assoc :string/local new-str) - (set! (.-value target) new-str) + ;; execCommand is obsolete: + ;; be wary before updating electron - as chromium might drop support for execCommand + ;; electron 11 - uses chromium < 90(latest) which supports execCommand + (.. js/document (execCommand + "insertText" + false + (str key close-pair))) (set-cursor-position target new-idx) (when (>= (count (:string/local @state)) 4) (let [four-char (subs (:string/local @state) (dec start) (+ start 3)) @@ -592,7 +596,13 @@ (not= selection "") (let [surround-selection (surround selection key) new-str (str head surround-selection tail)] (swap! state assoc :string/local new-str) - (set! (.-value target) new-str) + ;; execCommand is obsolete: + ;; be wary before updating electron - as chromium might drop support for execCommand + ;; electron 11 - uses chromium < 90(latest) which supports execCommand + (.. js/document (execCommand + "insertText" + false + surround-selection)) (set! (.-selectionStart target) (inc start)) (set! (.-selectionEnd target) (inc end)) (let [four-char (str (subs (:string/local @state) (dec start) (inc start))