Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zero-width joined emoji incorrectly displayed #925

Open
Nogesma opened this issue Feb 5, 2024 · 4 comments
Open

Zero-width joined emoji incorrectly displayed #925

Nogesma opened this issue Feb 5, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@Nogesma
Copy link
Contributor

Nogesma commented Feb 5, 2024

Description

When trying to display a zero-width joined emoji like πŸ‘©β€πŸ”¬ ("\u{1f469}\u{200d}\u{1f52c}"), on kitty terminal, kitty will only display πŸ‘© ("\u{1f469}").

This happens because when ratatui calculates the diff of the two terminal buffers, it will not skip the correct amount of cells. It seems to only skip 1 cell instead of the the 3 needed for this emoji. This causes it to overwrite the other cells, which deletes part of the emoji.

I am not exactly sure how the diff is calculated, but it looks like the to_skip value gets overwritten on each loop iteration, which makes it skip only 1 cell, instead of the 3 returned by current.symbol().width().saturating_sub(1).

This issue is only visible on terminals that correctly display this emoji over 4 cells, like kitty.

Expected behaviour

Here's a test that should pass:

#[test]
fn buffer_diffing_zero_width_joined() {
    let mut prev = Buffer::empty(Rect::new(0, 0, 5, 1));
    prev.set_string(0, 0, "aaaaa", Style::default());

    let mut next = Buffer::empty(Rect::new(0, 0, 5, 1));
    next.set_string(0, 0, "\u{1f469}\u{200d}\u{1f52c}", Style::default());

    let diff = prev.diff(&next);

    assert_eq!(
        diff,
        vec![
            (0, 0, &cell("\u{1f469}\u{200d}\u{1f52c}")),
            (4, 0, &cell(" ")),
        ]
    );
}

We instead get

vec![
    (0, 0, &cell("\u{1f469}\u{200d}\u{1f52c}")),
    (2, 0, &cell(" ")),
    (3, 0, &cell(" ")),
    (4, 0, &cell(" ")),
]
@Nogesma Nogesma added the bug Something isn't working label Feb 5, 2024
@kovidgoyal
Copy link

Not that kitty's behavior with ZWJ is incorrect and subject to change in the future, see the open issue about it in the kitty bug tracker.

@joshka
Copy link
Member

joshka commented Feb 6, 2024

Also note #75 which I have no idea how to resolve in a way that satisfies all parties.

@kdheepak
Copy link
Collaborator

kdheepak commented Feb 6, 2024

Relevant issue for Kitty: kovidgoyal/kitty#3810

PS: @kovidgoyal thank you for making and maintaining Kitty (and Calibre)!

@Nogesma
Copy link
Contributor Author

Nogesma commented Feb 6, 2024

Okay, I thought kitty had the right behavior, and that ratatui was not respecting the 4 cell width given by the unicode-width crate.

Feel free to close this if you consider it a duplicate of #75.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants