Skip to content

Commit e8bddda

Browse files
scheinrieseclaude
authored andcommitted
fix(shortcut): limit prefix-conflict detection to same-handler only
Cross-handler prefix overlaps don't cause chord dormancy because each Closure KeyboardShortcutHandler instance has its own independent key tree and state machine. Only same-handler prefix conflicts (where Closure's tree can't have a node be both leaf and branch) cause actual chord dormancy. - Change binding-match? to use same-handler? instead of handler-match? for prefix overlaps (exact matches still use handler-match?) - Update test to verify cross-handler prefixes are NOT detected Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 32d5aaf commit e8bddda

2 files changed

Lines changed: 13 additions & 11 deletions

File tree

src/main/frontend/modules/shortcut/data_helper.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@
243243
(every? #(handlers-co-active? % handler-id') handler-ids)))))
244244
binding-match?
245245
(or (= input-binding k)
246-
(and handler-match?
246+
(and same-handler?
247247
(binding-prefix-overlap? input-binding k)))]
248248
(if (and (not (contains? exclude-ids id))
249249
handler-match?

src/test/frontend/modules/shortcut/core_test.cljs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,22 +114,24 @@
114114
{:exclude-ids #{} :group-global? false})]
115115
(is (false? (dh/conflict-has-exact? conflicts "t"))))))
116116

117-
(deftest test-cross-handler-prefix-detection
118-
(testing "t on global-prevent-default detects cross-handler chord prefix conflicts"
119-
;; With group-global? true, "t" should detect chord conflicts from co-active
120-
;; handlers like global-non-editing-only (which has t d, t t, t r, etc.)
117+
(deftest test-same-handler-prefix-detection
118+
(testing "prefix conflicts are only detected within the same handler"
119+
;; Prefix overlaps only cause chord dormancy on the SAME Closure handler
120+
;; instance. Cross-handler prefixes work fine because each handler has
121+
;; its own independent key tree and state machine.
121122
(let [conflicts (dh/get-conflicts-by-keys
122123
"t" :shortcut.handler/global-prevent-default
123124
{:exclude-ids #{} :group-global? true})
124125
all-keys (->> (vals conflicts) (mapcat vals) (map first) (set))]
125-
;; Same-handler chords (global-prevent-default has t n, t b)
126+
;; Same-handler chords (global-prevent-default has t n, t b) — detected
126127
(is (contains? all-keys "t n"))
127128
(is (contains? all-keys "t b"))
128-
;; Cross-handler chords from co-active global-non-editing-only
129-
(is (contains? all-keys "t d")
130-
"t d from global-non-editing-only should be detected as cross-handler prefix conflict")
131-
(is (contains? all-keys "t r")
132-
"t r from global-non-editing-only should be detected as cross-handler prefix conflict"))))
129+
;; Cross-handler chords from global-non-editing-only — NOT detected
130+
;; because they're on a different handler and still work at runtime
131+
(is (not (contains? all-keys "t d"))
132+
"t d from global-non-editing-only should NOT be detected (cross-handler)")
133+
(is (not (contains? all-keys "t r"))
134+
"t r from global-non-editing-only should NOT be detected (cross-handler)"))))
133135

134136
(deftest test-add-reaction-shortcut
135137
(testing "add reaction shortcut is configured with p r"

0 commit comments

Comments
 (0)