Skip to content
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

[SuperEditor] Limit tag expansion to caret position (Resolves #2240, #2241, #2242) #2387

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

angelosilvestre
Copy link
Collaborator

@angelosilvestre angelosilvestre commented Oct 29, 2024

[SuperEditor] Limit tag expansion to caret position. Resolves #2240, #2241, #2242

Steps to reproduce:

  1. Go to the "Action Tags" section of the example app
  2. Type some text
  3. Place the cursor in the middle of the text
  4. Type "/"
  5. Press backspace
  6. Type "/" again

The editor crashes with the following exception:

════════ Exception caught by services library ══════════════════════════════════
The following _Exception was thrown during method call TextInputClient.updateEditingStateWithDeltas:
Exception: removeAttribution() did not satisfy start < 0 and start > end, start: 6, end: 5

When the exception was thrown, this was the stack:
#0      AttributedSpans.removeAttribution (package:attributed_text/src/attributed_spans.dart:514:7)
attributed_spans.dart:514
#1      RemoveTextAttributionsCommand.execute (package:super_editor/src/default_editor/text.dart:1439:15)
text.dart:1439
#2      _DocumentEditorCommandExecutor.executeCommand (package:super_editor/src/core/editor.dart:701:15)
editor.dart:701
#3      Editor._executeCommand (package:super_editor/src/core/editor.dart:304:22)
editor.dart:304
#4      Editor.execute (package:super_editor/src/core/editor.dart:266:30)
editor.dart:266
#5      ActionTagComposingReaction._healCancelledTags (package:super_editor/src/default_editor/text_tokenizing/action_tags.dart:364:23)
action_tags.dart:364
#6      ActionTagComposingReaction.react (package:super_editor/src/default_editor/text_tokenizing/action_tags.dart:286:5)
action_tags.dart:286
#7      Editor._reactToChanges (package:super_editor/src/core/editor.dart:357:16)
editor.dart:357
#8      Editor.endTransaction (package:super_editor/src/core/editor.dart:222:5)
editor.dart:222
... many more

While investigating this, I noticed that typing "/" at the middle of the word causes all the text that comes after the "/" to be part of the action tag:

Screen.Recording.2024-10-29.at.20.23.32.mov

This doesn't look like is expected.

This PR changes this behavior. Now, the tag is expanded only until the caret position:

Screen.Recording.2024-10-29.at.20.25.46.mov

Changing this seems to already fix the issue, and also #2241 and #2242

@angelosilvestre
Copy link
Collaborator Author

@alterhuman @KevinBrendel Would you mind trying this PR?

@alterhuman
Copy link

@angelosilvestre thanks for the PR

Working correctly:

  • Not crashing when deleting and adding a slash in the middle of a word.
  • Automatically cancelling after a space
  • Matching action only till caret position

Issues:

  1. Moving caret behind the / while still being on the same word doesn't cancel the dropdown. To reproduce:
  • Type Some Information
  • Add / after o: So/me Information
  • Dropdown shows up, move caret behind /, the dropdown hides, then move it again infront of the / the dropdown is visible again but it should've cancelled.
  1. Action tag dropdown popping up after reopening a document and focus the caret on the text containing the tag rule /, after the slash. To reproduce:
  • Instead of having an empty document add this text:
_document = MutableDocument(nodes: [
      ParagraphNode(
        id: Editor.createNodeId(),
        text: AttributedText("Some Infor/mation"),
      ),
    ]);
  • Focus caret at n, the dropdown pops up.

@angelosilvestre
Copy link
Collaborator Author

@alterhuman I fixed the first issue you mentioned. For the second issue, I'm not sure I followed. It doesn't seem to be related to any of the existing issues.

@alterhuman
Copy link

alterhuman commented Oct 31, 2024

@angelosilvestre tested the first issue, it's working correctly. This is the video of second issue, this text is already present in the document when it is opened:

Screen.Recording.2024-10-31.at.6.16.39.PM.mov

Focusing on a word which already has a / inside it when you open the editor, shows the dropdown with the value being the text between / and the caret. This should only happen when I type a slash till the time it's cancelled. It's also happening on opening an editor and then focusing the caret near a word which already has a slash.

@angelosilvestre
Copy link
Collaborator Author

@alterhuman Is this happening on latest main? It doesn't look like it's related to the changes of this PR. If so, can you file a separate issue for this?

@alterhuman
Copy link

@angelosilvestre yes this is also happening on main. Will file a separate issue for this. All good for this PR.

@angelosilvestre angelosilvestre changed the title [SuperEditor] Limit tag expansion to caret position (Resolves #2240) [SuperEditor] Limit tag expansion to caret position (Resolves #2240, #2241, #2242) Oct 31, 2024
@@ -10,11 +10,15 @@ import 'package:super_editor/src/default_editor/text.dart';
class TagFinder {
/// Finds a tag that touches the given [expansionPosition] and returns that tag,
/// indexed within the document, along with the [expansionPosition].
///
/// If [endPosition] is provided, the search will be limited to the range between
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand this description of endPosition. This method was intended to only look for tags that touch expansionPosition, which is a singular position. There shouldn't be a range involved. So the idea of an endPosition doesn't make sense to me.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So should we keep this method as it was before and modify the reaction to adjust the reported tag?

Copy link
Contributor

Choose a reason for hiding this comment

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

My point was that I don't know what you're trying to do here because it doesn't seem to make sense. I can't answer that question until I first understand what exactly you were trying to do.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What I'm trying to do is to prevent the tag to expand beyond the caret position. For example, if we have the string "helloworld" and the user types a "/" at the middle, changing it to "hello/world", the string "world" shouldn't be attributed as a tag. The user can input a tag in the middle of a word, but the tag shouldn't expand beyond the caret position.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] - Exception when deleting composing action tag, then starting new one
3 participants