Skip to content

Commit 1c46db8

Browse files
committed
fix list item node view update, apply marks for new items
1 parent e4acb71 commit 1c46db8

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

packages/super-editor/src/core/commands/splitListItem.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

packages/super-editor/src/extensions/list-item/ListItemNodeView.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,19 @@ export class ListItemNodeView {
127127
// ie: open a modal to customize numbering
128128
};
129129

130+
update(node, decorations) {
131+
this.node = node;
132+
this.decorations = decorations;
133+
134+
const { fontSize, fontFamily } = getTextStyleMarksFromLinkedStyles({
135+
node,
136+
pos: this.getPos(),
137+
editor: this.editor,
138+
});
139+
this.dom.style.fontSize = fontSize;
140+
this.dom.style.fontFamily = fontFamily || 'inherit';
141+
}
142+
130143
destroy() {
131144
// Unregister this node view
132145
activeListItemNodeViews.delete(this);

0 commit comments

Comments
 (0)