Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions package/components/editor-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,18 @@ export const useEditorToolbar = ({
});
};
updateMarkStates();
// Only update mark states on selection changes — not every transaction.
// Text input transactions don't change which marks are active at the cursor.
// Update on selection changes and when storedMarks change (e.g. toggling
// bold on an empty paragraph, or after sink/lift restructures the doc).
editor.on('selectionUpdate', updateMarkStates);
const onTransaction = ({ transaction }: { transaction: any }) => {
if (transaction.storedMarksSet) {
updateMarkStates();
}
};
editor.on('transaction', onTransaction);
return () => {
editor.off('selectionUpdate', updateMarkStates);
editor.off('transaction', onTransaction);
};
}, [editor]);

Expand Down
32 changes: 22 additions & 10 deletions package/extensions/d-block/dblock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,22 @@ export const DBlock = Node.create<DBlockOptions>({
const node = $from.node(d);

if (node.type.name === 'listItem') {
// Try to sink the list item
// If it's the first item, sinkListItem will return false and nothing happens
// Preserve active marks before sinking — sinkListItem restructures
// the document which clears storedMarks, causing formatting loss.
const marks = editor.state.storedMarks || selection.$from.marks();
editor.commands.sinkListItem('listItem');

// Always return true to prevent browser Tab behavior
if (marks.length) {
editor.view.dispatch(editor.state.tr.setStoredMarks(marks));
}
return true;
}

if (node.type.name === 'taskItem') {
// Try to sink the task item
// If it's the first item, sinkListItem will return false and nothing happens
const marks = editor.state.storedMarks || selection.$from.marks();
editor.commands.sinkListItem('taskItem');

// Always return true to prevent browser Tab behavior
if (marks.length) {
editor.view.dispatch(editor.state.tr.setStoredMarks(marks));
}
return true;
}
}
Expand Down Expand Up @@ -198,10 +200,20 @@ export const DBlock = Node.create<DBlockOptions>({
const node = $from.node(d);

if (node.type.name === 'listItem') {
return editor.commands.liftListItem('listItem');
const marks = editor.state.storedMarks || $from.marks();
const result = editor.commands.liftListItem('listItem');
if (marks.length) {
editor.view.dispatch(editor.state.tr.setStoredMarks(marks));
}
return result;
}
if (node.type.name === 'taskItem') {
return editor.commands.liftListItem('taskItem');
const marks = editor.state.storedMarks || $from.marks();
const result = editor.commands.liftListItem('taskItem');
if (marks.length) {
editor.view.dispatch(editor.state.tr.setStoredMarks(marks));
}
return result;
}
}

Expand Down