Skip to content

Commit 2401593

Browse files
PR Updates, also fixed AttributedText Markdown serialization bug
1 parent 4598d9d commit 2401593

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

super_editor/lib/src/infrastructure/super_textfield/infrastructure/editing/commands.dart

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class ChangeSelectionCommand extends AttributedTextEditingValueCommand {
2424
_previousComposingRange = previousValue.composingRegion;
2525

2626
return AttributedTextEditingValue(
27-
text: previousValue.text,
27+
text: previousValue.text.copy(),
2828
selection: newSelection,
2929
composingRegion: newComposingRange ?? TextRange.empty,
3030
);
@@ -33,7 +33,7 @@ class ChangeSelectionCommand extends AttributedTextEditingValueCommand {
3333
@override
3434
AttributedTextEditingValue doUndo(AttributedTextEditingValue currentValue) {
3535
return AttributedTextEditingValue(
36-
text: currentValue.text,
36+
text: currentValue.text.copy(),
3737
selection: _previousSelection!,
3838
composingRegion: _previousComposingRange!,
3939
);
@@ -263,15 +263,6 @@ class InsertTextAtOffsetCommand extends AttributedTextEditingValueCommand {
263263
}
264264
}
265265

266-
extension on AttributedText {
267-
AttributedText copy() {
268-
return AttributedText(
269-
text: text,
270-
spans: spans.copy(),
271-
);
272-
}
273-
}
274-
275266
/// Deletes the currently selected text, collapsing the selection to a caret
276267
/// at the selection base.
277268
class DeleteSelectedTextCommand extends AttributedTextEditingValueCommand {
@@ -517,3 +508,12 @@ int _moveCaretForDeletion({
517508
return deleteFrom + (caretOffset - deleteTo);
518509
}
519510
}
511+
512+
extension on AttributedText {
513+
AttributedText copy() {
514+
return AttributedText(
515+
text: text,
516+
spans: spans.copy(),
517+
);
518+
}
519+
}

super_editor/test/super_textfield/infrastructure/editing/event_source_controller_test.dart

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -833,11 +833,24 @@ void main() {
833833

834834
group("deletes text", () {
835835
test("between the caret and the beginning of the line", () {
836-
// TODO:
837-
});
836+
final controller = EventSourcedAttributedTextEditingController(
837+
AttributedTextEditingValue(
838+
text: AttributedText(text: "before the caret:after"),
839+
selection: const TextSelection.collapsed(offset: 16),
840+
),
841+
);
842+
843+
controller.deleteTextOnLineBeforeCaret(textLayout: _FakeTextLayout(["before the caret:after"]));
844+
expect(controller.text.text, ":after");
845+
expect(controller.selection, const TextSelection.collapsed(offset: 0));
838846

839-
test("between the caret and the end of the line", () {
840-
// TODO:
847+
// Undo it.
848+
controller.undo();
849+
expect(controller.text.text, "before the caret:after");
850+
expect(
851+
controller.selection,
852+
const TextSelection.collapsed(offset: 16),
853+
);
841854
});
842855

843856
test("when it's selected", () {
@@ -1138,10 +1151,6 @@ void main() {
11381151
));
11391152
});
11401153
});
1141-
1142-
test("pastes text from clipboard", () {
1143-
// TODO:
1144-
});
11451154
});
11461155
}
11471156

0 commit comments

Comments
 (0)