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

Spelling error decorations and suggestions (Resolves #388) #2324

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

Conversation

matthew-carroll
Copy link
Contributor

Spelling error decorations and suggestions (Resolves #388)

Screen.Recording.2024-09-17.at.7.09.40.PM.mov

@matthew-carroll
Copy link
Contributor Author

@miguelcmedeiros @brian-superlist - Do you guys wanna try out this PR and report back with any issues?

return viewModel;
}
if (viewModel is! TextComponentViewModel) {
// TODO: log error about component type
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this log be added?

}
}

class TextError {
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about a dart doc for this class?

Copy link
Collaborator

Choose a reason for hiding this comment

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

The new golden isn't showing an underline. This seem to be the case for other goldens as well.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you intend to commit these .run files?


final _styler = SpellingAndGrammarStyler();

final _selectedWordLink = LeaderLink();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we could add a dart doc for this.

setState(() {
// If the selection was sitting in an ignored spelling error, and
// now the selection is somewhere else, reset the ignored error.
if (_ignoredSpellingErrorRange != null) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about returning early if _ignoredSpellingErrorRange is null?

Comment on lines +157 to +161
WidgetsBinding.instance.addPostFrameCallback((_) {
if (_suggestionToolbarOverlayController.isShowing) {
_suggestionToolbarOverlayController.hide();
}
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add a comment explaining why we hide the overlay here?

return const SizedBox();
}

return OverlayPortal(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add a comment explaining why we need an OverlayPortal, since the widget returned here is already displayed over the content? I'm assuming it's because of the Follower, but it would be good to explain that here.

Comment on lines +68 to +76
/// Clears all spelling suggestions for text within the node with the given [nodeId].
void clearNode(String nodeId) {
_suggestions.remove(nodeId);
}

/// Clears all spelling suggestions for all text in the document.
void clear() {
_suggestions.clear();
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since we are notifying listeners when adding suggestions, shouldn't we also notify when clearing?


class SpellingErrorSuggestion {
const SpellingErrorSuggestion(
{required this.word, required this.nodeId, required this.range, required this.suggestions});
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about end with , to re-format?

Copy link
Collaborator

@miguelcmedeiros miguelcmedeiros left a comment

Choose a reason for hiding this comment

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

@matthew-carroll noticed a small issue (see comment) with the code.

Also tested the feature. Here's my initial feedback:

  • We should be able to pass a tapRegionGroupId to the suggestion toolbar so that it plays well with a TapRegion ancestor
  • Tested on android for potential regression and the following is thrown:
I/flutter ( 5003): (12.427) PlatformException(channel-error, Unable to establish connection on channel: "dev.flutter.pigeon.super_editor_spellcheck.SpellCheckMac.checkSpelling"., null, null)
I/flutter ( 5003): #0      SpellCheckMac.checkSpelling (package:super_editor_spellcheck/src/platform/messages.g.dart:277:7)
I/flutter ( 5003): <asynchronous suspension>
I/flutter ( 5003): #1      SuperEditorSpellCheckerMacPlugin.checkSpelling (package:super_editor_spellcheck/src/platform/spell_checker_mac.dart:37:20)
I/flutter ( 5003): <asynchronous suspension>
I/flutter ( 5003): #2      SpellingAndGrammarReaction._findSpellingAndGrammarErrors (package:super_editor_spellcheck/src/super_editor/spelling_and_grammar_plugin.dart:200:21)
I/flutter ( 5003): <asynchronous suspension>

}) : super(nodeId: nodeId, maxWidth: maxWidth, padding: padding) {
this.composingRegion = composingRegion;
this.showComposingRegionUnderline = showComposingRegionUnderline;

this.spellingErrorUnderlineStyle = spellingErrorUnderlineStyle;
this.spellingErrors = spellingErrors;

this.grammarErrorUnderlineStyle = grammarErrorUnderlineStyle;
this.grammarErrors = spellingErrors;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
this.grammarErrors = spellingErrors;
this.grammarErrors = grammarErrors;

parentNode: widget.editorFocusNode,
child: Container(
decoration: BoxDecoration(
color: Colors.white,
Copy link
Collaborator

Choose a reason for hiding this comment

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

The current implementation looks fine on light mode, but not on dark mode.
Also, it would be great to be able to customize the suggestion overlay. Is it possible to expose this in the API?

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.

Spell-check + Auto-Correct Support
3 participants