solid-software / languagetool_textfield

🌐 Flutter text field that implements LanguageTool spellcheck.
BSD 3-Clause "New" or "Revised" License
34 stars 10 forks source link

Added mistake range guards #40

Closed mitryp closed 1 year ago

mitryp commented 1 year ago

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 commented 1 year ago

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,
    ),
  ],
);