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

Buggy Unicode Support #293

Closed
d34db3ff opened this issue May 26, 2024 · 6 comments · May be fixed by #358
Closed

Buggy Unicode Support #293

d34db3ff opened this issue May 26, 2024 · 6 comments · May be fixed by #358
Labels
modalkit Issues that require an accompanying modalkit change
Milestone

Comments

@d34db3ff
Copy link

d34db3ff commented May 26, 2024

The cursor does not align correctly with user input when typing certain Unicode characters, such as Chinese characters or emojis. This issue appears to be caused by the presence of certain Unicode characters in the buffer, which results in get_term_cursor() returning an incorrect value.

main.rs: 321
if let Some((cx, cy)) = sstate.get_term_cursor() {
                if let Some(c) = cursor {
                    let style = Style::default().fg(Color::Green);
                    let span = Span::styled(c.to_string(), style);
                    let para = Paragraph::new(span);
                    let inner = Rect::new(cx, cy, 1, 1);
                    f.render_widget(para, inner)
                }
                f.set_cursor(cx, cy);
}

@ulyssa ulyssa added the modalkit Issues that require an accompanying modalkit change label Aug 1, 2024
@ulyssa ulyssa added this to the v0.0.11 milestone Aug 1, 2024
@simnalamburt
Copy link

simnalamburt commented Sep 26, 2024

I've just confirmed that this is not a bug on the iamb side. It’s actually a bug in ratatui.

Reference

@simnalamburt
Copy link

Sorry for the confusion. I've just confirmed that it’s actually a bug on the iamb side. I was able to create a small PoC and patch for it.
Diff: (40d92a2)

@@ -28,7 +28,7 @@ impl State {
     }

     fn cursor(&self) -> u16 {
-        self.idx_chars as u16
+        self.input[..self.idx_bytes()].width_cjk() as u16
     }
 }

Before:

After:

Reference

@simnalamburt
Copy link

@ulyssa I’m willing to fix this issue on my own, but I’m not familiar with the iamb codebase. Could you give me a rough hint on where I should start?

@ulyssa
Copy link
Owner

ulyssa commented Sep 29, 2024

@simnalamburt thank you for looking into this! You will want to update how coff is calculated here and here to use the unicode-width crate.

simnalamburt added a commit to simnalamburt/modalkit that referenced this issue Sep 29, 2024
simnalamburt added a commit to simnalamburt/iamb that referenced this issue Sep 29, 2024
@simnalamburt
Copy link

simnalamburt commented Sep 29, 2024

Thanks for the guide :) Fixed it

Reference

@simnalamburt
Copy link

simnalamburt commented Nov 27, 2024

@ulyssa I'm afraid that this issue has not fixed yet since iamb is still using modalkit v0.0.20. See #358 for the fix. (Otherwise you can release modalkit v0.0.21)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
modalkit Issues that require an accompanying modalkit change
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants