@@ -151,6 +151,51 @@ it.each([
151151 expect ( textWithMark ( editor , "code" ) ) . toEqual ( code ) ;
152152} ) ;
153153
154+ it . each ( [
155+ { mark : "bold" , key : "b" , marker : "**" } ,
156+ { mark : "italic" , key : "i" , marker : "*" } ,
157+ ] ) ( "toggles $mark with Mod+$key at a collapsed cursor" , async ( { mark, key, marker } ) => {
158+ await using screen = await mountEditor ( "ship it" ) ;
159+ const { editor } = screen ;
160+ const mod = isMacPlatform ( navigator . platform ) ? "Meta" : "Control" ;
161+ const chord = `{${ mod } >}${ key } {/${ mod } }` ;
162+ await act ( async ( ) => {
163+ editor . commands . focus ( "end" ) ;
164+ } ) ;
165+ await vi . waitFor ( ( ) => expect ( document . activeElement ) . toBe ( editor . view . dom ) ) ;
166+ await userEvent . keyboard ( " " ) ;
167+ await userEvent . keyboard ( chord ) ;
168+ await userEvent . keyboard ( "now" ) ;
169+ await userEvent . keyboard ( chord ) ;
170+ await userEvent . keyboard ( " done" ) ;
171+ await vi . waitFor ( ( ) =>
172+ expect ( serializeEditorDoc ( editor . state . doc ) . value ) . toBe ( `ship it ${ marker } now${ marker } done` ) ,
173+ ) ;
174+ expect ( textWithMark ( editor , mark ) ) . toEqual ( [ "now" ] ) ;
175+ } ) ;
176+
177+ it . each ( [
178+ { key : "i" , caret : 10 , expected : "ship it **n*X*ow** done" } ,
179+ { key : "i" , caret : 9 , expected : "ship it *X***now** done" } ,
180+ { key : "e" , caret : "{ArrowLeft>5/}" , expected : "ship it **now**`X` done" } ,
181+ ] ) (
182+ "Mod+$key at $caret in a bold word styles the next typed text" ,
183+ async ( { key, caret, expected } ) => {
184+ await using screen = await mountEditor ( "ship it **now** done" ) ;
185+ const { editor } = screen ;
186+ const mod = isMacPlatform ( navigator . platform ) ? "Meta" : "Control" ;
187+ await act ( async ( ) => {
188+ if ( typeof caret === "number" ) editor . commands . focus ( caret ) ;
189+ else editor . commands . focus ( "end" ) ;
190+ } ) ;
191+ await vi . waitFor ( ( ) => expect ( document . activeElement ) . toBe ( editor . view . dom ) ) ;
192+ if ( typeof caret === "string" ) await userEvent . keyboard ( caret ) ;
193+ await userEvent . keyboard ( `{${ mod } >}${ key } {/${ mod } }` ) ;
194+ await userEvent . keyboard ( "X" ) ;
195+ await vi . waitFor ( ( ) => expect ( serializeEditorDoc ( editor . state . doc ) . value ) . toBe ( expected ) ) ;
196+ } ,
197+ ) ;
198+
154199it . each ( [
155200 { word : "ship" , prefix : "" , source : [ "**ship**" ] } ,
156201 { word : "path\\" , prefix : "" , source : [ ] } ,
@@ -169,7 +214,7 @@ it.each([
169214 code : [ "path\\" ] ,
170215 } ,
171216] ) (
172- "bolds $word after '$prefix' with Mod+B only when text is selected " ,
217+ "bolds $word after '$prefix' with Mod+B over a selection " ,
173218 async ( { word, prefix, prefixText = prefix , source, code = [ ] } ) => {
174219 const value = `${ prefix } ${ word } it` ;
175220 await using screen = await mountEditor ( value ) ;
@@ -179,10 +224,6 @@ it.each([
179224 editor . commands . focus ( "end" ) ;
180225 } ) ;
181226 await vi . waitFor ( ( ) => expect ( document . activeElement ) . toBe ( editor . view . dom ) ) ;
182- await userEvent . keyboard ( modB ) ;
183- // Without the guard, Tiptap stores bold for the next typed text.
184- expect ( editor . state . storedMarks ) . toBeNull ( ) ;
185-
186227 await act ( async ( ) => {
187228 editor . commands . setTextSelection ( {
188229 from : prefixText . length + 1 ,
0 commit comments