Add an option to control highlighting of moved lines

This commit is contained in:
Kovid Goyal 2026-03-12 12:59:46 +05:30
parent f45345c7a7
commit d8af7e2c88
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
4 changed files with 12 additions and 6 deletions

View file

@ -168,6 +168,8 @@ Detailed list of changes
0.46.1 [future]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- diff kitten: Highlight moved lines using a different background color (:opt:`kitten-diff.mark_moved_lines`) (:iss:`3241`)
- Fix a regression that broke ``kitten update-self`` (:iss:`9642`)
- macOS: Clear bell alert badge on dock icon on mouse/keyboard activity (:iss:`9640`)

View file

@ -65,6 +65,10 @@ def main(args: list[str]) -> None:
''',
)
opt('mark_moved_lines', 'yes', option_type='to_bool', long_text='''
Highlight lines that are moved, that is removed from the left and added to the right
differently, using the :opt:`moved_bg` color.''')
opt('word_diff_mode', 'words', choices=('words', 'central'),
long_text='''
The algorithm to use for highlighting which parts of changed lines differ.
@ -153,10 +157,10 @@ def main(args: list[str]) -> None:
opt('dark_added_margin_bg', '#31503d', option_type='to_color')
opt('moved_bg', '#fffde7', option_type='to_color', long_text='Moved text backgrounds (same text that was removed in one place and added in another)')
opt('dark_moved_bg', '#2c2200', option_type='to_color')
opt('dark_moved_bg', '#003333', option_type='to_color')
opt('moved_margin_bg', '#fff3b0', option_type='to_color')
opt('dark_moved_margin_bg', '#4a3800', option_type='to_color')
opt('dark_moved_margin_bg', '#00495b', option_type='to_color')
opt('filler_bg', '#fafbfc', option_type='to_color', long_text='Filler (empty) line background')
opt('dark_filler_bg', '#262c36', option_type='to_color')

View file

@ -544,7 +544,7 @@ func parse_patch(raw string, left_lines, right_lines []string) (ans *Patch, err
ans.largest_line_number = ans.all_hunks[len(ans.all_hunks)-1].largest_line_number
}
err = ans.compute_centers(left_lines, right_lines)
if err == nil {
if err == nil && conf.Mark_moved_lines {
ans.detect_moved_lines(left_lines, right_lines)
}
return

View file

@ -547,9 +547,9 @@ type DiffData struct {
left_path, right_path string
available_cols, margin_size int
left_lines, right_lines []string
left_moved_lines *utils.Set[int]
right_moved_lines *utils.Set[int]
left_lines, right_lines []string
left_moved_lines *utils.Set[int]
right_moved_lines *utils.Set[int]
}
func hunk_title(hunk *Hunk) string {