-
Notifications
You must be signed in to change notification settings - Fork 281
[SuperEditor] Don't activate an action tag when placing the caret at an existing tag pattern. (Resolves #2392) #2771
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
|
@@ -326,6 +327,17 @@ class ActionTagComposingReaction extends EditReaction { | |
return; | ||
} | ||
|
||
final hasComposingTagAttribution = textNode!.text | ||
.getAttributionSpansInRange( | ||
attributionFilter: (attribution) => attribution == actionTagComposingAttribution, | ||
range: SpanRange(tagAroundPosition.indexedTag.startOffset, tagAroundPosition.indexedTag.endOffset), | ||
) | ||
.isNotEmpty; | ||
if (changeList.none((event) => event is DocumentEdit) && !hasComposingTagAttribution) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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 >", () { | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.