Skip to content

Select a word with an apostrophe in it as one word. - #352

Open
ilya-fedin wants to merge 1 commit into
desktop-app:masterfrom
ilya-fedin:text-word-apostrophe
Open

Select a word with an apostrophe in it as one word.#352
ilya-fedin wants to merge 1 commit into
desktop-app:masterfrom
ilya-fedin:text-word-apostrophe

Conversation

@ilya-fedin

Copy link
Copy Markdown
Contributor

IsWordSeparator() is a copy of Qt's QTextEngine::atWordSeparator() list, made
back in 2014, and it has the apostrophe in it. Selecting by words - a double
click, or TextSelectType::Words in adjustSelection() - therefore cuts don't
down to don, it's to it, o'clock to o.

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't is one word while don''t and
'quoted' are not. This applies the same rule here, where the text is ours to
look 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 QTextDocument answers that without copying itself for every question, which
is what lib_spellcheck needs for the word under the cursor. The plain
character 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::WordUnderCursor on every position of a set of
samples: don't, it's, o'clock, donn't, a'b come out as one word,
don''t as two, and the quotes of 'quoted' and rock 'n' roll stay outside.

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