Skip to content

Take the word under the cursor from the shared word rule. - #34

Open
ilya-fedin wants to merge 1 commit into
desktop-app:masterfrom
ilya-fedin:spellcheck-word-under-cursor
Open

Take the word under the cursor from the shared word rule.#34
ilya-fedin wants to merge 1 commit into
desktop-app:masterfrom
ilya-fedin:spellcheck-word-under-cursor

Conversation

@ilya-fedin

@ilya-fedin ilya-fedin commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

The word under the cursor was taken with
QTextCursor::select(QTextCursor::WordUnderCursor) in two places - when a range
is re-checked after an edit, and when the context menu is filled. That path goes
through QTextEngine::atWordSeparator(), a hardcoded list of ASCII punctuation
that has the apostrophe in it, so don't was cut down to don: the suggestions
were 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't shows it.

WordAtPosition() now answers it with Ui::Text::IsWordSeparator(), which knows
the 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 word
boundaries, 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:

block WordUnderCursor this
128 558 ns 398 ns
512 548 ns 396 ns
4096 536 ns 402 ns
8192 534 ns 404 ns
16384 563 ns 400 ns

It also keeps the convention of WordUnderCursor - when the position is between
two words, the one on the left is answered - because the caller compensates for
it (isPosNotInWord in contentsChange()). Verified against it on every
position of a set of samples.

Needs desktop-app/lib_ui#352.

@ilya-fedin
ilya-fedin force-pushed the spellcheck-word-under-cursor branch from cc9ddac to 6699c60 Compare August 26, 2026 22:28
@ilya-fedin ilya-fedin changed the title Take the word under the cursor from QTextBoundaryFinder. Take the word under the cursor from the shared word rule. Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant