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
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ KeyEventResult _toggleAttribute(
node.type == HeadingBlockKeys.type &&
node.attributes[HeadingBlockKeys.level] == level;

final delta = (node.delta ?? Delta()).toJson();

editorState.formatNode(
selection,
(node) => node.copyWith(
Expand All @@ -86,7 +84,7 @@ KeyEventResult _toggleAttribute(
node.attributes[blockComponentBackgroundColor],
blockComponentTextDirection:
node.attributes[blockComponentTextDirection],
blockComponentDelta: delta,
blockComponentDelta: (node.delta ?? Delta()).toJson(),
},
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,31 @@ void main() async {
node = editorState.getNodeAtPath([0])!;
expect(node.type, ParagraphBlockKeys.type);
});

test('toggle H1 preserves each selected node text', () {
const firstText = 'First paragraph';
const secondText = 'Second paragraph';
final document = Document.blank()
..addParagraph(initialText: firstText)
..addParagraph(initialText: secondText);

final editorState = EditorState(document: document)
..selection = Selection(
start: Position(path: [0], offset: 0),
end: Position(path: [1], offset: secondText.length),
);

toggleH1.execute(editorState);

final firstNode = editorState.getNodeAtPath([0])!;
final secondNode = editorState.getNodeAtPath([1])!;

expect(firstNode.type, HeadingBlockKeys.type);
expect(secondNode.type, HeadingBlockKeys.type);
expect(firstNode.attributes[HeadingBlockKeys.level], 1);
expect(secondNode.attributes[HeadingBlockKeys.level], 1);
expect(firstNode.delta?.toPlainText(), firstText);
expect(secondNode.delta?.toPlainText(), secondText);
});
});
}
Loading