@@ -52,6 +52,8 @@ export const splitListItem = () => (props) => {
5252 // Declare variables that will be used across if-else blocks
5353 let firstList , secondList ;
5454
55+ const marks = state . storedMarks || $from . marks ( ) || [ ] ;
56+
5557 // Check if the list item has multiple paragraphs
5658 const listItemHasMultipleParagraphs = listItemNode . childCount > 1 ;
5759
@@ -119,11 +121,21 @@ export const splitListItem = () => (props) => {
119121 secondList = editor . schema . nodes . orderedList . createAndFill ( parentListNode . attrs , Fragment . from ( secondListItem ) ) ;
120122 } else {
121123 // Simple case: single paragraph, use original logic
122- const firstParagraph = editor . schema . nodes . paragraph . create ( paragraphNode . attrs , beforeCursor ) ;
124+ let firstParagraphContent = beforeCursor ;
125+ if ( marks . length > 0 && beforeCursor . size === 0 ) {
126+ firstParagraphContent = editor . schema . text ( ' ' , marks ) ;
127+ }
128+
129+ const firstParagraph = editor . schema . nodes . paragraph . create ( paragraphNode . attrs , firstParagraphContent ) ;
123130 const firstListItem = editor . schema . nodes . listItem . create ( { ...listItemNode . attrs } , firstParagraph ) ;
124131 firstList = editor . schema . nodes . orderedList . createAndFill ( parentListNode . attrs , Fragment . from ( firstListItem ) ) ;
125132
126- const secondParagraph = editor . schema . nodes . paragraph . create ( paragraphNode . attrs , afterCursor ) ;
133+ let secondParagraphContent = afterCursor ;
134+ if ( marks . length > 0 && afterCursor . size === 0 ) {
135+ secondParagraphContent = editor . schema . text ( ' ' , marks ) ;
136+ }
137+
138+ const secondParagraph = editor . schema . nodes . paragraph . create ( paragraphNode . attrs , secondParagraphContent ) ;
127139 const secondListItem = editor . schema . nodes . listItem . create ( { ...listItemNode . attrs } , secondParagraph ) ;
128140 secondList = editor . schema . nodes . orderedList . createAndFill ( parentListNode . attrs , Fragment . from ( secondListItem ) ) ;
129141 }
@@ -145,7 +157,7 @@ export const splitListItem = () => (props) => {
145157 tr . scrollIntoView ( ) ;
146158
147159 // Retain any marks
148- const marks = state . storedMarks || $from . marks ( ) || [ ] ;
160+ // const marks = state.storedMarks || $from.marks() || [];
149161 if ( marks ?. length ) {
150162 tr . ensureMarks ( marks ) ;
151163 }
0 commit comments