From d117b8da338a521658724767ee68e5b2b9585627 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Fri, 11 Aug 2023 11:04:09 +0800 Subject: [PATCH] enhance: backspace moves cursor to the above item --- src/main/frontend/components/property.cljs | 7 +++--- .../frontend/components/property/value.cljs | 23 +++++++++++++++---- .../frontend/handler/db_based/property.cljs | 3 +-- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/main/frontend/components/property.cljs b/src/main/frontend/components/property.cljs index 6f1bfa7bbb..3dc58d17e1 100644 --- a/src/main/frontend/components/property.cljs +++ b/src/main/frontend/components/property.cljs @@ -262,6 +262,9 @@ (db/sub-block (:db/id block)))) (rum/defcs properties-area < rum/reactive + {:init (fn [state] + (assoc state ::blocks-container-id (or (:blocks-container-id (last (:rum/args state))) + (state/next-blocks-container-id))))} [state target-block edit-input-id opts] (let [block (resolve-instance-page-if-exists target-block) properties (if (and (:class-schema? opts) (:block/schema block)) @@ -293,9 +296,7 @@ @(:*configure-show? opts) (empty? properties)) (= edit-input-id (state/sub :ui/new-property-input-id))) - opts (if (:blocks-container-id opts) - opts - (assoc opts :blocks-container-id (state/next-blocks-container-id)))] + opts (assoc opts :blocks-container-id (::blocks-container-id state))] (when-not (and (empty? properties) (not new-property?) (not (:page-configure? opts))) diff --git a/src/main/frontend/components/property/value.cljs b/src/main/frontend/components/property/value.cljs index 9d55b19ada..a60004efad 100644 --- a/src/main/frontend/components/property/value.cljs +++ b/src/main/frontend/components/property/value.cljs @@ -197,11 +197,12 @@ meta? (util/meta-key? e) create-another-one? (and meta? enter?) down? (= (util/ekey e) "ArrowDown") - up? (= (util/ekey e) "ArrowUp")] - (when (and (or enter? esc? create-another-one? down? up?) + up? (= (util/ekey e) "ArrowUp") + backspace? (= (util/ekey e) "Backspace")] + (when (and (or enter? esc? create-another-one? down? up? backspace?) (not (state/get-editor-action))) - (util/stop e) - (when-not blank? + (when-not (or down? up? backspace?) (util/stop e)) + (when (and (not blank?) (or enter? esc?)) (when (not= (string/trim new-value) (string/trim value)) (property-handler/set-block-property! repo (:block/uuid block) (:block/original-name property) @@ -211,6 +212,19 @@ (exit-edit-property) (cond + (and backspace? (= new-value "") (not @*add-new-item?)) ; delete item + (do + (move-cursor true opts) + (property-handler/delete-property-value! repo block (:block/uuid property) value)) + + (and backspace? (= new-value "") @*add-new-item?) + (do + (move-cursor true opts) + (reset! *add-new-item? false)) + + backspace? + nil + down? (move-cursor false opts) @@ -396,6 +410,7 @@ opts {:editor-args editor-args :editor-id editor-id + :idx (count items) :dom-id dom-id :editing? true :*add-new-item? *add-new-item?})) diff --git a/src/main/frontend/handler/db_based/property.cljs b/src/main/frontend/handler/db_based/property.cljs index 48e4823cdf..4600384789 100644 --- a/src/main/frontend/handler/db_based/property.cljs +++ b/src/main/frontend/handler/db_based/property.cljs @@ -265,8 +265,7 @@ {:block/uuid (:block/uuid block) :block/properties properties' :block/refs refs}] - {:outliner-op :save-block})))) - (state/clear-edit!)))))) + {:outliner-op :save-block}))))))))) (defn class-add-property! [repo class k-name]