fix: Improve "n" key navigation for change blocks

This commit is contained in:
n loewen (aider) 2025-06-08 02:09:28 +01:00
parent 229a1e9360
commit a86704e531
1 changed files with 32 additions and 18 deletions

50
gtm
View File

@ -297,17 +297,24 @@ def jump_to_next_change(state: AppState) -> AppState:
if not state.change_blocks:
return state
# Find the next change block after current position
# Find the next change block after current position or current change index
current_pos = state.right_scroll_offset
next_idx = -1
for i, (start_pos, _) in enumerate(state.change_blocks):
if start_pos > current_pos:
next_idx = i
break
current_idx = state.current_change_idx
# If no next change found, wrap to the first change
if next_idx == -1 and state.change_blocks:
next_idx = 0
# If we're already on a change block, try to move to the next one
if current_idx != -1:
next_idx = (current_idx + 1) % len(state.change_blocks)
else:
# Otherwise find the next change block after current scroll position
next_idx = -1
for i, (start_pos, _) in enumerate(state.change_blocks):
if start_pos > current_pos:
next_idx = i
break
# If no next change found, wrap to the first change
if next_idx == -1 and state.change_blocks:
next_idx = 0
if next_idx != -1:
# Get the start position of the change block
@ -320,17 +327,24 @@ def jump_to_prev_change(state: AppState) -> AppState:
if not state.change_blocks:
return state
# Find the previous change block before current position
# Find the previous change block before current position or current change index
current_pos = state.right_scroll_offset
prev_idx = -1
for i in range(len(state.change_blocks) - 1, -1, -1):
if state.change_blocks[i][0] < current_pos:
prev_idx = i
break
current_idx = state.current_change_idx
# If no previous change found, wrap to the last change
if prev_idx == -1 and state.change_blocks:
prev_idx = len(state.change_blocks) - 1
# If we're already on a change block, try to move to the previous one
if current_idx != -1:
prev_idx = (current_idx - 1) % len(state.change_blocks)
else:
# Otherwise find the previous change block before current scroll position
prev_idx = -1
for i in range(len(state.change_blocks) - 1, -1, -1):
if state.change_blocks[i][0] < current_pos:
prev_idx = i
break
# If no previous change found, wrap to the last change
if prev_idx == -1 and state.change_blocks:
prev_idx = len(state.change_blocks) - 1
if prev_idx != -1:
# Get the start position of the change block