Skip to content

wcswidth incorrect for heart emoji, ❤️ ("\u2764\ufe0f") #96

Closed

Description

@dscrofts

Hello,

The wcswidth function seems to be incorrectly calculating the width of the heart "❤️" ("\u2764\ufe0f") moji. An example:

>>> from wcwidth import wcswidth
>>> wcswidth("❤️")
1
>>> wcswidth("💞")
2
>>> wcswidth("💘")
2

The heart emoji occupies 2 cells and should be returning 2 as per the other examples above.

Activity

  1. changed the title [-]wcswidth incorrect for heart emoji ("❤️")[/-] [+]wcswidth incorrect for heart emoji, ❤️ ("\u2764\ufe0f")[/+] on Oct 31, 2023
  2. jquast commented on Oct 31, 2023

    @jquast
    Owner

    In this case, the first character "\u2764" (❤) is a width of 1, but is then cojoined with a second character, variation selector "\ufe0f" which then modifies the cell length of the first character to 2.

    We don't have any code in wcwidth to detect this special kind of combining, this might be like the Devanagari issue #47, that "combiner may sometimes increase the width of the previous cell, depending on its value"

  3. jquast commented on Oct 31, 2023

    @jquast
    Owner

    this sequence is in https://www.unicode.org/Public/UCD/latest/ucd/emoji/emoji-variation-sequences.txt which doesn't seem to hint about this width modification, but maybe it could be used to test for and make a "narrow to wide variations" table of sorts.

  4. jquast commented on Nov 7, 2023

    @jquast
    Owner

    I have created a solution in #97, I am now testing it with popular terminals, thanks again for the bug report

  5. added a commit that references this issue on Nov 7, 2023
    488a729
  6. added a commit that references this issue on Nov 13, 2023
    42e7af8
  7. jquast commented on Nov 13, 2023

    @jquast
    Owner

    This fix will be soon released in version 0.2.10. I also tested many terminals for VS16 support, only about 28% of those tested support any kind of VS-16 sequence. https://ucs-detect.readthedocs.io/results.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions