Skip to content

Commit

Permalink
fix cursor spawning positions in files with tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
Kl4rry committed Dec 2, 2024
1 parent 07324aa commit cc25aa9
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions crates/ferrite-core/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,8 +683,16 @@ impl Buffer {
let new_cursor_pos = if next_width < before_cursor {
next_line_start + next_line.len_bytes()
} else {
let idx = next_line.nth_next_grapheme_boundary_byte(0, before_cursor);
next_line_start + idx
let mut width = 0;
let mut byte_idx = 0;
for grapeheme in next_line.grapehemes() {
width += grapeheme.width(width);
byte_idx += grapeheme.len_bytes();
if width >= before_cursor {
break;
}
}
next_line_start + byte_idx
};

if create_cursor {
Expand Down Expand Up @@ -738,8 +746,16 @@ impl Buffer {
let new_cursor_pos = if next_width < before_cursor {
next_line_start + next_line.len_bytes()
} else {
let idx = next_line.nth_next_grapheme_boundary_byte(0, before_cursor);
next_line_start + idx
let mut width = 0;
let mut byte_idx = 0;
for grapeheme in next_line.grapehemes() {
width += grapeheme.width(width);
byte_idx += grapeheme.len_bytes();
if width >= before_cursor {
break;
}
}
next_line_start + byte_idx
};

if create_cursor {
Expand Down

0 comments on commit cc25aa9

Please sign in to comment.