-
-
Notifications
You must be signed in to change notification settings - Fork 85
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
Spell Checking #428
Open
Wavesonics
wants to merge
86
commits into
MohamedRejeb:main
Choose a base branch
from
Wavesonics:spell-check-test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Spell Checking #428
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Wavesonics
force-pushed
the
spell-check-test
branch
2 times, most recently
from
November 18, 2024 02:44
e9a772d
to
4d3dc84
Compare
richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/model/RichTextState.kt
Outdated
Show resolved
Hide resolved
This update introduces a callback function `onRichSpanClick` to allow apps to handle clicks on RichSpans in the RichTextEditor. The updates also modify the visibility of some classes and properties to support this- `RichSpan`, `ParagraphType` and `getRichSpanByOffset` method in `RichTextState` are now publicly visible.
cleanup # Conflicts: # sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/richeditor/RichEditorContent.kt
# Conflicts: # richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/BasicRichTextEditor.kt
# Conflicts: # richeditor-compose/api/android/richeditor-compose.api # richeditor-compose/api/desktop/richeditor-compose.api # sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/richeditor/RichEditorContent.kt
Wavesonics
force-pushed
the
spell-check-test
branch
from
November 29, 2024 10:10
1a1f9b3
to
8bf8154
Compare
Wavesonics
commented
Nov 29, 2024
voyager = "1.1.0-beta03" | ||
richeditor = "1.0.0-rc10" | ||
coroutines = "1.9.0" | ||
ktor = "3.0.1" | ||
android-minSdk = "21" | ||
android-minSdk = "26" |
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't install APKs that have min SDK set below 26 on devices running SDK 35+
It will be required by anyone who uses this module
This is smaller and faster to load and parse
# Conflicts: # richeditor-compose/api/android/richeditor-compose.api # richeditor-compose/api/desktop/richeditor-compose.api # richeditor-compose/api/richeditor-compose.klib.api # richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/BasicRichTextEditor.kt # richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/material/OutlinedRichTextEditor.kt # richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/material/RichTextEditor.kt # richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/material3/OutlinedRichTextEditor.kt # sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/richeditor/RichEditorContent.kt
Wavesonics
force-pushed
the
spell-check-test
branch
2 times, most recently
from
December 6, 2024 05:29
c462fb6
to
c057947
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Update: I've been working on this one and it is actually pretty much ready now I think.
It creates a new module:
richeditor-compose-spellcheck
which contains all of the common spell checking code, imports my SymSpellKt library, and ultimately provides a new composable:SpellCheckedRichTextEditor
which automatically provides spell checking as you type.You still need to provide it with a
SpellChecker
which requires loading a dictionary, and this has to be up to the application as it probably shouldn't be done inside the UI as it is done in the sample. Loading the dictionary is expensive and slow and should be done at the application level.It also adds a new screen to the sample that implements spell checking fully.
The only "but" here is that it uses a fairly naive algorithm (if you can call it that) to scan for new misspellings. Because
BasicTextField
does not give us any info when it updates on WHAT changed, only that something changed, I haven't yet found a very efficient way to invalidate only theSpellCheck
spans which contain the new edit.As such, I invalidate all
SpellCheck
spans and fully rescan the text for new misspellings. To this end, I went to great lengths to make that scanning as efficient as possible. I find the individual words to spell check by walking theRichSpan
tree rather than flattening the whole tree to a String and segmenting off of that. This reduces the required memory allocations be at least 1 full copy of the text.SymSpell it's self is also incredibly efficient, so the cost of scanning each word is very minimal.
I think what is here is more than sufficient for a v1 of our spell checker, and I can continue to brain storm how we can be more efficient.
As mentioned below, this relies on #194 to be able to handle the clicks on the SpellCheck spans, and #432 to know when to scan for changes.
This is not production ready by any means yet, but I wanted to see how close I was to finally getting Spell Checking working.The answer is: pretty darn close!
spell-check.mp4
This relies on #194 to be able to handle the clicks on the
SpellCheck
spans, and #432 to know when to scan for changes.One problem currently is that when the spellcheck correction is applied, any existing rich text span is lost.