Feat: now spell-checking works in real-time

pull/2118/head
CatHood0 8 months ago
parent b4c9d84fd4
commit dc1a58cd68
  1. 2
      example/lib/screens/quill/quill_screen.dart
  2. 1
      lib/flutter_quill.dart
  3. 14
      lib/src/editor/spellchecker/default_spellchecker_service.dart
  4. 25
      lib/src/editor/spellchecker/simple_spellchecker_impl.dart
  5. 7
      lib/src/editor/spellchecker/spellchecker_service.dart
  6. 15
      lib/src/editor/widgets/text/text_line.dart
  7. 2
      pubspec.yaml

@ -43,6 +43,8 @@ class _QuillScreenState extends State<QuillScreen> {
void initState() {
super.initState();
_controller.document = widget.args.document;
SpellcheckerServiceProvider.setInstance(
SimpleSpellCheckerImpl(language: 'en'));
}
@override

@ -24,6 +24,7 @@ export 'src/editor/raw_editor/config/raw_editor_configurations.dart';
export 'src/editor/raw_editor/quill_single_child_scroll_view.dart';
export 'src/editor/raw_editor/raw_editor.dart';
export 'src/editor/raw_editor/raw_editor_state.dart';
export 'src/editor/spellchecker/simple_spellchecker_impl.dart';
export 'src/editor/spellchecker/spellchecker_service.dart';
export 'src/editor/spellchecker/spellchecker_service_provider.dart';
export 'src/editor/style_widgets/style_widgets.dart';

@ -1,11 +1,17 @@
import 'package:flutter/material.dart';
import 'spellchecker_service.dart';
import 'package:flutter/gestures.dart' show LongPressGestureRecognizer;
import 'package:flutter/material.dart' show TextSpan;
import 'spellchecker_service.dart' show SpellcheckerService;
class DefaultSpellcheckerService extends SpellcheckerService{
class DefaultSpellcheckerService extends SpellcheckerService {
DefaultSpellcheckerService() : super(language: 'en');
@override
List<TextSpan>? fetchSpellchecker(String text) {
void dispose() {}
@override
List<TextSpan>? fetchSpellchecker(String text,
{LongPressGestureRecognizer Function(String p1)?
customLongPressRecognizerOnWrongSpan}) {
return null;
}
}

@ -1,13 +1,32 @@
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:simple_spell_checker/simple_spell_checker.dart';
import 'spellchecker_service.dart';
class SimpleSpellCheckerImpl extends SpellcheckerService {
SimpleSpellCheckerImpl({required super.language});
SimpleSpellCheckerImpl({required super.language})
: checker = SimpleSpellChecker(
language: language,
safeDictionaryLoad: true,
);
final SimpleSpellChecker checker;
@override
List<TextSpan>? fetchSpellchecker(String text) {
return null;
List<TextSpan>? fetchSpellchecker(
String text, {
LongPressGestureRecognizer Function(String word)?
customLongPressRecognizerOnWrongSpan,
}) {
return checker.check(
text,
customLongPressRecognizerOnWrongSpan:
customLongPressRecognizerOnWrongSpan,
);
}
@override
void dispose() {
checker.dispose(closeDirectionary: true);
}
}

@ -1,8 +1,13 @@
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
abstract class SpellcheckerService {
SpellcheckerService({required this.language});
final String language;
List<TextSpan>? fetchSpellchecker(String text);
void dispose();
List<TextSpan>? fetchSpellchecker(String text,
{LongPressGestureRecognizer Function(String)?
customLongPressRecognizerOnWrongSpan});
}

@ -391,10 +391,8 @@ class _TextLineState extends State<TextLine> {
final nodeStyle = textNode.style;
final isLink = nodeStyle.containsKey(Attribute.link.key) &&
nodeStyle.attributes[Attribute.link.key]!.value != null;
final style =
_getInlineTextStyle(nodeStyle, defaultStyles, lineStyle, isLink);
if (widget.controller.configurations.requireScriptFontFeatures == false &&
textNode.value.isNotEmpty) {
if (nodeStyle.containsKey(Attribute.script.key)) {
@ -406,6 +404,19 @@ class _TextLineState extends State<TextLine> {
}
}
// verify is node is not link because we never need check a link word
if (!isLink) {
final service = SpellcheckerServiceProvider.instance;
final spellcheckedSpans = service.fetchSpellchecker(textNode.value);
if (spellcheckedSpans != null && spellcheckedSpans.isNotEmpty) {
return TextSpan(
children: spellcheckedSpans,
style: style,
mouseCursor: null,
);
}
}
final recognizer = _getRecognizer(node, isLink);
return TextSpan(
text: textNode.value,

@ -45,7 +45,7 @@ dependencies:
# Dart Packages
intl: ^0.19.0
dart_quill_delta: ^10.0.0
simple_spell_checker: ^1.0.1
simple_spell_checker: ^1.0.3
collection: ^1.17.0
quiver: ^3.2.1
equatable: ^2.0.5

Loading…
Cancel
Save