From fe6417407e152f63678c749f0058cf8a787a7aeb Mon Sep 17 00:00:00 2001 From: charlie Date: Thu, 8 May 2025 00:07:50 +0800 Subject: [PATCH] fix(ui): incorrect select blocks behavior for the block editing mode --- src/main/frontend/components/block.cljs | 31 +++++++++++++++---------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/main/frontend/components/block.cljs b/src/main/frontend/components/block.cljs index 5db1d6b9f4..54600d27bf 100644 --- a/src/main/frontend/components/block.cljs +++ b/src/main/frontend/components/block.cljs @@ -3355,19 +3355,24 @@ (prn ::unhandled-drop-data-transfer-type transfer-types)))))) (block-drag-end event *move-to')) +(defonce *block-last-mouse-event (atom nil)) + (defn- block-mouse-over - [e block *control-show? block-id doc-mode?] - (when-not (or @*dragging? (= (:block/uuid block) (:block/uuid (state/get-edit-block)))) - (.preventDefault e) - (reset! *control-show? true) - (when-let [parent (gdom/getElement block-id)] - (let [node (.querySelector parent ".bullet-container")] - (when doc-mode? - (dom/remove-class! node "hide-inner-bullet")))) - (when (non-dragging? e) - (when-let [container (gdom/getElement "app-container-wrapper")] - (dom/add-class! container "blocks-selection-mode")) - (editor-handler/highlight-selection-area! block-id {:append? true})))) + [^js e block *control-show? block-id doc-mode?] + (let [mouse-moving? (not= (some-> @*block-last-mouse-event (.-clientY)) (.-clientY e))] + (when (and mouse-moving? + (not @*dragging?) + (not= (:block/uuid block) (:block/uuid (state/get-edit-block)))) + (.preventDefault e) + (reset! *control-show? true) + (when-let [parent (gdom/getElement block-id)] + (let [node (.querySelector parent ".bullet-container")] + (when doc-mode? + (dom/remove-class! node "hide-inner-bullet")))) + (when (non-dragging? e) + (when-let [container (gdom/getElement "app-container-wrapper")] + (dom/add-class! container "blocks-selection-mode")) + (editor-handler/highlight-selection-area! block-id {:append? true}))))) (defn- block-mouse-leave [*control-show? block-id doc-mode?] @@ -3608,6 +3613,8 @@ (block-handler/on-touch-cancel *show-left-menu? *show-right-menu?)) :on-mouse-enter (fn [e] (block-mouse-over e block *control-show? block-id doc-mode?)) + :on-mouse-move (fn [e] + (reset! *block-last-mouse-event e)) :on-mouse-leave (fn [_e] (block-mouse-leave *control-show? block-id doc-mode?))}