Skip to content

Commit

Permalink
PR Updates, also fixed AttributedText Markdown serialization bug
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-carroll committed Jul 25, 2022
1 parent 4598d9d commit 2401593
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ChangeSelectionCommand extends AttributedTextEditingValueCommand {
_previousComposingRange = previousValue.composingRegion;

return AttributedTextEditingValue(
text: previousValue.text,
text: previousValue.text.copy(),
selection: newSelection,
composingRegion: newComposingRange ?? TextRange.empty,
);
Expand All @@ -33,7 +33,7 @@ class ChangeSelectionCommand extends AttributedTextEditingValueCommand {
@override
AttributedTextEditingValue doUndo(AttributedTextEditingValue currentValue) {
return AttributedTextEditingValue(
text: currentValue.text,
text: currentValue.text.copy(),
selection: _previousSelection!,
composingRegion: _previousComposingRange!,
);
Expand Down Expand Up @@ -263,15 +263,6 @@ class InsertTextAtOffsetCommand extends AttributedTextEditingValueCommand {
}
}

extension on AttributedText {
AttributedText copy() {
return AttributedText(
text: text,
spans: spans.copy(),
);
}
}

/// Deletes the currently selected text, collapsing the selection to a caret
/// at the selection base.
class DeleteSelectedTextCommand extends AttributedTextEditingValueCommand {
Expand Down Expand Up @@ -517,3 +508,12 @@ int _moveCaretForDeletion({
return deleteFrom + (caretOffset - deleteTo);
}
}

extension on AttributedText {
AttributedText copy() {
return AttributedText(
text: text,
spans: spans.copy(),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -833,11 +833,24 @@ void main() {

group("deletes text", () {
test("between the caret and the beginning of the line", () {
// TODO:
});
final controller = EventSourcedAttributedTextEditingController(
AttributedTextEditingValue(
text: AttributedText(text: "before the caret:after"),
selection: const TextSelection.collapsed(offset: 16),
),
);

controller.deleteTextOnLineBeforeCaret(textLayout: _FakeTextLayout(["before the caret:after"]));
expect(controller.text.text, ":after");
expect(controller.selection, const TextSelection.collapsed(offset: 0));

test("between the caret and the end of the line", () {
// TODO:
// Undo it.
controller.undo();
expect(controller.text.text, "before the caret:after");
expect(
controller.selection,
const TextSelection.collapsed(offset: 16),
);
});

test("when it's selected", () {
Expand Down Expand Up @@ -1138,10 +1151,6 @@ void main() {
));
});
});

test("pastes text from clipboard", () {
// TODO:
});
});
}

Expand Down

0 comments on commit 2401593

Please sign in to comment.