@@ -191,6 +191,7 @@ describe "KeymapManager", ->
191
191
' .editor.visual-mode' : ' i w' : ' select-inside-word'
192
192
193
193
events = []
194
+ editor .addEventListener ' textInput' , (event ) -> events .push (" input:#{ event .data } " )
194
195
workspace .addEventListener ' dog' , -> events .push (' dog' )
195
196
workspace .addEventListener ' viva!' , -> events .push (' viva!' )
196
197
workspace .addEventListener ' viv' , -> events .push (' viv' )
@@ -222,27 +223,15 @@ describe "KeymapManager", ->
222
223
expect (vEvent .defaultPrevented ).toBe true
223
224
expect (iEvent .defaultPrevented ).toBe true
224
225
expect (kEvent .defaultPrevented ).toBe false
225
- expect (events).toEqual [' enter-visual-mode' ]
226
+ expect (events).toEqual [' enter-visual-mode' , ' input:i ' ]
226
227
expect (clearTimeout).toHaveBeenCalled ()
227
228
228
229
it " dispatches a text-input event for any replayed keyboard events that would have inserted characters" , ->
229
- textInputCharacters = []
230
- editor .addEventListener ' textInput' , (event ) -> textInputCharacters .push (event .data )
231
-
232
- keymapManager .handleKeyboardEvent (buildKeydownEvent (' v' , target : editor))
233
- keymapManager .handleKeyboardEvent (buildKeydownEvent (' i' , target : editor))
234
- keymapManager .handleKeyboardEvent (lastEvent = buildKeydownEvent (' k' , target : editor))
235
-
236
- expect (textInputCharacters).toEqual [' i' ]
237
- expect (lastEvent .defaultPrevented ).toBe false # inserted as normal
238
-
239
- textInputCharacters = []
240
-
241
230
keymapManager .handleKeyboardEvent (buildKeydownEvent (' d' , target : editor))
242
231
keymapManager .handleKeyboardEvent (buildKeydownEvent (' o' , target : editor))
243
232
keymapManager .handleKeyboardEvent (lastEvent = buildKeydownEvent (' q' , target : editor))
244
233
245
- expect (textInputCharacters ).toEqual [' d' , ' o' ]
234
+ expect (events ).toEqual [' input: d' , ' input: o' ]
246
235
expect (lastEvent .defaultPrevented ).toBe false # inserted as normal
247
236
248
237
describe " when the currently queued keystrokes exactly match at least one binding" , ->
@@ -257,7 +246,7 @@ describe "KeymapManager", ->
257
246
keymapManager .handleKeyboardEvent (buildKeydownEvent (' i' , target : editor))
258
247
expect (events).toEqual []
259
248
advanceClock (keymapManager .getPartialMatchTimeout ())
260
- expect (events).toEqual [' enter-visual-mode' ]
249
+ expect (events).toEqual [' enter-visual-mode' , ' input:i ' ]
261
250
262
251
events = []
263
252
keymapManager .handleKeyboardEvent (buildKeydownEvent (' v' , target : editor))
@@ -275,17 +264,31 @@ describe "KeymapManager", ->
275
264
expect (global .setTimeout ).not .toHaveBeenCalled ()
276
265
expect (keymapManager .queuedKeyboardEvents .length ).toBe 0
277
266
267
+ describe " when the first queued keystroke corresponds to a character insertion" , ->
268
+ it " disables partially-matching bindings and replays the queued keystrokes if the ::partialMatchTimeout expires" , ->
269
+ keymapManager .handleKeyboardEvent (buildKeydownEvent (' d' , target : editor))
270
+ keymapManager .handleKeyboardEvent (buildKeydownEvent (' o' , target : editor))
271
+ advanceClock (keymapManager .getPartialMatchTimeout ())
272
+
273
+ expect (events).toEqual [' input:d' , ' input:o' ]
274
+
278
275
describe " when the currently queued keystrokes don't exactly match any bindings" , ->
279
276
it " never times out of the pending state" , ->
280
- keymapManager .handleKeyboardEvent (buildKeydownEvent (' d' , target : editor))
277
+ keymapManager .add ' test' ,
278
+ ' .workspace' :
279
+ ' ctrl-d o g' : ' control-dog'
280
+
281
+ workspace .addEventListener ' control-dog' , -> events .push (' control-dog' )
282
+
283
+ keymapManager .handleKeyboardEvent (buildKeydownEvent (' ctrl-d' , target : editor))
281
284
keymapManager .handleKeyboardEvent (buildKeydownEvent (' o' , target : editor))
282
285
283
286
advanceClock (keymapManager .getPartialMatchTimeout ())
284
287
advanceClock (keymapManager .getPartialMatchTimeout ())
285
288
286
289
expect (events).toEqual []
287
290
keymapManager .handleKeyboardEvent (buildKeydownEvent (' g' , target : editor))
288
- expect (events).toEqual [' dog' ]
291
+ expect (events).toEqual [' control- dog' ]
289
292
290
293
describe " when the partially matching bindings all map to the 'unset!' directive" , ->
291
294
it " ignores the 'unset!' bindings and invokes the command associated with the matching binding as normal" , ->
@@ -298,6 +301,16 @@ describe "KeymapManager", ->
298
301
299
302
expect (events).toEqual [' enter-visual-mode' ]
300
303
304
+ describe " when a subsequent keystroke begins a new match of an already pending binding" , ->
305
+ it " recognizes the match" , ->
306
+ keymapManager .handleKeyboardEvent (buildKeydownEvent (' d' , target : editor))
307
+ keymapManager .handleKeyboardEvent (buildKeydownEvent (' o' , target : editor))
308
+ keymapManager .handleKeyboardEvent (buildKeydownEvent (' d' , target : editor))
309
+ keymapManager .handleKeyboardEvent (buildKeydownEvent (' o' , target : editor))
310
+ keymapManager .handleKeyboardEvent (buildKeydownEvent (' g' , target : editor))
311
+
312
+ expect (events).toEqual [' input:d' , ' input:o' , ' dog' ]
313
+
301
314
it " only counts entire keystrokes when checking for partial matches" , ->
302
315
element = $$ -> @ div class : ' a'
303
316
keymapManager .add ' test' ,
0 commit comments