Select a word with an apostrophe in it as one word. - #352
Open
ilya-fedin wants to merge 1 commit into
Open
Conversation
This was referenced Aug 26, 2026
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.
IsWordSeparator()is a copy of Qt'sQTextEngine::atWordSeparator()list, madeback in 2014, and it has the apostrophe in it. Selecting by words - a double
click, or
TextSelectType::WordsinadjustSelection()- therefore cutsdon'tdown to
don,it'stoit,o'clocktoo.Qt itself has the same problem, and one of the Qt patches of the official builds
fixes it there: an apostrophe is a separator only when it is doubled or when it
stands at the edge of a word, so
don'tis one word whiledon''tand'quoted'are not. This applies the same rule here, where the text is ours tolook at, so the selection no longer depends on that patch.
The rule needs the neighbours of a character, so it comes as an overload that is
given the text along with the position. There are two of them: one for a text
that is already a string, and one that reads a character at a time - a block of
a
QTextDocumentanswers that without copying itself for every question, whichis what
lib_spellcheckneeds for the word under the cursor. The plaincharacter overload keeps the list as it was, for the callers that have a single
character and no way to look around it.
Verified against
QTextCursor::WordUnderCursoron every position of a set ofsamples:
don't,it's,o'clock,donn't,a'bcome out as one word,don''tas two, and the quotes of'quoted'androck 'n' rollstay outside.