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

Added mistake range guards #40

Merged
merged 1 commit into from
May 26, 2023
Merged

Added mistake range guards #40

merged 1 commit into from
May 26, 2023

Conversation

mitryp
Copy link
Contributor

@mitryp mitryp commented May 26, 2023

Resolves #39

Range guards prevent the ColoredTextEditingController from creating mistakes highlighting TextSpans with substrings of the text that are longer than the current text.

@mitryp
Copy link
Contributor Author

mitryp commented May 26, 2023

Is there any particular reason why there are used two nested text spans in the ColoredTextEditingController._generateSpans instead of one?

yield TextSpan(
  children: [
    TextSpan(
      text: text.substring(
        mistake.offset,
        min(mistake.endOffset, text.length),
      ),
      mouseCursor: MaterialStateMouseCursor.clickable,
      style: style?.copyWith(
        backgroundColor: mistakeColor.withOpacity(
          highlightStyle.backgroundOpacity,
        ),
        decoration: highlightStyle.decoration,
        decorationColor: mistakeColor,
        decorationThickness: highlightStyle.mistakeLineThickness,
      ),
      recognizer: _onTap,
    ),
  ],
);

Copy link
Collaborator

@solid-vovabeloded solid-vovabeloded left a comment

Choose a reason for hiding this comment

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

LGTM

@mitryp mitryp merged commit 29bd626 into main May 26, 2023
1 check passed
@mitryp mitryp deleted the fix/mistake-range-guards branch May 26, 2023 11:00
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.

Throws if the mistakes are rendered after text change
2 participants