@@ -94,6 +94,15 @@ describe('GlobalCommandsProvider owned-shortcut yielding', () => {
9494} )
9595
9696describe ( 'GlobalCommandsProvider editable guard' , ( ) => {
97+ /**
98+ * jsdom does not implement `isContentEditable`, so stub the browser's computed
99+ * editability on the element the test focuses.
100+ */
101+ function focusWithEditability ( element : HTMLElement , isContentEditable : boolean ) {
102+ Object . defineProperty ( element , 'isContentEditable' , { value : isContentEditable } )
103+ element . focus ( )
104+ }
105+
97106 it ( 'skips a non-editable command when focus is in an input' , ( ) => {
98107 const handler = vi . fn ( )
99108 mount (
@@ -115,9 +124,25 @@ describe('GlobalCommandsProvider editable guard', () => {
115124 < div contentEditable />
116125 </ GlobalCommandsProvider >
117126 )
118- ; ( container . querySelector ( '[contenteditable]' ) as HTMLElement ) . focus ( )
127+ focusWithEditability ( container . querySelector ( '[contenteditable]' ) as HTMLElement , true )
128+ pressModK ( )
129+ expect ( handler ) . not . toHaveBeenCalled ( )
130+ } )
131+
132+ it ( 'skips a non-editable command when focus is on a descendant of a contenteditable root' , ( ) => {
133+ const handler = vi . fn ( )
134+ mount (
135+ < GlobalCommandsProvider >
136+ < RegisterModKOutsideEditable handler = { handler } />
137+ < div contentEditable >
138+ { /* biome-ignore lint/a11y/noNoninteractiveTabindex: focusable stand-in for a node view inside the editor */ }
139+ < span tabIndex = { 0 } />
140+ </ div >
141+ </ GlobalCommandsProvider >
142+ )
143+ focusWithEditability ( container . querySelector ( 'span' ) as HTMLElement , true )
119144 pressModK ( )
120- expect ( handler ) . toHaveBeenCalledTimes ( 0 )
145+ expect ( handler ) . not . toHaveBeenCalled ( )
121146 } )
122147
123148 it ( 'fires a non-editable command when focus is in a contenteditable="false" element' , ( ) => {
@@ -129,7 +154,7 @@ describe('GlobalCommandsProvider editable guard', () => {
129154 < div contentEditable = { false } tabIndex = { 0 } />
130155 </ GlobalCommandsProvider >
131156 )
132- ; ( container . querySelector ( '[contenteditable]' ) as HTMLElement ) . focus ( )
157+ focusWithEditability ( container . querySelector ( '[contenteditable]' ) as HTMLElement , false )
133158 pressModK ( )
134159 expect ( handler ) . toHaveBeenCalledTimes ( 1 )
135160 } )
0 commit comments