Skip to content

TextInput: copy and cut the text the selection actually covers - #1373

Open
hoseyjoe wants to merge 1 commit into
HeapsIO:masterfrom
hoseyjoe:textinput-expanded-selection
Open

hoseyjoe wants to merge 1 commit into
HeapsIO:masterfrom
hoseyjoe:textinput-expanded-selection

Conversation

@hoseyjoe

@hoseyjoe hoseyjoe commented Oct 3, 2026

Copy link
Copy Markdown

cursorIndex and selectionRange count the expanded text (with the line breaks word wrapping inserts, as getTextPos documents), and every operation on the text converts through getTextPos first, except two:

  • Ctrl+C / Ctrl+X used text.substr(selectionRange.start, selectionRange.length) directly, so on wrapped text the clipboard got a copy shifted by one character per wrap above the selection, while cutSelection removed the correct characters. Cutting a word and pasting it back lost a letter. Both now use getSelectedText(), which already does the conversion.
  • getWordEnd bounded a text position (ret) by getTextLength(), the expanded length. Double-clicking the last word of a wrapped text selected one character past its end. It now bounds by text.length.

Single-line inputs are unaffected, since expanded and raw positions are the same there.

cursorIndex and selectionRange count the EXPANDED text - the text with the
line breaks word wrapping inserted, as getTextPos's documentation says - and
every operation on the text itself converts through getTextPos first.
Ctrl+C and Ctrl+X did not: they took `text.substr(selectionRange.start,
selectionRange.length)` straight from the text, so on any wrapped line the
clipboard was given a copy shifted by one character per wrap above the
selection, while cutSelection removed the correct characters. Cutting a word
and pasting it back therefore lost a letter. getSelectedText already does the
conversion, so both now use it.

getWordEnd had the mirror of the same confusion: `ret` is a position in the
text, but it was bounded by getTextLength(), which is the expanded length and
so longer than the text by one per inserted break. A double-click on a word at
the end of a wrapped text selected one character past the end of it.

This branch has not been deployed

No deployments
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