Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

vim: Fix increment panicking due to invalid utf8 offsets (#43101)

Lukas Wirth5052a460b4b3
diff --git a/crates/vim/src/normal/increment.rs b/crates/vim/src/normal/increment.rs
index a6a76b22aa1..d9ef32deba5 100644
--- a/crates/vim/src/normal/increment.rs
+++ b/crates/vim/src/normal/increment.rs
@@ -210,12 +210,12 @@ fn find_target(
.map_or(false, |ch| ch.is_ascii_hexdigit());
let mut pre_char = String::new();
+ let next_offset = offset
+ + snapshot
+ .chars_at(start_offset)
+ .next()
+ .map_or(0, |ch| ch.len_utf8());
// Backward scan to find the start of the number, but stop at start_offset
- let next_offset = if offset < snapshot.len() {
- offset + 1usize
- } else {
- offset
- };
for ch in snapshot.reversed_chars_at(next_offset) {
// Search boundaries
if offset.0 == 0 || ch.is_whitespace() || (need_range && offset <= start_offset) {
@@ -823,6 +823,14 @@ mod test {
cx.set_state("trueˇ 1 2 3", Mode::Normal);
cx.simulate_keystrokes("ctrl-a");
cx.assert_state("true ˇ2 2 3", Mode::Normal);
+
+ cx.set_state("falseˇ", Mode::Normal);
+ cx.simulate_keystrokes("ctrl-a");
+ cx.assert_state("truˇe", Mode::Normal);
+
+ cx.set_state("⚡️ˇ⚡️", Mode::Normal);
+ cx.simulate_keystrokes("ctrl-a");
+ cx.assert_state("⚡️ˇ⚡️", Mode::Normal);
}
#[gpui::test]