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

Intelligent highlight #30

Closed
wants to merge 2 commits into from
Closed

Intelligent highlight #30

wants to merge 2 commits into from

Conversation

drooxie
Copy link
Contributor

@drooxie drooxie commented May 24, 2023

Do not update unchanged text errors and move highlighting with text expansion

@drooxie drooxie linked an issue May 24, 2023 that may be closed by this pull request
@drooxie
Copy link
Contributor Author

drooxie commented May 24, 2023

@drooxie
Copy link
Contributor Author

drooxie commented May 24, 2023

there is wrong behavior of highlight after replacing mistake. I'm currently fixing this bug

@drooxie drooxie self-assigned this May 24, 2023
@drooxie
Copy link
Contributor Author

drooxie commented May 24, 2023

Now it works fine in most cases, but sometimes there is hard-reproducible bug occurred.
I will try to dig into this problem and find solution

Comment on lines +75 to +82
_mistakes.removeWhere((mistake) {
final mistakeRange = IntRange(
mistake.offset,
mistake.endOffset,
).toSet();

return selectionRange.intersection(mistakeRange).isNotEmpty;
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Replace with a well-named method:

Suggested change
_mistakes.removeWhere((mistake) {
final mistakeRange = IntRange(
mistake.offset,
mistake.endOffset,
).toSet();
return selectionRange.intersection(mistakeRange).isNotEmpty;
});
_mistakes.removeWhere(_doesMistakeIntersectWithSelection);
    Set<int> get _selectionRange => IntRange(selection.start, selection.end).toSet();
bool _doesMistakeIntersectWithSelection(mistake) {
      final mistakeRange = IntRange(
        mistake.offset,
        mistake.endOffset,
      ).toSet();

      return _selectionRange.intersection(mistakeRange).isNotEmpty;
    }

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also -- comparing start-end will be more efficient. We don't need the full set intersection here, do we?
All we need is to check whether two integers (mistake start-end) are inclusively within the selection range.

@@ -69,14 +70,43 @@ class ColoredTextEditingController extends TextEditingController {
///so this check avoid cleaning Mistake list when text wasn't really changed
if (newText == text) return;

_mistakes.clear();
for (final recognizer in _recognizers) {
recognizer.dispose();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Memory leak introduced?
Perhaps we need an extra internal structure to map mistakes to their respective tap recognizers?

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.

None yet

3 participants