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 @@ -2,6 +2,7 @@ import 'dart:math';

import 'package:attributed_text/attributed_text.dart';
import 'package:characters/characters.dart';
import 'package:collection/collection.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:super_editor/src/core/document.dart';
Expand Down Expand Up @@ -326,6 +327,17 @@ class ActionTagComposingReaction extends EditReaction {
return;
}

final hasComposingTagAttribution = textNode!.text
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we not already checking for an existing composing tag around the user's selection?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We check if there is a text that matches a tag pattern, but not if it is already attributed.

.getAttributionSpansInRange(
attributionFilter: (attribution) => attribution == actionTagComposingAttribution,
range: SpanRange(tagAroundPosition.indexedTag.startOffset, tagAroundPosition.indexedTag.endOffset),
)
.isNotEmpty;
if (changeList.none((event) => event is DocumentEdit) && !hasComposingTagAttribution) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we wait so long to do this check? Can't we do this check at the very beginning before all this other stuff?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can move it to the beginning, because we need to let the code that clears the attributions when the user presses ESC run.

// The user is neither typing nor moving the caret within an existing composing tag.
return;
}

_updateComposingTag(requestDispatcher, tagAroundPosition.indexedTag);
editorContext.composingActionTag.value = tagAroundPosition.indexedTag;
_onUpdateComposingActionTag(tagAroundPosition.indexedTag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,63 @@ void main() {
// Ensure that we received a notification when the tag was cancelled.
expect(tagNotificationCount, 7);
});

testWidgetsOnAllPlatforms("does not start composing when placing the caret at an existing tag pattern",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is what the original ticket was about, was it? Isn't the issue about the surrounding text, not the user taping to place the caret?

Your example here says "origin/main" - but even if the user was typing, do we expect the "/" to trigger an action tag with "origin" immediately upstream? Maybe we want that for action tags, but I know we don't for "@" mentions or "#" tags....

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is what the original ticket was about, was it? Isn't the issue about the surrounding text, not the user taping to place the caret?

No, that was other ticket. This ticket is about initializing the editor with an existing document that contains text that matches the tag pattern. Tapping at such text shouldn't start a tag composition.

(tester) async {
await _pumpTestEditor(
tester,
MutableDocument(
nodes: [
ParagraphNode(
id: "1",
text: AttributedText("This is origin/main branch"),
),
],
),
);

// Place the caret at "mai|n".
await tester.placeCaretInParagraph("1", 18);

// Ensure that we are not composing a tag.
final text = SuperEditorInspector.findTextInComponent("1");
expect(
text.getAttributionSpansInRange(
attributionFilter: (attribution) => attribution == actionTagComposingAttribution,
range: const SpanRange(0, 26),
),
isEmpty,
);
});

testWidgetsOnAllPlatforms("updates composing when moving the caret within an existing composing tag",
(tester) async {
await _pumpTestEditor(
tester,
singleParagraphEmptyDoc(),
);
await tester.placeCaretInParagraph("1", 0);

// Compose an action tag.
await tester.typeImeText("/header");

// Ensure that the tag has a composing attribution.
final textBefore = SuperEditorInspector.findTextInComponent("1");
expect(
textBefore.getAttributedRange({actionTagComposingAttribution}, 0),
const SpanRange(0, 6),
);

// Press the left arrow to move the caret within the tag.
await tester.pressLeftArrow();

// Ensure that the tag was updated.
final textAfter = SuperEditorInspector.findTextInComponent("1");
expect(
textAfter.getAttributedRange({actionTagComposingAttribution}, 0),
const SpanRange(0, 5),
);
});
});

group("submissions >", () {
Expand Down
Loading