Skip to content

Commit

Permalink
On Wayland, fix invalid offsets being sent in Preedit
Browse files Browse the repository at this point in the history
Even when the protocol explicitly tells to send proper UTF-8
boundaries for cursor, some IMEs don't do that, so sanity check
them before sending downstream.
  • Loading branch information
kchibisov authored Oct 18, 2022
1 parent 462bb4d commit 4f06cfc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ And please only add new entries to the top of this list, right below the `# Unre
- On Windows, emit `ReceivedCharacter` events on system keybindings.
- On Windows, fixed focus event emission on minimize.
- On X11, fixed IME crashing during reload.
- On Wayland, fix byte offset in `Ime::Preedit` pointing to invalid bytes.

# 0.27.3

Expand Down
9 changes: 7 additions & 2 deletions src/platform_impl/linux/wayland/seat/text_input/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,14 @@ pub(super) fn handle_text_input(
cursor_begin,
cursor_end,
} => {
let cursor_begin = usize::try_from(cursor_begin).ok();
let cursor_end = usize::try_from(cursor_end).ok();
let text = text.unwrap_or_default();
let cursor_begin = usize::try_from(cursor_begin)
.ok()
.and_then(|idx| text.is_char_boundary(idx).then(|| idx));
let cursor_end = usize::try_from(cursor_end)
.ok()
.and_then(|idx| text.is_char_boundary(idx).then(|| idx));

inner.pending_preedit = Some(Preedit {
text,
cursor_begin,
Expand Down

0 comments on commit 4f06cfc

Please sign in to comment.