Skip to content

Commit

Permalink
fix: wrong indexing for unicode
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrreadiness committed Jun 12, 2024
1 parent 0a85a56 commit 4e66fbe
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions wezterm-gui/src/overlay/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,6 @@ impl CopyRenderable {
Pattern::Regex(s) => Pattern::CaseSensitiveString(s.clone()),
};
self.pattern = pattern;
self.search_cursor.x = SEARCH_CURSOR_PADDING + self.pattern.len();
self.schedule_update_search();
}

Expand Down Expand Up @@ -1158,8 +1157,15 @@ impl Pane for CopyOverlay {
if render.pattern.capacity() - render.pattern.len() == 0 {
render.pattern.reserve(10);
}

let position = render.search_cursor.x - SEARCH_CURSOR_PADDING;
render.pattern.insert(position, c);
if position == render.pattern.graphemes(true).count() {
render.pattern.push(c);
} else {
let (offset, _) =
render.pattern.grapheme_indices(true).nth(position).unwrap();
render.pattern.insert(offset, c);
}
render.search_cursor.x += 1;

render.schedule_update_search();
Expand All @@ -1170,7 +1176,12 @@ impl Pane for CopyOverlay {
&& render.search_cursor.x - SEARCH_CURSOR_PADDING > 0
{
let position = render.search_cursor.x - SEARCH_CURSOR_PADDING;
render.pattern.remove(position - 1);
let (offset, _) = render
.pattern
.grapheme_indices(true)
.nth(position - 1)
.unwrap();
render.pattern.remove(offset);
if render.search_cursor.x - SEARCH_CURSOR_PADDING > 0 {
render.search_cursor.x -= 1;
}
Expand All @@ -1183,7 +1194,9 @@ impl Pane for CopyOverlay {
}
}
(KeyCode::RightArrow, KeyModifiers::NONE) => {
if render.search_cursor.x - SEARCH_CURSOR_PADDING < render.pattern.len() {
if render.search_cursor.x - SEARCH_CURSOR_PADDING
< render.pattern.graphemes(true).count()
{
render.search_cursor.x += 1;
}
}
Expand Down

0 comments on commit 4e66fbe

Please sign in to comment.