From 36cb047997d728cb740bd6c1ab2e9860d5e20b0b Mon Sep 17 00:00:00 2001 From: charlie Date: Mon, 19 Aug 2024 12:50:55 +0800 Subject: [PATCH] fix(ui): invalid input for command popups in block editing mode --- src/main/frontend/components/editor.cljs | 9 +- src/main/frontend/handler/editor.cljs | 155 +++++++++--------- .../frontend/modules/shortcut/before.cljs | 8 +- 3 files changed, 87 insertions(+), 85 deletions(-) diff --git a/src/main/frontend/components/editor.cljs b/src/main/frontend/components/editor.cljs index 41078a1270..e0cd7c6f51 100644 --- a/src/main/frontend/components/editor.cljs +++ b/src/main/frontend/components/editor.cljs @@ -456,8 +456,7 @@ ;; escape 27 (fn [_state _e] (let [[id _on-submit on-cancel] (:rum/args state)] - (on-cancel id)))})) - ) + (on-cancel id)))}))) [state _id on-submit _on-cancel] (when-let [action-data (state/get-editor-action-data)] (let [{:keys [pos options]} action-data @@ -465,11 +464,12 @@ (when (seq options) (let [command (:command (first options))] [:div.p-2.rounded-md.flex.flex-col.gap-2 - (for [{:keys [id placeholder type] :as input-item} options] + (for [{:keys [id placeholder type]} options] (shui/input (cond-> {:key (str "modal-input-" (name id)) :type (or type "text") + :auto-complete (if (util/chrome?) "chrome-off" "off") :on-change (fn [e] (swap! input-value assoc id (util/evalue e)))} @@ -480,8 +480,7 @@ :on-click (fn [e] (util/stop e) - (on-submit command @input-value pos))) - ]))))) + (on-submit command @input-value pos)))]))))) (rum/defc image-uploader < rum/reactive [id format] diff --git a/src/main/frontend/handler/editor.cljs b/src/main/frontend/handler/editor.cljs index 330e69a9f4..2090e8e9f0 100644 --- a/src/main/frontend/handler/editor.cljs +++ b/src/main/frontend/handler/editor.cljs @@ -2763,86 +2763,89 @@ (defn keydown-backspace-handler [cut? e] (let [^js input (state/get-input) - id (state/get-edit-input-id) - current-pos (cursor/pos input) - value (gobj/get input "value") - deleted (and (> current-pos 0) - (util/nth-safe value (dec current-pos))) - selected-start (util/get-selection-start input) - selected-end (util/get-selection-end input) - block (state/get-edit-block) - block (db/entity (:db/id block)) - repo (state/get-current-repo) - top-block? (= (:db/id (or (ldb/get-left-sibling block) (:block/parent block))) - (:db/id (:block/page block))) - single-block? (inside-of-single-block (.-target e)) - root-block? (= (:block.temp/container block) (str (:block/uuid block)))] - (block-handler/mark-last-input-time! repo) - (cond - (not= selected-start selected-end) - (do - (util/stop e) - (when cut? - (js/document.execCommand "copy")) - (delete-and-update input selected-start selected-end)) - - (zero? current-pos) - (let [editor-state (get-state) - custom-query? (get-in editor-state [:config :custom-query?])] - (util/stop e) - (when (and (not (and top-block? (not (string/blank? value)))) - (not root-block?) - (not single-block?) - (not custom-query?)) - (if (own-order-number-list? block) - (p/do! - (save-current-block!) - (remove-block-own-order-list-type! block)) - (delete-block! repo)))) - - (and (> current-pos 0) - (contains? #{commands/command-trigger commands/angle-bracket commands/command-ask} - (util/nth-safe value (dec current-pos)))) - (do - (util/stop e) - (commands/restore-state) - (delete-and-update input (dec current-pos) current-pos)) - - ;; pair - (and - deleted - (contains? - (set (keys delete-map)) - deleted) - (>= (count value) (inc current-pos)) - (= (util/nth-safe value current-pos) - (get delete-map deleted))) - - (do - (util/stop e) - (commands/delete-pair! id) + element js/document.activeElement] + (if (= input element) + (let [id (state/get-edit-input-id) + current-pos (cursor/pos input) + value (gobj/get input "value") + deleted (and (> current-pos 0) + (util/nth-safe value (dec current-pos))) + selected-start (util/get-selection-start input) + selected-end (util/get-selection-end input) + block (state/get-edit-block) + block (db/entity (:db/id block)) + repo (state/get-current-repo) + top-block? (= (:db/id (or (ldb/get-left-sibling block) (:block/parent block))) + (:db/id (:block/page block))) + single-block? (inside-of-single-block (.-target e)) + root-block? (= (:block.temp/container block) (str (:block/uuid block)))] + (block-handler/mark-last-input-time! repo) (cond - (and (= deleted "[") (state/get-editor-show-page-search?)) - (state/clear-editor-action!) + (not= selected-start selected-end) + (do + (util/stop e) + (when cut? + (js/document.execCommand "copy")) + (delete-and-update input selected-start selected-end)) - (and (= deleted "(") (state/get-editor-show-block-search?)) - (state/clear-editor-action!) + (zero? current-pos) + (let [editor-state (get-state) + custom-query? (get-in editor-state [:config :custom-query?])] + (util/stop e) + (when (and (not (and top-block? (not (string/blank? value)))) + (not root-block?) + (not single-block?) + (not custom-query?)) + (if (own-order-number-list? block) + (p/do! + (save-current-block!) + (remove-block-own-order-list-type! block)) + (delete-block! repo)))) + (and (> current-pos 0) + (contains? #{commands/command-trigger commands/angle-bracket commands/command-ask} + (util/nth-safe value (dec current-pos)))) + (do + (util/stop e) + (commands/restore-state) + (delete-and-update input (dec current-pos) current-pos)) + + ;; pair + (and + deleted + (contains? + (set (keys delete-map)) + deleted) + (>= (count value) (inc current-pos)) + (= (util/nth-safe value current-pos) + (get delete-map deleted))) + + (do + (util/stop e) + (commands/delete-pair! id) + (cond + (and (= deleted "[") (state/get-editor-show-page-search?)) + (state/clear-editor-action!) + + (and (= deleted "(") (state/get-editor-show-block-search?)) + (state/clear-editor-action!) + + :else + nil)) + + ;; deleting hashtag + (and (= deleted "#") (state/get-editor-show-page-search-hashtag?)) + (do + (state/clear-editor-action!) + (delete-and-update input (dec current-pos) current-pos)) + + ;; just delete :else - nil)) - - ;; deleting hashtag - (and (= deleted "#") (state/get-editor-show-page-search-hashtag?)) - (do - (state/clear-editor-action!) - (delete-and-update input (dec current-pos) current-pos)) - - ;; just delete - :else - (when (and input (not (mobile-util/native-ios?))) - (util/stop e) - (delete-and-update - input (util/safe-dec-current-pos-from-end (.-value input) current-pos) current-pos))))) + (when (and input (not (mobile-util/native-ios?))) + (util/stop e) + (delete-and-update + input (util/safe-dec-current-pos-from-end (.-value input) current-pos) current-pos)))) + false))) (defn indent-outdent [indent?] diff --git a/src/main/frontend/modules/shortcut/before.cljs b/src/main/frontend/modules/shortcut/before.cljs index bf7f6ce72c..138c078ed8 100644 --- a/src/main/frontend/modules/shortcut/before.cljs +++ b/src/main/frontend/modules/shortcut/before.cljs @@ -28,10 +28,10 @@ [f] (fn [e] (when (state/editing?) - (if (mobile-util/native-ios?) - (util/stop-propagation e) - (util/stop e)) - (f e)))) + (when-not (false? (f e)) + (if (mobile-util/native-ios?) + (util/stop-propagation e) + (util/stop e)))))) (defn enable-when-not-component-editing! [f]