@@ -55,6 +55,7 @@ function createEditor(value: string) {
5555 ] ,
5656 content : buildDocJson ( value , ( name ) => ( { label : name , description : null } ) ) ,
5757 } ) ;
58+ // Headless editors need the plugins installed explicitly because there is no mounted view.
5859 editor . view . updateState ( editor . state . reconfigure ( { plugins : editor . extensionManager . plugins } ) ) ;
5960 editor . view . dispatch ( editor . state . tr . setSelection ( TextSelection . atEnd ( editor . state . doc ) ) ) ;
6061 onTestFinished ( ( ) => editor . destroy ( ) ) ;
@@ -219,27 +220,15 @@ describe("composer list normalization", () => {
219220 } ,
220221 ) ;
221222
222- it ( "waits until composition ends before changing paragraph structure" , async ( ) => {
223+ it ( "waits for a non- composition transaction before changing paragraph structure" , ( ) => {
223224 const editor = createEditor ( "" ) ;
224225 editor . view . dispatch ( editor . state . tr . insertText ( "- text" ) . setMeta ( "composition" , 1 ) ) ;
225226 expect ( editor . state . doc . firstChild ?. type . name ) . toBe ( "paragraph" ) ;
226227 editor . view . dispatch ( editor . state . tr . insertText ( "日本語" , 3 , 7 ) . setMeta ( "composition" , 1 ) ) ;
227228 expect ( editor . state . doc . firstChild ?. type . name ) . toBe ( "paragraph" ) ;
228- const normalization = editor . state . plugins . find (
229- ( plugin ) => plugin . props . handleDOMEvents ?. compositionend && plugin . spec . appendTransaction ,
230- ) ! ;
231- normalization . props . handleDOMEvents ! . compositionend ! . call (
232- normalization ,
233- editor . view ,
234- new Event ( "compositionend" ) as CompositionEvent ,
235- ) ;
236- // ProseMirror flushes the final composition text in a microtask after this event.
237- queueMicrotask ( ( ) => {
238- editor . view . dispatch ( editor . state . tr . insertText ( "確定" , 3 , 6 ) . setMeta ( "composition" , 1 ) ) ;
239- } ) ;
240- await Promise . resolve ( ) ;
229+ editor . view . dispatch ( editor . state . tr . insertText ( "確定" , 3 , 6 ) . setMeta ( "composition" , 1 ) ) ;
241230 expect ( editor . state . doc . firstChild ?. type . name ) . toBe ( "paragraph" ) ;
242- await Promise . resolve ( ) ;
231+ editor . view . dispatch ( editor . state . tr . setSelection ( TextSelection . atEnd ( editor . state . doc ) ) ) ;
243232 expect ( editor . state . doc . firstChild ?. type . name ) . toBe ( "bulletList" ) ;
244233 expect ( serializeEditorDoc ( editor . state . doc ) . value ) . toBe ( "- 確定" ) ;
245234 expect ( undo ( editor . state , editor . view . dispatch ) ) . toBe ( true ) ;
@@ -263,7 +252,7 @@ describe("composer list normalization", () => {
263252
264253 it ( "preserves formatting and the caret when removing the literal prefix" , ( ) => {
265254 const editor = createEditor ( "**text**" ) ;
266- editor . view . dispatch ( editor . state . tr . insertText ( "- " , 1 ) ) ;
255+ editor . view . dispatch ( editor . state . tr . insert ( 1 , editor . schema . text ( "- " ) ) ) ;
267256 expect ( editor . state . selection . $from . parent . type . name ) . toBe ( "paragraph" ) ;
268257 expect ( editor . state . selection . $from . parentOffset ) . toBe ( 4 ) ;
269258 expect ( serializeEditorDoc ( editor . state . doc ) . value ) . toBe ( "- **text**" ) ;
@@ -276,6 +265,21 @@ describe("composer list normalization", () => {
276265 expect ( serializeEditorDoc ( editor . state . doc ) . value ) . toBe ( "`- text`" ) ;
277266 } ) ;
278267
268+ it . each ( [ "**- x**" , "*-* x" , "~~- x~~" , "a\n**1.** b" ] ) (
269+ "preserves styled markers when restoring %j" ,
270+ ( value ) => {
271+ const editor = createEditor ( "" ) ;
272+ editor . commands . setContent (
273+ buildDocJson ( value , ( name ) => ( { label : name , description : null } ) ) ,
274+ { emitUpdate : false } ,
275+ ) ;
276+ expect ( serializeEditorDoc ( editor . state . doc ) . value ) . toBe ( value ) ;
277+ expect ( editor . state . doc . lastChild ?. type . name ) . toBe ( "paragraph" ) ;
278+ editor . view . dispatch ( editor . state . tr . insertText ( "x" , editor . state . doc . content . size - 1 ) ) ;
279+ expect ( editor . state . doc . lastChild ?. type . name ) . toBe ( "paragraph" ) ;
280+ } ,
281+ ) ;
282+
279283 it ( "only normalizes changed blocks" , ( ) => {
280284 const editor = createEditor ( "" ) ;
281285 editor . view . updateState ( editor . state . reconfigure ( { plugins : [ ] } ) ) ;
0 commit comments