@@ -11,7 +11,6 @@ const ZR_KEY_END = 13;
1111const ZR_KEY_LEFT = 22 ;
1212const ZR_KEY_RIGHT = 23 ;
1313
14- const ZR_MOD_SHIFT = 1 << 0 ;
1514const ZR_MOD_CTRL = 1 << 1 ;
1615const ZR_MOD_ALT = 1 << 2 ;
1716const ZR_MOD_META = 1 << 3 ;
@@ -44,8 +43,18 @@ function utf8Bytes(s: string): Uint8Array {
4443function edit (
4544 event : ZrevEvent ,
4645 ctx : Readonly < { id : string ; value : string ; cursor : number } > ,
47- ) : ReturnType < typeof applyInputEditEvent > {
48- return applyInputEditEvent ( event , ctx ) ;
46+ ) : Readonly < {
47+ nextValue : string ;
48+ nextCursor : number ;
49+ action ?: Readonly < { id : string ; action : "input" ; value : string ; cursor : number } > ;
50+ } > | null {
51+ const next = applyInputEditEvent ( event , ctx ) ;
52+ if ( ! next ) return null ;
53+ return Object . freeze ( {
54+ nextValue : next . nextValue ,
55+ nextCursor : next . nextCursor ,
56+ ...( next . action ? { action : next . action } : { } ) ,
57+ } ) ;
4958}
5059
5160function routeInputWithFocus (
@@ -296,38 +305,52 @@ describe("input editor contract", () => {
296305 } ) ;
297306 } ) ;
298307
299- test ( "modifier handling: modifiers do not alter supported edit/navigation keys " , ( ) => {
300- const mods = ZR_MOD_SHIFT | ZR_MOD_CTRL | ZR_MOD_ALT | ZR_MOD_META ;
308+ test ( "modifier handling: ctrl changes word movement; non-shift modifiers keep edits deterministic " , ( ) => {
309+ const plainMods = ZR_MOD_ALT | ZR_MOD_META ;
301310
302- const leftWithMods = edit ( keyEvent ( ZR_KEY_LEFT , { mods } ) , {
311+ const leftWithMods = edit ( keyEvent ( ZR_KEY_LEFT , { mods : plainMods } ) , {
303312 id : "input" ,
304313 value : "abcd" ,
305314 cursor : 2 ,
306315 } ) ;
307316 assert . deepEqual ( leftWithMods , { nextValue : "abcd" , nextCursor : 1 } ) ;
308317
309- const rightWithMods = edit ( keyEvent ( ZR_KEY_RIGHT , { mods } ) , {
318+ const rightWithMods = edit ( keyEvent ( ZR_KEY_RIGHT , { mods : plainMods } ) , {
310319 id : "input" ,
311320 value : "abcd" ,
312321 cursor : 2 ,
313322 } ) ;
314323 assert . deepEqual ( rightWithMods , { nextValue : "abcd" , nextCursor : 3 } ) ;
315324
316- const homeWithMods = edit ( keyEvent ( ZR_KEY_HOME , { mods } ) , {
325+ const homeWithMods = edit ( keyEvent ( ZR_KEY_HOME , { mods : plainMods } ) , {
317326 id : "input" ,
318327 value : "abcd" ,
319328 cursor : 3 ,
320329 } ) ;
321330 assert . deepEqual ( homeWithMods , { nextValue : "abcd" , nextCursor : 0 } ) ;
322331
323- const endWithMods = edit ( keyEvent ( ZR_KEY_END , { mods } ) , {
332+ const endWithMods = edit ( keyEvent ( ZR_KEY_END , { mods : plainMods } ) , {
324333 id : "input" ,
325334 value : "abcd" ,
326335 cursor : 1 ,
327336 } ) ;
328337 assert . deepEqual ( endWithMods , { nextValue : "abcd" , nextCursor : 4 } ) ;
329338
330- const backspaceWithMods = edit ( keyEvent ( ZR_KEY_BACKSPACE , { mods } ) , {
339+ const ctrlLeft = edit ( keyEvent ( ZR_KEY_LEFT , { mods : ZR_MOD_CTRL } ) , {
340+ id : "input" ,
341+ value : "hello world" ,
342+ cursor : 11 ,
343+ } ) ;
344+ assert . deepEqual ( ctrlLeft , { nextValue : "hello world" , nextCursor : 6 } ) ;
345+
346+ const ctrlRight = edit ( keyEvent ( ZR_KEY_RIGHT , { mods : ZR_MOD_CTRL } ) , {
347+ id : "input" ,
348+ value : "hello world" ,
349+ cursor : 0 ,
350+ } ) ;
351+ assert . deepEqual ( ctrlRight , { nextValue : "hello world" , nextCursor : 5 } ) ;
352+
353+ const backspaceWithMods = edit ( keyEvent ( ZR_KEY_BACKSPACE , { mods : plainMods } ) , {
331354 id : "input" ,
332355 value : "abcd" ,
333356 cursor : 2 ,
@@ -338,7 +361,7 @@ describe("input editor contract", () => {
338361 action : { id : "input" , action : "input" , value : "acd" , cursor : 1 } ,
339362 } ) ;
340363
341- const deleteWithMods = edit ( keyEvent ( ZR_KEY_DELETE , { mods } ) , {
364+ const deleteWithMods = edit ( keyEvent ( ZR_KEY_DELETE , { mods : plainMods } ) , {
342365 id : "input" ,
343366 value : "abcd" ,
344367 cursor : 1 ,
@@ -349,7 +372,7 @@ describe("input editor contract", () => {
349372 action : { id : "input" , action : "input" , value : "acd" , cursor : 1 } ,
350373 } ) ;
351374
352- const keyUpBubbles = edit ( keyEvent ( ZR_KEY_LEFT , { mods, action : "up" } ) , {
375+ const keyUpBubbles = edit ( keyEvent ( ZR_KEY_LEFT , { mods : plainMods , action : "up" } ) , {
353376 id : "input" ,
354377 value : "abcd" ,
355378 cursor : 2 ,
0 commit comments