Skip to content

Handle multi-byte characters correctly in text fields - #10194

Open
hard25670559 wants to merge 1 commit into
PathOfBuildingCommunity:devfrom
hard25670559:fix/multibyte-text-editing
Open

Handle multi-byte characters correctly in text fields#10194
hard25670559 wants to merge 1 commit into
PathOfBuildingCommunity:devfrom
hard25670559:fix/multibyte-text-editing

Conversation

@hard25670559

Copy link
Copy Markdown

Description of the problem being solved

Two independent defects in EditControl make non-ASCII text unusable, regardless of platform or language.

Pasting discards the text entirely. Every byte >= 0x80 is replaced with "?" before insertion:

text = text:gsub("[\128-\255]","?")

In a field carrying a filename filter (\\/:%*%?\"<>|%c), those "?" are then stripped again by Insert() as illegal characters. The result is not mangled text but no text — pasting a build name, folder name or item appears to do nothing at all.

Backspace and delete corrupt the text. Both remove a fixed single byte:

local len = 1

A multi-byte character is therefore cut in half, leaving an invalid sequence that renders as ?. Caret movement already steps by whole characters via utf8.next, so the two behaviours disagree: the caret moves over a character but deleting only removes a third of it.

Related: #5632 (open since 2023, "POB currently cannot input languages other than english"), and #6669, which relaxed the default input filter under PoeCharm but did not address paste or deletion.

Description of the changes

  • Remove the byte substitution on paste. Insert() still applies each control's own filter, so filename-illegal characters are still rejected — only the blanket replacement of non-ASCII is gone.
  • Derive the deletion length from utf8.next, the same helper caret movement already uses, so a keystroke removes exactly the character the caret moved over. The ctrl-modified word-wise paths are unchanged.

Both changes are platform-independent and affect any language that uses characters outside ASCII.

Steps taken to verify a working solution

Tested on macOS with Traditional Chinese text in the "Save As" build name field:

  • Pasting 測試中文 previously left the field empty; it now inserts the text, and saving produces a file named correctly on disk.
  • Backspace previously needed three presses per character and left ? behind after the first; it now removes one whole character per press (卡在這卡在).
  • ASCII input, the ctrl-modified word deletion, and filename filtering are unaffected.

The fields still need engine-side font support to display these characters; that is separate and not part of this change.

Two independent defects made non-ASCII text unusable in EditControl.

Pasting replaced every byte >= 0x80 with "?" before inserting. In a
field carrying a filename filter the "?" was then stripped again as an
illegal character, so pasted text disappeared outright rather than
merely being mangled. Drop the substitution and let the bytes through;
Insert() still applies the control's own filter.

Backspace and delete removed a fixed single byte, which splits a
multi-byte character and leaves an invalid sequence behind. Caret
movement already steps by whole characters through utf8.next, so
deletion now derives its length from the same helper. The ctrl-modified
word-wise paths are untouched.
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