Repository navigation
util: Treat zero-width joiner and non-joiner as combining characters - #4274
Open
ShryukGrandhi wants to merge 1 commit into
Open
ShryukGrandhi wants to merge 1 commit into
ShryukGrandhi wants to merge 1 commit into
Conversation
Signed-off-by: ShryukGrandhi <85529990+ShryukGrandhi@users.noreply.github.com>
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.
Summary
Zero-width joiner (U+200D) and zero-width non-joiner (U+200C) are used a lot in Persian and other scripts. micro decoded each of them as a separate character, and since they have a display width of 0, tcell rendered every one of them as its own blank cell. A word like
sl<ZWNJ x8>amwas shown assl am. This also didn't match micro's own width calculations (StringWidth,SliceVisualEnd, softwrap), which already counted these runes as width 0, so the cursor could be placed in the wrong column on lines that contain them.Changes
isMarkininternal/util/unicode.gonow also matchesunicode.Join_Control(U+200C, U+200D). This meansDecodeCharacter/DecodeCharacterInStringattach them to the preceding character the same way they already attach combining marks, andCharacterCountstops counting them. They get sent to the terminal together with the base character and no longer take up a cell of their own.Testing
TestDecodeCharacterJoinControlininternal/util/util_test.go. It fails without the fix (ZWNJ/ZWJ were decoded as separate characters) and passes with it.go test ./...passes,go vet ./internal/util/andgofmt -l internal/are clean, andgo build ./cmd/microsucceeds.Fixes #2155