Skip to content

Commit 9a7d8f5

Browse files
joskeclaude
andauthored
Fix chunk navigation label reset on Insert/Delete chunks (#27)
* Fix chunk navigation label reset on Insert/Delete chunks The cursor_position_notify handler (added for cursor tracking) overwrites current_chunk via chunk_at_cursor() whenever the cursor moves. For Insert chunks where start_a == end_a, the zero-length range check fails and current_chunk is set to None, causing the label to show "3 changes" instead of "Change 3 of 3". Fix by setting current_chunk AFTER place_cursor_at_line calls so the correct value persists after the cursor tracking handler runs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * bump to 0.5.2 --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 4399cd7 commit 9a7d8f5

4 files changed

Lines changed: 8 additions & 4 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mergers"
3-
version = "0.5.1"
3+
version = "0.5.2"
44
edition = "2024"
55
description = "A visual diff and merge tool for files and directories"
66
license = "GPL-2.0"

src/ui/common.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1537,12 +1537,14 @@ pub(super) fn navigate_chunk(
15371537
};
15381538

15391539
if let Some(idx) = diff_state::find_next_chunk(chunks, cursor_line, direction, side, wrap) {
1540-
current_chunk.set(Some(idx));
15411540
let chunk = &chunks[idx];
15421541
scroll_to_line(left_tv, left_buf, chunk.start_a, left_scroll);
15431542
scroll_to_line(right_tv, right_buf, chunk.start_b, right_scroll);
15441543
place_cursor_at_line(left_buf, chunk.start_a);
15451544
place_cursor_at_line(right_buf, chunk.start_b);
1545+
// Set current_chunk AFTER placing cursors, because cursor_position_notify
1546+
// handlers may overwrite it (e.g. for Insert chunks with zero-length ranges).
1547+
current_chunk.set(Some(idx));
15461548
}
15471549
}
15481550

src/ui/merge_view.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,6 @@ fn build_merge_view(
832832
}
833833
};
834834
if let Some((idx, is_right)) = found {
835-
cur.set(Some((idx, is_right)));
836835
if is_right {
837836
// right_chunks: A = middle, B = right
838837
let chunk = &rch[idx];
@@ -852,6 +851,9 @@ fn build_merge_view(
852851
// Right pane: no corresponding line — just scroll to middle line
853852
scroll_to_line(rtv, rb, chunk.start_b, r_scroll);
854853
}
854+
// Set current_chunk AFTER placing cursors, because cursor_position_notify
855+
// handlers may overwrite it (e.g. for Insert chunks with zero-length ranges).
856+
cur.set(Some((idx, is_right)));
855857
lf.queue_draw();
856858
mf.queue_draw();
857859
rf.queue_draw();

0 commit comments

Comments
 (0)