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

Fixed Windows Terminal UTF-16 surrogate pair issue #857

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kazatsuyu
Copy link

@kazatsuyu kazatsuyu commented Jan 10, 2024

Resolve #848

Windows Terminal seems to send the characters represented by surrogate pairs in the following order:

  1. key down event for the upper surrogate
  2. key up event for the upper surrogate
  3. key down event for the lower surrogate
  4. key up event for the lower surrogate

On the other hand, crossterm's surrogate pair handling does not distinguish between key-down/key-up events. This may be reasonable, as there are cases where another terminal sends only key-up events, but this results in an incorrect sequence of input from the Windows Terminal.

This fix uses only the last input in the case of a sequence of upper surrogates and ignores the input of lower surrogates with no upper surrogates; in the Windows Terminal, inputs 1 and 4 above are ignored and a single surrogate pair is created from inputs 2 and 3.

*surrogate_buffer = Some(new_surrogate);
None
}
if new_surrogate < 0xDC00 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this value represent. A constant would help document this.

@@ -61,19 +61,16 @@ pub(crate) fn handle_key_event(
}

fn handle_surrogate(surrogate_buffer: &mut Option<u16>, new_surrogate: u16) -> Option<char> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method could do with an explanation that clarifies the intent as well as some unit tests for the same.

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.

Surrogate pairs are ignored on Windows Terminal
2 participants