Skip to content

Conversation

@linenive
Copy link

@linenive linenive commented Sep 8, 2024

This PR fixes issues with UTF-8 handling, specifically for wide characters like Korean.

Fixes

  • Prevents panic when inserting UTF-8 characters by properly checking character boundaries.
  • Corrects cursor positioning for wide characters using the unicode-width crate.

How to test

To test this PR, you can copy and paste the following UTF-8 strings into the input field and observe the behavior.

UTF-8 Strings to test:

  • "안녕하세요" (Korean)
  • "你好世界" (Chinese)
  • "こんにちは世界" (Japanese)
  • "😀😁😂🤣" (Emoji)

Steps:

  • Run the program using the previous version and paste any of the above strings into the input field.
  • Observe whether the program panics when inserting these characters.
  • In the updated version (this PR), ensure that the program no longer panics and that the cursor aligns correctly when wide characters are inserted.

- Resolved panic caused by String.insert when inserting UTF-8 characters (e.g., Korean) due to incorrect handling of char boundaries.
- Added `unicode-width` dependency to properly calculate cursor position for wide characters in the terminal.
- Updated cursor offset calculation to account for character width, ensuring correct cursor display for wide characters.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant