Take the word under the cursor from the shared word rule. - #34
Open
ilya-fedin wants to merge 1 commit into
Open
Conversation
ilya-fedin
force-pushed
the
spellcheck-word-under-cursor
branch
from
August 26, 2026 22:28
cc9ddac to
6699c60
Compare
This file contains hidden or 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
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.
The word under the cursor was taken with
QTextCursor::select(QTextCursor::WordUnderCursor)in two places - when a rangeis re-checked after an edit, and when the context menu is filled. That path goes
through
QTextEngine::atWordSeparator(), a hardcoded list of ASCII punctuationthat has the apostrophe in it, so
don'twas cut down todon: the suggestionswere offered for a piece of the word, and "add to dictionary" added that piece.
One of the Qt patches of the official builds is what makes it behave; on an
unpatched Qt the menu and the underline disagree -
donn'tshows it.WordAtPosition()now answers it withUi::Text::IsWordSeparator(), which knowsthe same rule the patch teaches Qt: an apostrophe is a separator only when it is
doubled or when it stands at the edge of a word. The whole module then agrees
about what a word is, without the patch.
RangesFromText()is left alone: splitting a whole text needs the Unicode wordboundaries, which a list of separators cannot replace for the scripts that do
not put spaces between words.
The text is read a character at a time, through
QTextDocument::characterAt(),so a block is not copied for every question. Measured on the same machine with
the flags of the release build (
-O3 -flto, static Qt), per call:WordUnderCursorIt also keeps the convention of
WordUnderCursor- when the position is betweentwo words, the one on the left is answered - because the caller compensates for
it (
isPosNotInWordincontentsChange()). Verified against it on everyposition of a set of samples.
Needs desktop-app/lib_ui#352.