diff --git a/README.md b/README.md index 9e9a5473d..b48375331 100644 --- a/README.md +++ b/README.md @@ -286,11 +286,8 @@ The following packages can be used: ## 📝 Spelling checker -While spell-checking is not a feature that's implemented into the project, it can be used using external dependencies. - -It's implemented using the package `simple_spell_checker` in the [Example](./example/). - -Take a look at [Spelling Checker](./doc/spell_checker.md) page for more info. +This feature is currently not implemented and is being planned. Refer to [#2246](https://github.com/singerdmx/flutter-quill/issues/2246) +for discussion. ## ✂️ Shortcut events diff --git a/doc/spell_checker.md b/doc/spell_checker.md deleted file mode 100644 index 5fc3e56b5..000000000 --- a/doc/spell_checker.md +++ /dev/null @@ -1,79 +0,0 @@ -# 📝 Spelling checker - -A spell checker is a software tool or feature integrated into various text processing applications that automatically identifies and corrects spelling errors in a written document. It works by comparing the words in the text against a built-in dictionary. If a word isn't found in the dictionary or doesn't match any known word patterns, the spell checker highlights it as a potential error. - -While spell-checking is not a feature that's implemented into the project, it can be used using external dependencies. - -It's implemented using the package `simple_spell_checker` in the [Example](../example/). - -> [!NOTE] -> [`simple_spell_checker`](https://pub.dev/packages/simple_spell_checker) is a client-side dependency that works without an internet connection, so, it could weigh more than expected due to each of the dictionaries. As mentioned below, it supports a very wide variety of languages which can have a file of up to 300.000 words (this being just one language). - -### Benefits of a spell checker include: - -* Improved Accuracy: It helps writers avoid common spelling mistakes, ensuring that the text is free of errors. -* Time-Saving: Automatically detecting errors reduces the time needed for manual proofreading. -* Enhanced Professionalism: Correctly spelled words contribute to the overall professionalism of documents, which is crucial in academic, business, and formal writing. -* Multilingual Support: Many spell checkers support multiple languages, making it easier for users to write accurately in different languages. - -> [!IMPORTANT] -> The spell checker usually does not work as expected in most cases. For now it is a purely **experimental** feature that may have **code that will be modified** in future versions. - -### The translations supported so far are: - -* German - `de`, `de-ch` -* English - `en`, `en-gb` -* Spanish - `es` -* Catalan - `ca` -* Arabic - `ar` -* Danish - `da` -* French - `fr` -* Bulgarian - `bg` -* Dutch - `nl` -* Korean - `ko` -* Estonian - `et` -* Hebrew - `he` -* Slovak - `sk` -* Italian - `it` -* Norwegian - `no` -* Portuguese - `pt` -* Swedish - `sv` -* Russian - `ru` - -_**Note**: If you have knowledge about any of these available languages or the unsupported ones, you can make a pull request to add support or add words that are not currently in [simple_spell_checker](https://github.com/CatHood0/simple_spell_checker)_. - -In order to activate this functionality you can use the following code: - -```dart -// you can use the language of your preference or directly select the language of the operating system -final language = 'en'; // or Localizations.localeOf(context).languageCode -SpellChecker.useSpellCheckerService(language); -``` - -> [!NOTE] -> The class `SpellChecker` is not available as part of the project API. Instead, you will have to implement it manually. Take a look at the example [Spell Checker](../example/lib/spell_checker/spell_checker.dart) class. - -When you no longer need to have the Spell checker activated you can simply use `dispose()` of the `SpellCheckerServiceProvider` class: - -```dart -// dispose all service and it cannot be used after this -SpellCheckerServiceProvider.dispose(); -``` - -If what we want is to **close the StreamControllers** without deleting the values that are already stored in it, we can set `onlyPartial` to `true`. - -```dart -// it can be still used by the editor -SpellCheckerServiceProvider.dispose(onlyPartial: true); -``` - -One use of this would be having the opportunity to **activate and deactivate** the service when we want, we can see this in the example that we have in this package, in which you can see that on each screen, we have a button that dynamically activates and deactivates the service. To do this is pretty simple: - -```dart - SpellCheckerServiceProvider.toggleState(); - // use isServiceActive to get the state of the service - SpellCheckerServiceProvider.isServiceActive(); - setState(() {}); -``` - -Open this [page](https://pub.dev/packages/simple_spell_checker) for more information. \ No newline at end of file diff --git a/example/lib/screens/home/widgets/home_screen.dart b/example/lib/screens/home/widgets/home_screen.dart index a0056d571..c75a6e514 100644 --- a/example/lib/screens/home/widgets/home_screen.dart +++ b/example/lib/screens/home/widgets/home_screen.dart @@ -27,6 +27,7 @@ class HomeScreen extends StatefulWidget { class _HomeScreenState extends State { @override void dispose() { + // ignore: deprecated_member_use SpellCheckerServiceProvider.dispose(); super.dispose(); } diff --git a/example/lib/screens/quill/quill_screen.dart b/example/lib/screens/quill/quill_screen.dart index 97cb0abfe..acb3dffe4 100644 --- a/example/lib/screens/quill/quill_screen.dart +++ b/example/lib/screens/quill/quill_screen.dart @@ -70,11 +70,13 @@ class _QuillScreenState extends State { IconButton( tooltip: 'Spell-checker', onPressed: () { + // ignore: deprecated_member_use SpellCheckerServiceProvider.toggleState(); setState(() {}); }, icon: Icon( Icons.document_scanner, + // ignore: deprecated_member_use color: SpellCheckerServiceProvider.isServiceActive() ? Colors.red.withOpacity(0.5) : null, diff --git a/example/lib/spell_checker/simple_spell_checker_service.dart b/example/lib/spell_checker/simple_spell_checker_service.dart index c804a8d19..26c109e11 100644 --- a/example/lib/spell_checker/simple_spell_checker_service.dart +++ b/example/lib/spell_checker/simple_spell_checker_service.dart @@ -4,8 +4,13 @@ import 'package:flutter_quill/flutter_quill.dart'; import 'package:simple_spell_checker/simple_spell_checker.dart'; /// SimpleSpellChecker is a simple spell checker for get -/// all words divide on different objects if them are wrong or not +/// all words divide on different objects if them are wrong or not. +/// +/// **Important**: A breaking change is planned and this shouldn't be used +/// for new applications. A replacement will arrive soon. +/// See: https://github.com/singerdmx/flutter-quill/issues/2246 class SimpleSpellCheckerService + // ignore: deprecated_member_use extends SpellCheckerService { SimpleSpellCheckerService({required super.language}) : checker = SimpleSpellChecker( diff --git a/example/lib/spell_checker/spell_checker.dart b/example/lib/spell_checker/spell_checker.dart index 08238ce17..df9eea350 100644 --- a/example/lib/spell_checker/spell_checker.dart +++ b/example/lib/spell_checker/spell_checker.dart @@ -1,3 +1,5 @@ +// ignore_for_file: deprecated_member_use + import 'package:flutter_quill/flutter_quill.dart'; import 'simple_spell_checker_service.dart'; diff --git a/lib/src/editor/spellchecker/default_spellchecker_service.dart b/lib/src/editor/spellchecker/default_spellchecker_service.dart index 4a8e6b1ad..79ec19c0a 100644 --- a/lib/src/editor/spellchecker/default_spellchecker_service.dart +++ b/lib/src/editor/spellchecker/default_spellchecker_service.dart @@ -1,10 +1,19 @@ +// ignore_for_file: deprecated_member_use_from_same_package + import 'package:flutter/gestures.dart' show LongPressGestureRecognizer; import 'package:flutter/material.dart' show TextSpan; +import 'package:meta/meta.dart'; import 'spellchecker_service.dart' show SpellCheckerService; /// A default implementation of the [SpellcheckerService] /// that always will return null since Spell checking /// is not a standard feature +@Deprecated( + 'A breaking change is being planned for the SpellCheckerService and SpellCheckerServiceProvider.\n' + "A replacement doesn't exist yet but should arrive soon." + 'See https://github.com/singerdmx/flutter-quill/issues/2246 for more details.', +) +@experimental class DefaultSpellCheckerService extends SpellCheckerService { DefaultSpellCheckerService() : super(language: 'en'); diff --git a/lib/src/editor/spellchecker/spellchecker_service.dart b/lib/src/editor/spellchecker/spellchecker_service.dart index 0e2ebd48c..41b34678f 100644 --- a/lib/src/editor/spellchecker/spellchecker_service.dart +++ b/lib/src/editor/spellchecker/spellchecker_service.dart @@ -1,7 +1,14 @@ import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; +import 'package:meta/meta.dart'; /// A representation a custom SpellCheckService. +@Deprecated( + 'A breaking change is being planned for the SpellCheckerService.\n' + "A replacement doesn't exist yet but should arrive soon." + 'See https://github.com/singerdmx/flutter-quill/issues/2246 for more details.', +) +@experimental abstract class SpellCheckerService { SpellCheckerService({required this.language}); diff --git a/lib/src/editor/spellchecker/spellchecker_service_provider.dart b/lib/src/editor/spellchecker/spellchecker_service_provider.dart index e5d41335f..47e80182d 100644 --- a/lib/src/editor/spellchecker/spellchecker_service_provider.dart +++ b/lib/src/editor/spellchecker/spellchecker_service_provider.dart @@ -1,8 +1,17 @@ +// ignore_for_file: deprecated_member_use_from_same_package + import 'package:flutter/foundation.dart' show immutable; +import 'package:meta/meta.dart' show experimental; import 'default_spellchecker_service.dart'; import 'spellchecker_service.dart'; @immutable +@Deprecated( + 'A breaking change is being planned for the SpellCheckerService and SpellCheckerServiceProvider.\n' + "A replacement doesn't exist yet but should arrive soon." + 'See https://github.com/singerdmx/flutter-quill/issues/2246 for more details.', +) +@experimental class SpellCheckerServiceProvider { const SpellCheckerServiceProvider._(); static SpellCheckerService _instance = DefaultSpellCheckerService(); diff --git a/lib/src/editor/widgets/text/text_line.dart b/lib/src/editor/widgets/text/text_line.dart index 43cab0930..a47d6f0e4 100644 --- a/lib/src/editor/widgets/text/text_line.dart +++ b/lib/src/editor/widgets/text/text_line.dart @@ -482,6 +482,7 @@ class _TextLineState extends State { !widget.line.style.attributes.containsKey('code-block') && !widget.line.style.attributes.containsKey('placeholder') && !isPlaceholderLine) { + // ignore: deprecated_member_use_from_same_package final service = SpellCheckerServiceProvider.instance; final spellcheckedSpans = service.checkSpelling(textNode.value); if (spellcheckedSpans != null && spellcheckedSpans.isNotEmpty) {