Skip to content

Commit 7828068

Browse files
[Spellcheck] - Check for spelling errors on initial document content (Resolves #2526) (#2527)
1 parent 4657853 commit 7828068

File tree

4 files changed

+60
-15
lines changed

4 files changed

+60
-15
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="main.dart" type="FlutterRunConfigurationType" factoryName="Flutter">
3+
<option name="filePath" value="$PROJECT_DIR$/example/lib/main_super_editor_spellcheck.dart" />
4+
<method v="2" />
5+
</configuration>
6+
</component>

super_editor_spellcheck/example/lib/main_super_editor_spellcheck.dart

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,14 @@ class _SuperEditorSpellcheckScreenState extends State<_SuperEditorSpellcheckScre
8585
);
8686

8787
_editor = createDefaultDocumentEditor(
88-
document: MutableDocument.empty(),
88+
document: MutableDocument(
89+
// Start the document with some misspelled content to ensure pre-existing
90+
// content is analyzed and styled.
91+
nodes: [
92+
ParagraphNode(id: "1", text: AttributedText("Tihs is mipelled")),
93+
ParagraphNode(id: "2", text: AttributedText()),
94+
],
95+
),
8996
composer: MutableDocumentComposer(),
9097
);
9198

@@ -104,8 +111,8 @@ class _SuperEditorSpellcheckScreenState extends State<_SuperEditorSpellcheckScre
104111
_editor.execute([
105112
InsertTextRequest(
106113
documentPosition: DocumentPosition(
107-
nodeId: _editor.context.document.first.id,
108-
nodePosition: _editor.context.document.first.beginningPosition,
114+
nodeId: _editor.context.document.last.id,
115+
nodePosition: _editor.context.document.last.beginningPosition,
109116
),
110117
textToInsert:
111118
'Flutter is a populr framework developd by Google for buildng natively compilid applications for mobil, web, and desktop from a single code base. Its hot reload featur allows developers to see the changes they make in real-time without havng to restart the app, which can greatly sped up the development proccess. With a rich set of widgets and a customizble UI, Flutter makes it easy to creat beautiful and performant apps quickly.',

super_editor_spellcheck/example/pubspec.lock

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ packages:
3737
dependency: transitive
3838
description:
3939
name: attributed_text
40-
sha256: "38e14c70958d5066ec79ca1a2c1e28abee8422dd257715de06fe3e90d46205ff"
40+
sha256: d16c10850371421a778474ac24c24b4ab8708e3e53f3796f8d9ea2a41a25a59a
4141
url: "https://pub.dev"
4242
source: hosted
43-
version: "0.3.3"
43+
version: "0.4.2"
4444
boolean_selector:
4545
dependency: transitive
4646
description:
@@ -160,6 +160,14 @@ packages:
160160
url: "https://pub.dev"
161161
source: hosted
162162
version: "0.0.24"
163+
flutter_test_runners:
164+
dependency: transitive
165+
description:
166+
name: flutter_test_runners
167+
sha256: cc575117ed66a79185a26995399d7048341517a1bd21188cb43753739627832d
168+
url: "https://pub.dev"
169+
source: hosted
170+
version: "0.0.4"
163171
flutter_web_plugins:
164172
dependency: transitive
165173
description: flutter
@@ -283,10 +291,10 @@ packages:
283291
dependency: transitive
284292
description:
285293
name: logging
286-
sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340"
294+
sha256: c8245ada5f1717ed44271ed1c26b8ce85ca3228fd2ffdb75468ab01979309d61
287295
url: "https://pub.dev"
288296
source: hosted
289-
version: "1.2.0"
297+
version: "1.3.0"
290298
matcher:
291299
dependency: transitive
292300
description:
@@ -490,22 +498,30 @@ packages:
490498
path: "../../super_editor"
491499
relative: true
492500
source: path
493-
version: "0.3.0-dev.9"
501+
version: "0.3.0-dev.15"
494502
super_editor_spellcheck:
495503
dependency: "direct main"
496504
description:
497505
path: ".."
498506
relative: true
499507
source: path
500508
version: "0.0.1"
509+
super_keyboard:
510+
dependency: transitive
511+
description:
512+
name: super_keyboard
513+
sha256: c8e303cd7bc1fc62732213f0f2660273a078be23eae7a4219d0ab3dd0b0ccb9a
514+
url: "https://pub.dev"
515+
source: hosted
516+
version: "0.1.0"
501517
super_text_layout:
502518
dependency: transitive
503519
description:
504520
name: super_text_layout
505-
sha256: b99c2326fe56a21463c24a41c4fd3f30e38942a4a67524bc3069b2b052cdb6a2
521+
sha256: e25f01ceb809118da66fd095b3dcdc608a611bf45e364f303e7f9f0af0c5f8d1
506522
url: "https://pub.dev"
507523
source: hosted
508-
version: "0.1.14"
524+
version: "0.1.18"
509525
sync_http:
510526
dependency: transitive
511527
description:
@@ -558,10 +574,10 @@ packages:
558574
dependency: transitive
559575
description:
560576
name: url_launcher
561-
sha256: "21b704ce5fa560ea9f3b525b43601c678728ba46725bab9b01187b4831377ed3"
577+
sha256: "9d06212b1362abc2f0f0d78e6f09f726608c74e3b9462e8368bb03314aa8d603"
562578
url: "https://pub.dev"
563579
source: hosted
564-
version: "6.3.0"
580+
version: "6.3.1"
565581
url_launcher_android:
566582
dependency: transitive
567583
description:
@@ -622,10 +638,10 @@ packages:
622638
dependency: transitive
623639
description:
624640
name: uuid
625-
sha256: "83d37c7ad7aaf9aa8e275490669535c8080377cfa7a7004c24dfac53afffaa90"
641+
sha256: a5be9ef6618a7ac1e964353ef476418026db906c4facdedaa299b7a2e71690ff
626642
url: "https://pub.dev"
627643
source: hosted
628-
version: "4.4.2"
644+
version: "4.5.1"
629645
vector_math:
630646
dependency: transitive
631647
description:
@@ -691,5 +707,5 @@ packages:
691707
source: hosted
692708
version: "3.1.2"
693709
sdks:
694-
dart: ">=3.4.0 <4.0.0"
710+
dart: ">=3.5.0 <4.0.0"
695711
flutter: ">=3.19.0"

super_editor_spellcheck/lib/src/super_editor/spelling_and_grammar_plugin.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ class SpellingAndGrammarPlugin extends SuperEditorPlugin {
140140

141141
_reaction = SpellingAndGrammarReaction(_spellingErrorSuggestions, _styler);
142142
editor.reactionPipeline.add(_reaction);
143+
144+
// Do initial spelling and grammar analysis, in case the document already
145+
// contains some content.
146+
_reaction.analyzeWholeDocument(editor.context);
143147
}
144148

145149
@override
@@ -267,6 +271,18 @@ class SpellingAndGrammarReaction implements EditReaction {
267271
final _mobileSpellChecker = DefaultSpellCheckService();
268272
final _macSpellChecker = SuperEditorSpellCheckerPlugin().macSpellChecker;
269273

274+
/// Checks every [TextNode] in the given document for spelling and grammar
275+
/// errors and stores them for visual styling.
276+
void analyzeWholeDocument(EditContext editorContext) {
277+
for (final node in editorContext.document) {
278+
if (node is! TextNode) {
279+
continue;
280+
}
281+
282+
_findSpellingAndGrammarErrors(node);
283+
}
284+
}
285+
270286
@override
271287
void modifyContent(EditContext editorContext, RequestDispatcher requestDispatcher, List<EditEvent> changeList) {
272288
// No-op - spelling and grammar checks style the document, they don't alter the document.

0 commit comments

Comments
 (0)