Skip to content

Commit 2d36218

Browse files
Cherry Pick: [SuperEditor] - Fix: Action tag exception when pressing ESC, then typing characters. (Resolves #2177) (#2232)
1 parent 27f13ee commit 2d36218

File tree

3 files changed

+8
-26
lines changed

3 files changed

+8
-26
lines changed

super_editor/lib/src/default_editor/text.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1429,7 +1429,7 @@ class RemoveTextAttributionsCommand extends EditCommand {
14291429
nodesAndSelections.putIfAbsent(textNode, () => selectionRange);
14301430
}
14311431

1432-
// Add attributions.
1432+
// Remove attributions.
14331433
for (final entry in nodesAndSelections.entries) {
14341434
for (Attribution attribution in attributions) {
14351435
final node = entry.key;

super_editor/lib/src/default_editor/text_tokenizing/action_tags.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ class CancelComposingActionTagCommand extends EditCommand {
256256
AddTextAttributionsCommand(
257257
documentRange: textNode.selectionBetween(
258258
composingToken.indexedTag.startOffset,
259-
composingToken.indexedTag.endOffset,
259+
composingToken.indexedTag.startOffset + 1,
260260
),
261261
attributions: {actionTagCancelledAttribution},
262262
),

super_editor/test/super_editor/text_entry/tagging/action_tags_test.dart

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -455,13 +455,13 @@ void main() {
455455
await tester.placeCaretInParagraph("1", 7);
456456

457457
// Start composing a tag.
458-
await tester.typeImeText("/");
458+
await tester.typeImeText("/stuff");
459459

460460
// Ensure that we're composing.
461461
var text = SuperEditorInspector.findTextInComponent("1");
462462
expect(
463463
text.getAttributedRange({actionTagComposingAttribution}, 7),
464-
const SpanRange(7, 7),
464+
const SpanRange(7, 12),
465465
);
466466

467467
// Cancel composing.
@@ -472,7 +472,7 @@ void main() {
472472
expect(
473473
text.getAttributionSpansInRange(
474474
attributionFilter: (attribution) => attribution == actionTagComposingAttribution,
475-
range: const SpanRange(0, 7),
475+
range: const SpanRange(0, 12),
476476
),
477477
isEmpty,
478478
);
@@ -482,33 +482,15 @@ void main() {
482482
);
483483

484484
// Start typing again.
485-
await tester.typeImeText("h");
486-
487-
// Ensure that we didn't start composing again.
488-
text = SuperEditorInspector.findTextInComponent("1");
489-
expect(text.text, "before /h");
490-
expect(
491-
text.getAttributionSpansInRange(
492-
attributionFilter: (attribution) => attribution == actionTagComposingAttribution,
493-
range: const SpanRange(0, 8),
494-
),
495-
isEmpty,
496-
);
497-
expect(
498-
text.getAttributedRange({actionTagCancelledAttribution}, 7),
499-
const SpanRange(7, 7),
500-
);
501-
502-
// Add a space, cause the tag to end.
503485
await tester.typeImeText(" ");
504486

505-
// Ensure that the cancelled tag wasn't submitted, and didn't start composing again.
487+
// Ensure that we didn't start composing again.
506488
text = SuperEditorInspector.findTextInComponent("1");
507-
expect(text.text, "before /h ");
489+
expect(text.text, "before /stuff ");
508490
expect(
509491
text.getAttributionSpansInRange(
510492
attributionFilter: (attribution) => attribution == actionTagComposingAttribution,
511-
range: const SpanRange(0, 9),
493+
range: const SpanRange(0, 13),
512494
),
513495
isEmpty,
514496
);

0 commit comments

Comments
 (0)