From d8af7e2c887936ef6fe6df399a02af2374d5a614 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 12 Mar 2026 12:59:46 +0530 Subject: [PATCH] Add an option to control highlighting of moved lines --- docs/changelog.rst | 2 ++ kittens/diff/main.py | 8 ++++++-- kittens/diff/patch.go | 2 +- kittens/diff/render.go | 6 +++--- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 4e5a84f2b..bf0dfad8b 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -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`) diff --git a/kittens/diff/main.py b/kittens/diff/main.py index 808e59644..9d6ed6ca4 100644 --- a/kittens/diff/main.py +++ b/kittens/diff/main.py @@ -65,6 +65,10 @@ Can be specified multiple times to use multiple patterns. For example:: ''', ) +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 @@ opt('added_margin_bg', '#cdffd8', option_type='to_color') 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') diff --git a/kittens/diff/patch.go b/kittens/diff/patch.go index b1779a52e..9df622ad7 100644 --- a/kittens/diff/patch.go +++ b/kittens/diff/patch.go @@ -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 diff --git a/kittens/diff/render.go b/kittens/diff/render.go index e8db88c0a..9dfd7046e 100644 --- a/kittens/diff/render.go +++ b/kittens/diff/render.go @@ -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 {