diff --git a/src/Models/DiffResult.cs b/src/Models/DiffResult.cs index d9d21031..eafe44ec 100644 --- a/src/Models/DiffResult.cs +++ b/src/Models/DiffResult.cs @@ -2,6 +2,7 @@ using System.Text; using System.Text.RegularExpressions; +using Avalonia; using Avalonia.Media.Imaging; namespace SourceGit.Models @@ -63,6 +64,7 @@ namespace SourceGit.Models public string File { get; set; } = string.Empty; public List Lines { get; set; } = new List(); public int MaxLineNumber = 0; + public Vector SyncScrollOffset { get; set; } = Vector.Zero; public void GenerateNewPatchFromSelection(Change change, string fileBlobGuid, TextDiffSelection selection, bool revert, string output) { diff --git a/src/Resources/Icons.axaml b/src/Resources/Icons.axaml index a3b59cbf..8f43742c 100644 --- a/src/Resources/Icons.axaml +++ b/src/Resources/Icons.axaml @@ -97,4 +97,5 @@ M408 232C408 210 426 192 448 192h416a40 40 0 110 80H448a40 40 0 01-40-40zM408 512c0-22 18-40 40-40h416a40 40 0 110 80H448A40 40 0 01408 512zM448 752A40 40 0 00448 832h416a40 40 0 100-80H448zM32 480l132 0 0-128 64 0 0 128 132 0 0 64-132 0 0 128-64 0 0-128-132 0Z M408 232C408 210 426 192 448 192h416a40 40 0 110 80H448a40 40 0 01-40-40zM408 512c0-22 18-40 40-40h416a40 40 0 110 80H448A40 40 0 01408 512zM448 752A40 40 0 00448 832h416a40 40 0 100-80H448zM32 480l328 0 0 64-328 0Z M645 448l64 64 220-221L704 64l-64 64 115 115H128v90h628zM375 576l-64-64-220 224L314 960l64-64-116-115H896v-90H262z + M248 221a77 77 0 00-30-21c-18-7-40-10-68-5a224 224 0 00-45 13c-5 2-10 5-15 8l-3 2v68l11-9c10-8 21-14 34-19 13-5 26-7 39-7 12 0 21 3 28 10 6 6 9 16 9 29l-62 9c-14 2-26 6-36 11a80 80 0 00-25 20c-7 8-12 17-15 27-6 21-6 44 1 65a70 70 0 0041 43c10 4 21 6 34 6a80 80 0 0063-28v22h64V298c0-16-2-31-6-44a91 91 0 00-18-33zm-41 121v15c0 8-1 15-4 22a48 48 0 01-24 29 44 44 0 01-33 2 29 29 0 01-10-6 25 25 0 01-6-9 30 30 0 01-2-12c0-5 1-9 2-14a21 21 0 015-9 28 28 0 0110-7 83 83 0 0120-5l42-6zm323-68a144 144 0 00-16-42 87 87 0 00-28-29 75 75 0 00-41-11 73 73 0 00-44 14c-6 5-12 11-17 17V64H326v398h59v-18c8 10 18 17 30 21 6 2 13 3 21 3 16 0 31-4 43-11 12-7 23-18 31-31a147 147 0 0019-46 248 248 0 006-57c0-17-2-33-5-49zm-55 49c0 15-1 28-4 39-2 11-6 20-10 27a41 41 0 01-15 15 37 37 0 01-36 1 44 44 0 01-13-12 59 59 0 01-9-18A76 76 0 01384 352v-33c0-10 1-20 4-29 2-8 6-15 10-22a43 43 0 0115-13 37 37 0 0119-5 35 35 0 0132 18c4 6 7 14 9 23 2 9 3 20 3 31zM154 634a58 58 0 0120-15c14-6 35-7 49-1 7 3 13 6 20 12l21 17V572l-6-4a124 124 0 00-58-14c-20 0-38 4-54 11-16 7-30 17-41 30-12 13-20 29-26 46-6 17-9 36-9 57 0 18 3 36 8 52 6 16 14 30 24 42 10 12 23 21 38 28 15 7 32 10 50 10 15 0 28-2 39-5 11-3 21-8 30-14l5-4v-57l-13 6a26 26 0 01-5 2c-3 1-6 2-8 3-2 1-15 6-15 6-4 2-9 3-14 4a63 63 0 01-38-4 53 53 0 01-20-14 70 70 0 01-13-24 111 111 0 01-5-34c0-13 2-26 5-36 3-10 8-19 14-26zM896 384h-256V320h288c21 1 32 12 32 32v384c0 18-12 32-32 32H504l132 133-45 45-185-185c-16-21-16-25 0-45l185-185L637 576l-128 128H896V384z diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index ad919346..a7f470da 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -166,6 +166,7 @@ SUBMODULE NEW Syntax Highlighting + Line Word Wrap Open In Merge Tool Decrease Number of Visible Lines Increase Number of Visible Lines diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index ba330800..6851458b 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -169,6 +169,7 @@ 子模块 新增 语法高亮 + 自动换行 使用外部合并工具查看 减少可见的行数 增加可见的行数 diff --git a/src/ViewModels/DiffContext.cs b/src/ViewModels/DiffContext.cs index a9bfb804..823f589b 100644 --- a/src/ViewModels/DiffContext.cs +++ b/src/ViewModels/DiffContext.cs @@ -58,12 +58,6 @@ namespace SourceGit.ViewModels private set => SetProperty(ref _content, value); } - public Vector SyncScrollOffset - { - get => _syncScrollOffset; - set => SetProperty(ref _syncScrollOffset, value); - } - public int Unified { get => _unified; @@ -203,6 +197,9 @@ namespace SourceGit.ViewModels Dispatcher.UIThread.Post(() => { + if (_content is Models.TextDiff old && rs is Models.TextDiff cur && old.File == cur.File) + cur.SyncScrollOffset = old.SyncScrollOffset; + FileModeChange = latest.FileModeChange; Content = rs; IsTextDiff = rs is Models.TextDiff; @@ -229,7 +226,6 @@ namespace SourceGit.ViewModels private bool _isLoading = true; private bool _isTextDiff = false; private object _content = null; - private Vector _syncScrollOffset = Vector.Zero; private int _unified = 4; } } diff --git a/src/ViewModels/Preference.cs b/src/ViewModels/Preference.cs index 68dd3532..7b07b4a7 100644 --- a/src/ViewModels/Preference.cs +++ b/src/ViewModels/Preference.cs @@ -164,6 +164,12 @@ namespace SourceGit.ViewModels set => SetProperty(ref _useSyntaxHighlighting, value); } + public bool EnableDiffViewWordWrap + { + get => _enableDiffViewWordWrap; + set => SetProperty(ref _enableDiffViewWordWrap, value); + } + public Models.ChangeViewMode UnstagedChangeViewMode { get => _unstagedChangeViewMode; @@ -526,6 +532,7 @@ namespace SourceGit.ViewModels private bool _useTwoColumnsLayoutInHistories = false; private bool _useSideBySideDiff = false; private bool _useSyntaxHighlighting = false; + private bool _enableDiffViewWordWrap = false; private Models.ChangeViewMode _unstagedChangeViewMode = Models.ChangeViewMode.List; private Models.ChangeViewMode _stagedChangeViewMode = Models.ChangeViewMode.List; diff --git a/src/ViewModels/WorkingCopy.cs b/src/ViewModels/WorkingCopy.cs index 4167c244..3d481153 100644 --- a/src/ViewModels/WorkingCopy.cs +++ b/src/ViewModels/WorkingCopy.cs @@ -273,10 +273,6 @@ namespace SourceGit.ViewModels Staged = staged; _isLoadingData = false; - var scrollOffset = Vector.Zero; - if (_detailContext is DiffContext old) - scrollOffset = old.SyncScrollOffset; - if (selectedUnstaged.Count > 0) SelectedUnstaged = selectedUnstaged; else if (selectedStaged.Count > 0) @@ -284,9 +280,6 @@ namespace SourceGit.ViewModels else SetDetail(null); - if (_detailContext is DiffContext cur) - cur.SyncScrollOffset = scrollOffset; - // Try to load merge message from MERGE_MSG if (string.IsNullOrEmpty(_commitMessage)) { diff --git a/src/Views/DiffView.axaml b/src/Views/DiffView.axaml index 9705715c..d8ed4356 100644 --- a/src/Views/DiffView.axaml +++ b/src/Views/DiffView.axaml @@ -41,7 +41,7 @@ - + + + + + - + SyncScrollOffset="{Binding #ThisControl.TextDiff.SyncScrollOffset, Mode=TwoWay}" + UseSyntaxHighlighting="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSyntaxHighlighting}" + WordWrap="{Binding Source={x:Static vm:Preference.Instance}, Path=EnableDiffViewWordWrap}"/>