Buggy Unicode Support
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);
}
~~I've just confirmed that this is not a bug on the iamb side. It’s actually a bug in ratatui.~~
Reference
- https://github.com/simnalamburt/ratatui-practice
- https://docs.rs/unicode-width/
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
- https://github.com/simnalamburt/ratatui-practice
@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?
@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.
Thanks for the guide :) Fixed it
Reference
- https://github.com/ulyssa/modalkit/pull/151
- https://github.com/ulyssa/iamb/pull/358
@ulyssa I'm afraid that this issue has not fixed yet since iamb is still using modalkit v0.0.20. See https://github.com/ulyssa/iamb/pull/358 for the fix. (Otherwise you can release modalkit v0.0.21)