diff --git a/frontend/src/app/main/data/shortcuts.cljs b/frontend/src/app/main/data/shortcuts.cljs index 19a473ae54..fa5e86e547 100644 --- a/frontend/src/app/main/data/shortcuts.cljs +++ b/frontend/src/app/main/data/shortcuts.cljs @@ -204,20 +204,27 @@ (defn- bind! [shortcuts] - (->> shortcuts - (remove #(:disabled (second %))) - (run! (fn [[key {:keys [command fn type overwrite]}]] - (let [callback (wrap-cb key fn) - commands (if (vector? command) - (into-array command) - #js [command])] - (if (vector? type) - (do (mousetrap/bind commands callback (nth type 0) overwrite) - (mousetrap/bind commands callback (nth type 1) overwrite)) - (let [undefined (js* "(void 0)")] - (if type - (mousetrap/bind commands callback type overwrite) - (mousetrap/bind commands callback undefined overwrite))))))))) + (let [entries (remove #(:disabled (second %)) shortcuts) + bind-fn (fn [[key {:keys [command fn type overwrite]}]] + (let [callback (wrap-cb key fn) + commands (if (vector? command) + (into-array command) + #js [command])] + (if (vector? type) + (do (mousetrap/bind commands callback (nth type 0) overwrite) + (mousetrap/bind commands callback (nth type 1) overwrite)) + (let [undefined (js* "(void 0)")] + (if type + (mousetrap/bind commands callback type overwrite) + (mousetrap/bind commands callback undefined overwrite))))))] + ;; Bind non-overwrite entries first so that entries flagged with + ;; `:overwrite` are bound last and can reliably splice out the + ;; colliding callbacks bound earlier (mousetrap's overwrite only + ;; removes callbacks that were already registered for the same + ;; combo). Map iteration order is hash-based, so we must force the + ;; order explicitly. + (run! bind-fn (remove (comp :overwrite second) entries)) + (run! bind-fn (filter (comp :overwrite second) entries)))) (defn- reset! ([] diff --git a/frontend/src/app/main/data/workspace/path/shortcuts.cljs b/frontend/src/app/main/data/workspace/path/shortcuts.cljs index fe35b33e40..f4ed3dd8f3 100644 --- a/frontend/src/app/main/data/workspace/path/shortcuts.cljs +++ b/frontend/src/app/main/data/workspace/path/shortcuts.cljs @@ -37,6 +37,7 @@ :command "p" :subsections [:path-editor] :section [:workspace] + :overwrite true :fn #(st/emit! (drp/change-edit-mode :draw))} :add-node {:tooltip (ds/shift "+") @@ -49,7 +50,9 @@ :command ["del" "backspace"] :subsections [:path-editor] :section [:workspace] - :fn #(st/emit! (drp/remove-node))} + :overwrite true + :fn #(st/emit! + (drp/remove-node))} :merge-nodes {:tooltip (ds/meta "J") :command (ds/c-mod "j") @@ -67,6 +70,7 @@ :command "k" :subsections [:path-editor] :section [:workspace] + :overwrite true :fn #(st/emit! (drp/separate-nodes))} :make-corner {:tooltip "X" @@ -79,6 +83,7 @@ :command "c" :subsections [:path-editor] :section [:workspace] + :overwrite true :fn #(st/emit! (drp/make-curve))} :snap-nodes {:tooltip (ds/meta "'") @@ -91,6 +96,7 @@ :escape {:tooltip (ds/esc) :command ["escape" "enter" "v"] :section [:workspace] + :overwrite true :fn #(st/emit! (esc-pressed))} :undo {:tooltip (ds/meta "Z")