From 72348168dafeffbbb90b55bb79ea0c2976da4c40 Mon Sep 17 00:00:00 2001 From: Ted Feng Date: Thu, 12 Nov 2026 11:10:38 +1300 Subject: [PATCH] Make diff line trimming configurable Add a persisted maximum line length to Appearance preferences, retaining the existing 1000-character default and allowing zero to disable trimming entirely. Apply the shared limit to combined and side-by-side diffs and the merge-conflict editor. Refreshing or reopening a view applies the updated setting. Validate default, custom, and unlimited thresholds across all three presenters, along with preference deserialization, using an isolated headless build. --- src/Resources/Locales/en_US.axaml | 3 ++- src/ViewModels/Preferences.cs | 7 +++++++ src/Views/MergeConflictEditor.axaml.cs | 7 ++++--- src/Views/Preferences.axaml | 18 +++++++++++++++--- src/Views/TextDiffView.axaml.cs | 14 ++++++++------ 5 files changed, 36 insertions(+), 13 deletions(-) diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 603d223a9c..4988b622a9 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -685,6 +685,7 @@ APPEARANCE Default Font Editor Tab Width + Max Diff Line Length (0 = unlimited) Font Size Default Editor @@ -831,7 +832,7 @@ Filter in commit graph filter(s) enabled Focus on Current Branch - + When this is toggled, all history filters will be cleared. And only commits belong to the current branch or its upstream (if it has one) will be listed in `Dashboard` page. Manually add a branch/tag history filter will disable this feature automatically. diff --git a/src/ViewModels/Preferences.cs b/src/ViewModels/Preferences.cs index 9d9fb3f9f9..0b6a7cad17 100644 --- a/src/ViewModels/Preferences.cs +++ b/src/ViewModels/Preferences.cs @@ -105,6 +105,12 @@ public int EditorTabWidth set => SetProperty(ref _editorTabWidth, value); } + public int MaxDiffLineLength + { + get => _maxDiffLineLength; + set => SetProperty(ref _maxDiffLineLength, Math.Max(0, value)); + } + public double Zoom { get => _zoom; @@ -797,6 +803,7 @@ private bool RemoveInvalidRepositoriesRecursive(List collection) private double _defaultFontSize = 13; private double _editorFontSize = 13; private int _editorTabWidth = 4; + private int _maxDiffLineLength = 1000; private double _zoom = 1.0; private LayoutInfo _layout = new(); diff --git a/src/Views/MergeConflictEditor.axaml.cs b/src/Views/MergeConflictEditor.axaml.cs index 79e9c961e5..dd65f9021a 100644 --- a/src/Views/MergeConflictEditor.axaml.cs +++ b/src/Views/MergeConflictEditor.axaml.cs @@ -379,12 +379,13 @@ private void UpdateContent() } var builder = new StringBuilder(); + var maxLineLength = ViewModels.Preferences.Instance.MaxDiffLineLength; foreach (var line in lines) { - if (line.Content.Length > 1000) + if (maxLineLength > 0 && line.Content.Length > maxLineLength) { - builder.Append(line.Content.AsSpan(0, 1000)); - builder.Append($"...({line.Content.Length - 1000} characters trimmed)"); + builder.Append(line.Content.AsSpan(0, maxLineLength)); + builder.Append($"...({line.Content.Length - maxLineLength} characters trimmed)"); } else { diff --git a/src/Views/Preferences.axaml b/src/Views/Preferences.axaml index 6b3aa863ca..3bc677d1ba 100644 --- a/src/Views/Preferences.axaml +++ b/src/Views/Preferences.axaml @@ -188,7 +188,7 @@ - + + + + - - + diff --git a/src/Views/TextDiffView.axaml.cs b/src/Views/TextDiffView.axaml.cs index ee8b41245c..5a6d445070 100644 --- a/src/Views/TextDiffView.axaml.cs +++ b/src/Views/TextDiffView.axaml.cs @@ -1012,12 +1012,13 @@ protected override void OnDataContextChanged(EventArgs e) if (DataContext is ViewModels.CombinedTextDiff { Data: { } diff }) { var builder = new StringBuilder(); + var maxLineLength = ViewModels.Preferences.Instance.MaxDiffLineLength; foreach (var line in diff.Lines) { - if (line.Content.Length > 1000) + if (maxLineLength > 0 && line.Content.Length > maxLineLength) { - builder.Append(line.Content.AsSpan(0, 1000)); - builder.Append($"...({line.Content.Length - 1000} characters trimmed)"); + builder.Append(line.Content.AsSpan(0, maxLineLength)); + builder.Append($"...({line.Content.Length - maxLineLength} characters trimmed)"); } else { @@ -1211,12 +1212,13 @@ protected override void OnDataContextChanged(EventArgs e) { var builder = new StringBuilder(); var lines = IsOld ? diff.Old : diff.New; + var maxLineLength = ViewModels.Preferences.Instance.MaxDiffLineLength; foreach (var line in lines) { - if (line.Content.Length > 1000) + if (maxLineLength > 0 && line.Content.Length > maxLineLength) { - builder.Append(line.Content.AsSpan(0, 1000)); - builder.Append($"...({line.Content.Length - 1000} characters trimmed)"); + builder.Append(line.Content.AsSpan(0, maxLineLength)); + builder.Append($"...({line.Content.Length - maxLineLength} characters trimmed)"); } else {