-
Notifications
You must be signed in to change notification settings - Fork 253
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
[SuperEditorSpellCheck] Add API to ignore text during spellcheck (Resolves #2564) #2567
Conversation
@matthew-carroll Do you have any ideas on what is the ideal approach to add tests for this? I think we could make the plugin take a Also, which other built-in rules should we add? |
/// | ||
/// This method replaces the ignored ranges with whitespaces so that the spellchecker | ||
/// doesn't see them. | ||
String _filterIgnoredRanges(TextNode node, Document document) { |
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.
Can we remove the document
from this? This seems to spread the document
around to a bunch of callsites, and in theory the broader document
shouldn't be necessary to evaluate rules for patterns, attributions, or explicit text spans.
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.
Removed.
typedef SpellingIgnoreRule = List<TextRange> Function(TextNode node, Document document); | ||
|
||
/// A collection of built-in rules for ignoring spans of text from spellchecking. | ||
class SpellingIgnoreRules { |
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 should add a rule for explicit text spans, just in case an app already knows the range of text to ignore.
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.
Like we talked before, the knowledge about ignored ranges lives only in the SpellingAndGrammarReaction
. So, a rule that takes a TextRange
would apply that range for all nodes in the document. A rule to ignore a portion of the document would need to take a DocumentRange
and a Document
, to generate different TextRanges
for each node, as the rules return the ignored range for a single TextNode
.
Regarding adding option directly on our native spellchecker plugin, I'm not sure it's a good idea, because the plugin basically just exposes the macOS API's, so I think we shouldn't be adding arbitrary parameters.
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.
LGTM - We should add some kind of tests for this. Maybe send a fake spell checker and verify that the text that's sent to the checker has blanked out the various ignore span. But I'll merge this as-is so that ClickUp can use it.
@matthew-carroll Added a PR with tests: #2574 |
[SuperEditorSpellCheck] Add API to ignore text during spellcheck (Resolves #2564)
This PR adds an optional
ignoreRules
to the plugin constructor, so apps can choose to ignore certain texts, like links, tags, etc.Each rule is a function that returns a list of
TextRange
s that should be ignored. All ranges from all rules are ignored.Since on mobile we pass the whole text at once to the spellchecker, we need a workaround to do this. This PR replaces all the ignored ranges with whitespaces, so the spellchecker doesn't report anything on those ranges.
This PR implements built-in rules for ignore by pattern, attribution and attribution filters.
Without the ignored ranges:
With ignored ranges: