fix(textarea): count runes, not display width, for CharLimit#1008
Open
sueun-dev wants to merge 1 commit into
Open
fix(textarea): count runes, not display width, for CharLimit#1008sueun-dev wants to merge 1 commit into
sueun-dev wants to merge 1 commit into
Conversation
Length summed uniseg.StringWidth per row, so CharLimit (documented as "the maximum number of characters") was enforced by display width. Wide runes (CJK, emoji) occupy two cells, so a textarea with CharLimit=N stopped accepting input at about N/2 characters. textinput enforces the same CharLimit by rune count, so the two components disagreed. Count runes instead, which matches Length's godoc and textinput.
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.
Length()sumsuniseg.StringWidthper row, soCharLimitis enforced by display width rather than character count. Wide runes (CJK, emoji) take two cells, so a textarea withCharLimit=Nstops accepting input at aboutN/2characters. This contradicts the godoc on bothLength()("the number of characters currently in the text input") andCharLimit("the maximum number of characters"), and disagrees withtextinput, which enforces the same limit by rune count.Repro: with
CharLimit = 5, typing five wide runes one at a time leaves only three in the textarea, while five ASCII characters are accepted.textinputwith the same limit accepts all five wide runes.The fix counts runes (
len(row), whererowis[]rune), matching the godoc andtextinput.unisegis still used for rendering, and the existing ASCIICharLimittests are unchanged (width equals rune count for ASCII). AddedTestCharLimitWideRunescovering the wide-rune case.