Skip to content

Does TextLength take precedence over column width? #183

@BDisp

Description

@BDisp

Is it really intentional to rely on the TextLength property, which is nothing more than simply obtaining the length of a string in characters, instead of relying on the column width?

If so, I would find it extremely strange after so many corrections regarding this issue. If not, then we will always return to the same point, because it is already known that AI agents only rely on the length in characters instead of the column width, and for this reason, there must be unit tests that avoid the same known problems.

To test this problem, simply paste these two graphemes 🦮👨‍👩‍👧 onto a new line. TextLength will return the length of 2 characters for the first grapheme, which coincidentally is the same value that would be obtained if the GetColumns method were used, but be aware that there are surrogate pairs that, despite having the length of two characters, only occupy 1 column. TextLength will return a size of 11 characters for the second grapheme, but it should be considered 2 columns, a value that would be obtained if the GetColumns method were used. To confirm the undesirable effect of this new calculation, place the cursor at the beginning of the line and press CursorRight. Since it has a size of 2, it will go to the second grapheme. Press CursorRight again and you will see that the cursor does not move to the end of the line, which will happen after the key is pressed again. Note that the second grapheme is a ZWJ. Therefore, in an application that has relied heavily on Unicode and emojis, you cannot rely on the size based on the number of characters in the grapheme, but rather on the width of the grapheme.
In addition to navigation, try deleting the second grapheme by pressing backspace several times, and you will get an exception because isolated surrogates will remain, which are not valid to use without the pair in a text.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions