mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-24 20:57:19 -08:00
code_review: PR #703
* change the name of this feature to `Enable Block-Navigation` * change the icon of the toggle button used to enable this feature * use a new class `BlockNavigation` to hold all the data about this feature * create `BlockNavigation` data only when it is enabled Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
0c04cccd52
commit
15d3ad355d
14 changed files with 277 additions and 323 deletions
|
@ -51,9 +51,6 @@ namespace SourceGit.Commands
|
|||
_result.TextDiff.MaxLineNumber = Math.Max(_newLine, _oldLine);
|
||||
}
|
||||
|
||||
if (_result.TextDiff != null)
|
||||
_result.TextDiff.ProcessChangeBlocks();
|
||||
|
||||
return _result;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
using Avalonia;
|
||||
using Avalonia.Media.Imaging;
|
||||
|
||||
|
@ -61,70 +59,16 @@ namespace SourceGit.Models
|
|||
}
|
||||
}
|
||||
|
||||
public class TextDiffChangeBlock
|
||||
{
|
||||
public TextDiffChangeBlock(int startLine, int endLine)
|
||||
{
|
||||
StartLine = startLine;
|
||||
EndLine = endLine;
|
||||
}
|
||||
|
||||
public int StartLine { get; set; } = 0;
|
||||
public int EndLine { get; set; } = 0;
|
||||
|
||||
public bool IsInRange(int line)
|
||||
{
|
||||
return line >= StartLine && line <= EndLine;
|
||||
}
|
||||
}
|
||||
|
||||
public partial class TextDiff : ObservableObject
|
||||
public partial class TextDiff
|
||||
{
|
||||
public string File { get; set; } = string.Empty;
|
||||
public List<TextDiffLine> Lines { get; set; } = new List<TextDiffLine>();
|
||||
public Vector ScrollOffset { get; set; } = Vector.Zero;
|
||||
public int MaxLineNumber = 0;
|
||||
|
||||
public int CurrentChangeBlockIdx
|
||||
{
|
||||
get => _currentChangeBlockIdx;
|
||||
set => SetProperty(ref _currentChangeBlockIdx, value);
|
||||
}
|
||||
|
||||
public string Repo { get; set; } = null;
|
||||
public DiffOption Option { get; set; } = null;
|
||||
|
||||
public List<TextDiffChangeBlock> ChangeBlocks { get; set; } = [];
|
||||
|
||||
public void ProcessChangeBlocks()
|
||||
{
|
||||
ChangeBlocks.Clear();
|
||||
int lineIdx = 0, blockStartIdx = 0;
|
||||
bool isNewBlock = true;
|
||||
foreach (var line in Lines)
|
||||
{
|
||||
lineIdx++;
|
||||
if (line.Type == Models.TextDiffLineType.Added ||
|
||||
line.Type == Models.TextDiffLineType.Deleted ||
|
||||
line.Type == Models.TextDiffLineType.None) // Empty
|
||||
{
|
||||
if (isNewBlock)
|
||||
{
|
||||
isNewBlock = false;
|
||||
blockStartIdx = lineIdx;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!isNewBlock)
|
||||
{
|
||||
ChangeBlocks.Add(new TextDiffChangeBlock(blockStartIdx, lineIdx - 1));
|
||||
isNewBlock = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public TextDiffSelection MakeSelection(int startLine, int endLine, bool isCombined, bool isOldSide)
|
||||
{
|
||||
var rs = new TextDiffSelection();
|
||||
|
@ -682,8 +626,6 @@ namespace SourceGit.Models
|
|||
return true;
|
||||
}
|
||||
|
||||
private int _currentChangeBlockIdx = -1; // NOTE: Use -1 as "not set".
|
||||
|
||||
[GeneratedRegex(@"^@@ \-(\d+),?\d* \+(\d+),?\d* @@")]
|
||||
private static partial Regex REG_INDICATOR();
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
<StreamGeometry x:Key="Icons.Clean">M797 829a49 49 0 1049 49 49 49 0 00-49-49zm147-114A49 49 0 10992 764a49 49 0 00-49-49zM928 861a49 49 0 1049 49A49 49 0 00928 861zm-5-586L992 205 851 64l-71 71a67 67 0 00-94 0l235 235a67 67 0 000-94zm-853 128a32 32 0 00-32 50 1291 1291 0 0075 112L288 552c20 0 25 21 8 37l-93 86a1282 1282 0 00120 114l100-32c19-6 28 15 14 34l-40 55c26 19 53 36 82 53a89 89 0 00115-20 1391 1391 0 00256-485l-188-188s-306 224-595 198z</StreamGeometry>
|
||||
<StreamGeometry x:Key="Icons.Clone">M1280 704c0 141-115 256-256 256H288C129 960 0 831 0 672c0-126 80-232 192-272A327 327 0 01192 384c0-177 143-320 320-320 119 0 222 64 277 160C820 204 857 192 896 192c106 0 192 86 192 192 0 24-5 48-13 69C1192 477 1280 580 1280 704zm-493-128H656V352c0-18-14-32-32-32h-96c-18 0-32 14-32 32v224h-131c-29 0-43 34-23 55l211 211c12 12 33 12 45 0l211-211c20-20 6-55-23-55z</StreamGeometry>
|
||||
<StreamGeometry x:Key="Icons.Code">M853 102H171C133 102 102 133 102 171v683C102 891 133 922 171 922h683C891 922 922 891 922 853V171C922 133 891 102 853 102zM390 600l-48 48L205 512l137-137 48 48L301 512l88 88zM465 819l-66-18L559 205l66 18L465 819zm218-171L634 600 723 512l-88-88 48-48L819 512 683 649z</StreamGeometry>
|
||||
<StreamGeometry x:Key="Icons.CodeBlock">M320 171A21 21 0 00299 192v213c0 49-32 85-61 107 30 22 61 58 61 107V832A21 21 0 00320 853h85v85H320A107 107 0 01213 832V619c0-11-8-26-32-42a157 157 0 00-33-17c-11-4-18-5-20-5v-85c2 0 9-1 20-5a157 157 0 0033-17c24-16 32-32 32-42V192A107 107 0 01320 85h85v85H320zm384 0h-85V85H704A107 107 0 01811 192v213c0 11 8 26 32 42 11 7 22 13 33 17 11 4 18 5 20 5v85c-2 0-9 1-20 5a157 157 0 00-33 17c-24 16-32 31-32 42V832A107 107 0 01704 939h-85v-85H704A21 21 0 00725 832V619c0-49 32-85 61-107-30-22-61-58-61-107V192A21 21 0 00704 171z</StreamGeometry>
|
||||
<StreamGeometry x:Key="Icons.ColorPicker">M128 854h768v86H128zM390 797c13 13 29 19 48 19s35-6 45-19l291-288c26-22 26-64 0-90L435 83l-61 61L426 192l-272 269c-22 22-22 64 0 90l237 246zm93-544 211 211-32 32H240l243-243zM707 694c0 48 38 86 86 86 48 0 86-38 86-86 0-22-10-45-26-61L794 576l-61 61c-13 13-26 35-26 58z</StreamGeometry>
|
||||
<StreamGeometry x:Key="Icons.Commit">M796 471A292 292 0 00512 256a293 293 0 00-284 215H0v144h228A293 293 0 00512 832a291 291 0 00284-217H1024V471h-228M512 688A146 146 0 01366 544A145 145 0 01512 400c80 0 146 63 146 144A146 146 0 01512 688</StreamGeometry>
|
||||
<StreamGeometry x:Key="Icons.CommitMessageGenerator">M796 561a5 5 0 014 7l-39 90a5 5 0 004 7h100a5 5 0 014 8l-178 247a5 5 0 01-9-4l32-148a5 5 0 00-5-6h-89a5 5 0 01-4-7l86-191a5 5 0 014-3h88zM731 122a73 73 0 0173 73v318a54 54 0 00-8-1H731V195H244v634h408l-16 73H244a73 73 0 01-73-73V195a73 73 0 0173-73h488zm-219 366v73h-195v-73h195zm146-146v73H317v-73h341z</StreamGeometry>
|
||||
|
@ -54,7 +55,6 @@
|
|||
<StreamGeometry x:Key="Icons.Grid">M30 271l241 0 0-241-241 0 0 241zM392 271l241 0 0-241-241 0 0 241zM753 30l0 241 241 0 0-241-241 0zM30 632l241 0 0-241-241 0 0 241zM392 632l241 0 0-241-241 0 0 241zM753 632l241 0 0-241-241 0 0 241zM30 994l241 0 0-241-241 0 0 241zM392 994l241 0 0-241-241 0 0 241zM753 994l241 0 0-241-241 0 0 241z</StreamGeometry>
|
||||
<StreamGeometry x:Key="Icons.Head">M0 512M1024 512M512 0M512 1024M955 323q0 23-16 39l-414 414-78 78q-16 16-39 16t-39-16l-78-78-207-207q-16-16-16-39t16-39l78-78q16-16 39-16t39 16l168 169 375-375q16-16 39-16t39 16l78 78q16 16 16 39z</StreamGeometry>
|
||||
<StreamGeometry x:Key="Icons.HiddenSymbol">M416 64H768v64h-64v704h64v64H448v-64h64V512H416a224 224 0 1 1 0-448zM576 832h64V128H576v704zM416 128H512v320H416a160 160 0 0 1 0-320z</StreamGeometry>
|
||||
<StreamGeometry x:Key="Icons.Highlight">M20.2585648,2.00438474 C20.6382605,2.00472706 20.9518016,2.28716326 21.0011348,2.65328337 L21.0078899,2.75506004 L21.0038407,7.25276883 C21.0009137,8.40908568 20.1270954,9.36072944 19.0029371,9.48671858 L19.0024932,11.7464847 C19.0024932,12.9373487 18.0773316,13.9121296 16.906542,13.9912939 L16.7524932,13.9964847 L16.501,13.9963847 L16.5017549,16.7881212 C16.5017549,17.6030744 16.0616895,18.349347 15.3600767,18.7462439 L15.2057929,18.8258433 L8.57108142,21.9321389 C8.10484975,22.1504232 7.57411944,21.8450614 7.50959937,21.3535767 L7.50306874,21.2528982 L7.503,13.9963847 L7.25,13.9964847 C6.05913601,13.9964847 5.08435508,13.0713231 5.00519081,11.9005335 L5,11.7464847 L5.00043957,9.4871861 C3.92882124,9.36893736 3.08392302,8.49812196 3.0058865,7.41488149 L3,7.25086975 L3,2.75438506 C3,2.3401715 3.33578644,2.00438474 3.75,2.00438474 C4.12969577,2.00438474 4.44349096,2.28653894 4.49315338,2.6526145 L4.5,2.75438506 L4.5,7.25086975 C4.5,7.63056552 4.78215388,7.94436071 5.14822944,7.99402313 L5.25,8.00086975 L18.7512697,8.00087075 C19.1315998,8.00025031 19.4461483,7.71759877 19.4967392,7.3518545 L19.5038434,7.25019537 L19.5078902,2.75371008 C19.508263,2.33949668 19.8443515,2.00401258 20.2585648,2.00438474 Z M15.001,13.9963847 L9.003,13.9963847 L9.00306874,20.0736262 L14.5697676,17.4673619 C14.8004131,17.3593763 14.9581692,17.1431606 14.9940044,16.89581 L15.0017549,16.7881212 L15.001,13.9963847 Z M17.502,9.50038474 L6.5,9.50038474 L6.5,11.7464847 C6.5,12.1261805 6.78215388,12.4399757 7.14822944,12.4896381 L7.25,12.4964847 L16.7524932,12.4964847 C17.1321889,12.4964847 17.4459841,12.2143308 17.4956465,11.8482552 L17.5024932,11.7464847 L17.502,9.50038474 Z</StreamGeometry>
|
||||
<StreamGeometry x:Key="Icons.Histories">M24 512A488 488 0 01512 24A488 488 0 011000 512A488 488 0 01512 1000A488 488 0 0124 512zm447-325v327L243 619l51 111 300-138V187H471z</StreamGeometry>
|
||||
<StreamGeometry x:Key="Icons.Home">M832 64h128v278l-128-146V64zm64 448L512 73 128 512H0L448 0h128l448 512h-128zm0 83V1024H640V704c0-35-29-64-64-64h-128a64 64 0 00-64 64v320H128V595l384-424 384 424z</StreamGeometry>
|
||||
<StreamGeometry x:Key="Icons.Hotkeys">M512 0C229 0 0 229 0 512c0 283 229 512 512 512s512-229 512-512c0-283-229-512-512-512zm0 958C266 958 66 758 66 512S266 66 512 66 958 266 958 512 758 958 512 958zM192 416h96a32 32 0 0032-32v-32a32 32 0 00-32-32H192a32 32 0 00-32 32v32a32 32 0 0032 32zM384 416h96a32 32 0 0032-32v-32a32 32 0 00-32-32h-96a32 32 0 00-32 32v32a32 32 0 0032 32zM576 416h96a32 32 0 0032-32v-32a32 32 0 00-32-32h-96a32 32 0 00-32 32v32a32 32 0 0032 32zM832 320h-64a32 32 0 00-32 32v128h-160a32 32 0 00-32 32v32a32 32 0 0032 32h256a32 32 0 0032-32v-192a32 32 0 00-32-32zM320 544v-32a32 32 0 00-32-32H192a32 32 0 00-32 32v32a32 32 0 0032 32h96a32 32 0 0032-32zM384 576h96a32 32 0 0032-32v-32a32 32 0 00-32-32h-96a32 32 0 00-32 32v32a32 32 0 0032 32zM800 640H256a32 32 0 00-32 32v32a32 32 0 0032 32h544a32 32 0 0032-32v-32a32 32 0 00-32-32z</StreamGeometry>
|
||||
|
|
|
@ -233,7 +233,6 @@
|
|||
<x:String x:Key="Text.Diff.Binary.New" xml:space="preserve">NEW</x:String>
|
||||
<x:String x:Key="Text.Diff.Binary.Old" xml:space="preserve">OLD</x:String>
|
||||
<x:String x:Key="Text.Diff.Copy" xml:space="preserve">Copy</x:String>
|
||||
<x:String x:Key="Text.Diff.HighlightedDiffNavigation" xml:space="preserve">Highlighted Diff Navigation</x:String>
|
||||
<x:String x:Key="Text.Diff.FileModeChanged" xml:space="preserve">File Mode Changed</x:String>
|
||||
<x:String x:Key="Text.Diff.IgnoreWhitespace" xml:space="preserve">Ignore Whitespace Change</x:String>
|
||||
<x:String x:Key="Text.Diff.LFS" xml:space="preserve">LFS OBJECT CHANGE</x:String>
|
||||
|
@ -248,6 +247,7 @@
|
|||
<x:String x:Key="Text.Diff.SwapCommits" xml:space="preserve">Swap</x:String>
|
||||
<x:String x:Key="Text.Diff.SyntaxHighlight" xml:space="preserve">Syntax Highlighting</x:String>
|
||||
<x:String x:Key="Text.Diff.ToggleWordWrap" xml:space="preserve">Line Word Wrap</x:String>
|
||||
<x:String x:Key="Text.Diff.UseBlockNavigation" xml:space="preserve">Enable Block-Navigation</x:String>
|
||||
<x:String x:Key="Text.Diff.UseMerger" xml:space="preserve">Open in Merge Tool</x:String>
|
||||
<x:String x:Key="Text.Diff.VisualLines.All" xml:space="preserve">Show All Lines</x:String>
|
||||
<x:String x:Key="Text.Diff.VisualLines.Decr" xml:space="preserve">Decrease Number of Visible Lines</x:String>
|
||||
|
|
|
@ -250,6 +250,7 @@
|
|||
<x:String x:Key="Text.Diff.SwapCommits" xml:space="preserve">交换比对双方</x:String>
|
||||
<x:String x:Key="Text.Diff.SyntaxHighlight" xml:space="preserve">语法高亮</x:String>
|
||||
<x:String x:Key="Text.Diff.ToggleWordWrap" xml:space="preserve">自动换行</x:String>
|
||||
<x:String x:Key="Text.Diff.UseBlockNavigation" xml:space="preserve">启用基于变更块的跳转</x:String>
|
||||
<x:String x:Key="Text.Diff.UseMerger" xml:space="preserve">使用外部合并工具查看</x:String>
|
||||
<x:String x:Key="Text.Diff.VisualLines.All" xml:space="preserve">显示完整文件</x:String>
|
||||
<x:String x:Key="Text.Diff.VisualLines.Decr" xml:space="preserve">减少可见的行数</x:String>
|
||||
|
|
|
@ -250,6 +250,7 @@
|
|||
<x:String x:Key="Text.Diff.SwapCommits" xml:space="preserve">交換比對雙方</x:String>
|
||||
<x:String x:Key="Text.Diff.SyntaxHighlight" xml:space="preserve">語法上色</x:String>
|
||||
<x:String x:Key="Text.Diff.ToggleWordWrap" xml:space="preserve">自動換行</x:String>
|
||||
<x:String x:Key="Text.Diff.UseBlockNavigation" xml:space="preserve">啟用基於變更區塊的導航</x:String>
|
||||
<x:String x:Key="Text.Diff.UseMerger" xml:space="preserve">使用外部合併工具檢視</x:String>
|
||||
<x:String x:Key="Text.Diff.VisualLines.All" xml:space="preserve">顯示檔案的全部內容</x:String>
|
||||
<x:String x:Key="Text.Diff.VisualLines.Decr" xml:space="preserve">減少可見的行數</x:String>
|
||||
|
|
122
src/ViewModels/BlockNavigation.cs
Normal file
122
src/ViewModels/BlockNavigation.cs
Normal file
|
@ -0,0 +1,122 @@
|
|||
using System.Collections.Generic;
|
||||
using Avalonia.Collections;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace SourceGit.ViewModels
|
||||
{
|
||||
public class BlockNavigation : ObservableObject
|
||||
{
|
||||
public class Block
|
||||
{
|
||||
public int Start { get; set; } = 0;
|
||||
public int End { get; set; } = 0;
|
||||
|
||||
public Block(int start, int end)
|
||||
{
|
||||
Start = start;
|
||||
End = end;
|
||||
}
|
||||
|
||||
public bool IsInRange(int line)
|
||||
{
|
||||
return line >= Start && line <= End;
|
||||
}
|
||||
}
|
||||
|
||||
public AvaloniaList<Block> Blocks
|
||||
{
|
||||
get;
|
||||
} = [];
|
||||
|
||||
public int Current
|
||||
{
|
||||
get => _current;
|
||||
private set => SetProperty(ref _current, value);
|
||||
}
|
||||
|
||||
public string Indicator
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Blocks.Count == 0)
|
||||
return "-/-";
|
||||
|
||||
if (_current >= 0 && _current < Blocks.Count)
|
||||
return $"{_current+1}/{Blocks.Count}";
|
||||
|
||||
return $"-/{Blocks.Count}";
|
||||
}
|
||||
}
|
||||
|
||||
public BlockNavigation(object context)
|
||||
{
|
||||
Blocks.Clear();
|
||||
Current = -1;
|
||||
|
||||
var lines = new List<Models.TextDiffLine>();
|
||||
if (context is Models.TextDiff combined)
|
||||
lines = combined.Lines;
|
||||
else if (context is TwoSideTextDiff twoSide)
|
||||
lines = twoSide.Old;
|
||||
|
||||
if (lines.Count == 0)
|
||||
return;
|
||||
|
||||
var lineIdx = 0;
|
||||
var blockStartIdx = 0;
|
||||
var isNewBlock = true;
|
||||
var blocks = new List<Block>();
|
||||
|
||||
foreach (var line in lines)
|
||||
{
|
||||
lineIdx++;
|
||||
if (line.Type == Models.TextDiffLineType.Added ||
|
||||
line.Type == Models.TextDiffLineType.Deleted ||
|
||||
line.Type == Models.TextDiffLineType.None)
|
||||
{
|
||||
if (isNewBlock)
|
||||
{
|
||||
isNewBlock = false;
|
||||
blockStartIdx = lineIdx;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!isNewBlock)
|
||||
{
|
||||
blocks.Add(new Block(blockStartIdx, lineIdx - 1));
|
||||
isNewBlock = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isNewBlock)
|
||||
blocks.Add(new Block(blockStartIdx, lines.Count - 1));
|
||||
|
||||
Blocks.AddRange(blocks);
|
||||
}
|
||||
|
||||
public Block GetCurrentBlock()
|
||||
{
|
||||
return (_current >= 0 && _current < Blocks.Count) ? Blocks[_current] : null;
|
||||
}
|
||||
|
||||
public Block GotoNext()
|
||||
{
|
||||
if (Blocks.Count == 0) return null;
|
||||
|
||||
Current = (_current + 1) % Blocks.Count;
|
||||
return Blocks[_current];
|
||||
}
|
||||
|
||||
public Block GotoPrev()
|
||||
{
|
||||
if (Blocks.Count == 0) return null;
|
||||
|
||||
Current = _current == -1 ? Blocks.Count - 1 : (_current - 1 + Blocks.Count) % Blocks.Count;
|
||||
return Blocks[_current];
|
||||
}
|
||||
|
||||
private int _current = -1;
|
||||
}
|
||||
}
|
|
@ -51,12 +51,6 @@ namespace SourceGit.ViewModels
|
|||
private set => SetProperty(ref _unifiedLines, value);
|
||||
}
|
||||
|
||||
public string ChangeBlockIndicator
|
||||
{
|
||||
get => _changeBlockIndicator;
|
||||
private set => SetProperty(ref _changeBlockIndicator, value);
|
||||
}
|
||||
|
||||
public DiffContext(string repo, Models.DiffOption option, DiffContext previous = null)
|
||||
{
|
||||
_repo = repo;
|
||||
|
@ -79,68 +73,12 @@ namespace SourceGit.ViewModels
|
|||
LoadDiffContent();
|
||||
}
|
||||
|
||||
public void PrevChange()
|
||||
{
|
||||
if (_content is Models.TextDiff textDiff)
|
||||
{
|
||||
if (textDiff.CurrentChangeBlockIdx > 0)
|
||||
{
|
||||
textDiff.CurrentChangeBlockIdx--;
|
||||
}
|
||||
else if (textDiff.ChangeBlocks.Count > 0)
|
||||
{
|
||||
// Force property value change and (re-)jump to first change block
|
||||
textDiff.CurrentChangeBlockIdx = -1;
|
||||
textDiff.CurrentChangeBlockIdx = 0;
|
||||
}
|
||||
}
|
||||
RefreshChangeBlockIndicator();
|
||||
}
|
||||
|
||||
public void NextChange()
|
||||
{
|
||||
if (_content is Models.TextDiff textDiff)
|
||||
{
|
||||
if (textDiff.CurrentChangeBlockIdx < textDiff.ChangeBlocks.Count - 1)
|
||||
{
|
||||
textDiff.CurrentChangeBlockIdx++;
|
||||
}
|
||||
else if (textDiff.ChangeBlocks.Count > 0)
|
||||
{
|
||||
// Force property value change and (re-)jump to last change block
|
||||
textDiff.CurrentChangeBlockIdx = -1;
|
||||
textDiff.CurrentChangeBlockIdx = textDiff.ChangeBlocks.Count - 1;
|
||||
}
|
||||
RefreshChangeBlockIndicator();
|
||||
}
|
||||
}
|
||||
|
||||
public void RefreshChangeBlockIndicator()
|
||||
{
|
||||
string curr = "-", tot = "-";
|
||||
if (_content is Models.TextDiff textDiff)
|
||||
{
|
||||
if (textDiff.CurrentChangeBlockIdx >= 0)
|
||||
curr = (textDiff.CurrentChangeBlockIdx + 1).ToString();
|
||||
tot = (textDiff.ChangeBlocks.Count).ToString();
|
||||
}
|
||||
ChangeBlockIndicator = curr + "/" + tot;
|
||||
}
|
||||
|
||||
public void ToggleFullTextDiff()
|
||||
{
|
||||
Preference.Instance.UseFullTextDiff = !Preference.Instance.UseFullTextDiff;
|
||||
LoadDiffContent();
|
||||
}
|
||||
|
||||
public void ToggleHighlightedDiffNavigation()
|
||||
{
|
||||
Preference.Instance.EnableChangeBlocks = !Preference.Instance.EnableChangeBlocks;
|
||||
if (_content is Models.TextDiff textDiff)
|
||||
textDiff.CurrentChangeBlockIdx = -1;
|
||||
RefreshChangeBlockIndicator();
|
||||
}
|
||||
|
||||
public void IncrUnified()
|
||||
{
|
||||
UnifiedLines = _unifiedLines + 1;
|
||||
|
@ -153,12 +91,6 @@ namespace SourceGit.ViewModels
|
|||
LoadDiffContent();
|
||||
}
|
||||
|
||||
public void ToggleTwoSideDiff()
|
||||
{
|
||||
Preference.Instance.UseSideBySideDiff = !Preference.Instance.UseSideBySideDiff;
|
||||
RefreshChangeBlockIndicator();
|
||||
}
|
||||
|
||||
public void OpenExternalMergeTool()
|
||||
{
|
||||
var toolType = Preference.Instance.ExternalMergeToolType;
|
||||
|
@ -285,9 +217,7 @@ namespace SourceGit.ViewModels
|
|||
FileModeChange = latest.FileModeChange;
|
||||
Content = rs;
|
||||
IsTextDiff = rs is Models.TextDiff;
|
||||
|
||||
RefreshChangeBlockIndicator();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -351,7 +281,6 @@ namespace SourceGit.ViewModels
|
|||
private string _title;
|
||||
private string _fileModeChange = string.Empty;
|
||||
private int _unifiedLines = 4;
|
||||
private string _changeBlockIndicator = "-/-";
|
||||
private bool _isTextDiff = false;
|
||||
private bool _ignoreWhitespace = false;
|
||||
private object _content = null;
|
||||
|
|
|
@ -206,10 +206,10 @@ namespace SourceGit.ViewModels
|
|||
set => SetProperty(ref _useFullTextDiff, value);
|
||||
}
|
||||
|
||||
public bool EnableChangeBlocks
|
||||
public bool UseBlockNavigationInDiffView
|
||||
{
|
||||
get => _enableChangeBlocks;
|
||||
set => SetProperty(ref _enableChangeBlocks, value);
|
||||
get => _useBlockNavigationInDiffView;
|
||||
set => SetProperty(ref _useBlockNavigationInDiffView, value);
|
||||
}
|
||||
|
||||
public Models.ChangeViewMode UnstagedChangeViewMode
|
||||
|
@ -620,7 +620,7 @@ namespace SourceGit.ViewModels
|
|||
private bool _enableDiffViewWordWrap = false;
|
||||
private bool _showHiddenSymbolsInDiffView = false;
|
||||
private bool _useFullTextDiff = false;
|
||||
private bool _enableChangeBlocks = false;
|
||||
private bool _useBlockNavigationInDiffView = false;
|
||||
|
||||
private Models.ChangeViewMode _unstagedChangeViewMode = Models.ChangeViewMode.List;
|
||||
private Models.ChangeViewMode _stagedChangeViewMode = Models.ChangeViewMode.List;
|
||||
|
|
|
@ -45,43 +45,10 @@ namespace SourceGit.ViewModels
|
|||
|
||||
FillEmptyLines();
|
||||
|
||||
ProcessChangeBlocks();
|
||||
|
||||
if (previous != null && previous.File == File)
|
||||
_syncScrollOffset = previous._syncScrollOffset;
|
||||
}
|
||||
|
||||
public List<Models.TextDiffChangeBlock> ChangeBlocks { get; set; } = [];
|
||||
|
||||
public void ProcessChangeBlocks()
|
||||
{
|
||||
ChangeBlocks.Clear();
|
||||
int lineIdx = 0, blockStartIdx = 0;
|
||||
bool isNewBlock = true;
|
||||
foreach (var line in Old) // NOTE: Same block size in both Old and New lines.
|
||||
{
|
||||
lineIdx++;
|
||||
if (line.Type == Models.TextDiffLineType.Added ||
|
||||
line.Type == Models.TextDiffLineType.Deleted ||
|
||||
line.Type == Models.TextDiffLineType.None) // Empty
|
||||
{
|
||||
if (isNewBlock)
|
||||
{
|
||||
isNewBlock = false;
|
||||
blockStartIdx = lineIdx;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!isNewBlock)
|
||||
{
|
||||
ChangeBlocks.Add(new Models.TextDiffChangeBlock(blockStartIdx, lineIdx - 1));
|
||||
isNewBlock = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ConvertsToCombinedRange(Models.TextDiff combined, ref int startLine, ref int endLine, bool isOldSide)
|
||||
{
|
||||
endLine = Math.Min(endLine, combined.Lines.Count - 1);
|
||||
|
|
|
@ -34,15 +34,6 @@
|
|||
|
||||
<!-- Toolbar Buttons -->
|
||||
<StackPanel Grid.Column="3" Margin="8,0,0,0" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<ToggleButton Classes="line_path"
|
||||
Width="28"
|
||||
Command="{Binding ToggleHighlightedDiffNavigation}"
|
||||
IsChecked="{Binding Source={x:Static vm:Preference.Instance}, Path=EnableChangeBlocks, Mode=OneWay}"
|
||||
IsVisible="{Binding IsTextDiff}"
|
||||
ToolTip.Tip="{DynamicResource Text.Diff.HighlightedDiffNavigation}">
|
||||
<Path Width="13" Height="13" Data="{StaticResource Icons.Highlight}" Margin="0,3,0,0"/>
|
||||
</ToggleButton>
|
||||
|
||||
<Button Classes="icon_button"
|
||||
Width="28"
|
||||
Click="OnGotoPrevChange"
|
||||
|
@ -50,18 +41,17 @@
|
|||
ToolTip.Tip="{DynamicResource Text.Diff.Prev}">
|
||||
<Path Width="12" Height="12" Stretch="Uniform" Margin="0,6,0,0" Data="{StaticResource Icons.Up}"/>
|
||||
</Button>
|
||||
|
||||
<TextBlock Classes="primary"
|
||||
Margin="0,0,0,0"
|
||||
Text="{Binding ChangeBlockIndicator}"
|
||||
FontSize="11">
|
||||
<TextBlock.IsVisible>
|
||||
|
||||
<Border>
|
||||
<Border.IsVisible>
|
||||
<MultiBinding Converter="{x:Static BoolConverters.And}">
|
||||
<Binding Path="IsTextDiff"/>
|
||||
<Binding Source="{x:Static vm:Preference.Instance}" Path="EnableChangeBlocks" Mode="OneWay"/>
|
||||
<Binding Source="{x:Static vm:Preference.Instance}" Path="UseBlockNavigationInDiffView" Mode="OneWay"/>
|
||||
</MultiBinding>
|
||||
</TextBlock.IsVisible>
|
||||
</TextBlock>
|
||||
</Border.IsVisible>
|
||||
|
||||
<TextBlock x:Name="BlockNavigationIndicator" Classes="primary" Margin="0,0,0,0" FontSize="11" Text="-/-"/>
|
||||
</Border>
|
||||
|
||||
<Button Classes="icon_button"
|
||||
Width="28"
|
||||
|
@ -71,6 +61,14 @@
|
|||
<Path Width="12" Height="12" Stretch="Uniform" Margin="0,6,0,0" Data="{StaticResource Icons.Down}"/>
|
||||
</Button>
|
||||
|
||||
<ToggleButton Classes="line_path"
|
||||
Width="28"
|
||||
IsChecked="{Binding Source={x:Static vm:Preference.Instance}, Path=UseBlockNavigationInDiffView, Mode=TwoWay}"
|
||||
IsVisible="{Binding IsTextDiff}"
|
||||
ToolTip.Tip="{DynamicResource Text.Diff.UseBlockNavigation}">
|
||||
<Path Width="13" Height="13" Data="{StaticResource Icons.CodeBlock}" Margin="0,3,0,0"/>
|
||||
</ToggleButton>
|
||||
|
||||
<Button Classes="icon_button"
|
||||
Width="28"
|
||||
Command="{Binding IncrUnified}"
|
||||
|
@ -145,8 +143,7 @@
|
|||
|
||||
<ToggleButton Classes="line_path"
|
||||
Width="28" Height="18"
|
||||
Command="{Binding ToggleTwoSideDiff}"
|
||||
IsChecked="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSideBySideDiff, Mode=OneWay}"
|
||||
IsChecked="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSideBySideDiff, Mode=TwoWay}"
|
||||
IsVisible="{Binding IsTextDiff}"
|
||||
ToolTip.Tip="{DynamicResource Text.Diff.SideBySide}">
|
||||
<Path Width="12" Height="12" Data="{StaticResource Icons.LayoutHorizontal}" Margin="0,2,0,0"/>
|
||||
|
@ -261,10 +258,10 @@
|
|||
|
||||
<!-- Text Diff -->
|
||||
<DataTemplate DataType="m:TextDiff">
|
||||
<v:TextDiffView
|
||||
UseSideBySideDiff="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSideBySideDiff, Mode=OneWay}"
|
||||
UseFullTextDiff="{Binding Source={x:Static vm:Preference.Instance}, Path=UseFullTextDiff, Mode=OneWay}"
|
||||
CurrentChangeBlockIdx="{Binding CurrentChangeBlockIdx, Mode=OneWay}"/>
|
||||
<v:TextDiffView
|
||||
UseSideBySideDiff="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSideBySideDiff, Mode=TwoWay}"
|
||||
UseBlockNavigation="{Binding Source={x:Static vm:Preference.Instance}, Path=UseBlockNavigationInDiffView, Mode=TwoWay}"
|
||||
BlockNavigationIndicator="{Binding #BlockNavigationIndicator.Text, Mode=OneWayToSource}"/>
|
||||
</DataTemplate>
|
||||
|
||||
<!-- Empty or only EOL changes -->
|
||||
|
|
|
@ -13,44 +13,16 @@ namespace SourceGit.Views
|
|||
|
||||
private void OnGotoPrevChange(object _, RoutedEventArgs e)
|
||||
{
|
||||
if (ViewModels.Preference.Instance.EnableChangeBlocks)
|
||||
{
|
||||
if (DataContext is ViewModels.DiffContext diffCtx)
|
||||
diffCtx.PrevChange();
|
||||
}
|
||||
else
|
||||
{
|
||||
var textDiff = this.FindDescendantOfType<ThemedTextDiffPresenter>();
|
||||
if (textDiff == null)
|
||||
return;
|
||||
|
||||
textDiff.GotoPrevChange();
|
||||
if (textDiff is SingleSideTextDiffPresenter presenter)
|
||||
presenter.ForceSyncScrollOffset();
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
var textDiff = this.FindDescendantOfType<TextDiffView>();
|
||||
textDiff?.GotoPrevChange();
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void OnGotoNextChange(object _, RoutedEventArgs e)
|
||||
{
|
||||
if (ViewModels.Preference.Instance.EnableChangeBlocks)
|
||||
{
|
||||
if (DataContext is ViewModels.DiffContext diffCtx)
|
||||
diffCtx.NextChange();
|
||||
}
|
||||
else
|
||||
{
|
||||
var textDiff = this.FindDescendantOfType<ThemedTextDiffPresenter>();
|
||||
if (textDiff == null)
|
||||
return;
|
||||
|
||||
textDiff.GotoNextChange();
|
||||
if (textDiff is SingleSideTextDiffPresenter presenter)
|
||||
presenter.ForceSyncScrollOffset();
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
var textDiff = this.FindDescendantOfType<TextDiffView>();
|
||||
textDiff?.GotoNextChange();
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,9 +30,9 @@
|
|||
UseSyntaxHighlighting="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSyntaxHighlighting}"
|
||||
WordWrap="{Binding Source={x:Static vm:Preference.Instance}, Path=EnableDiffViewWordWrap}"
|
||||
ShowHiddenSymbols="{Binding Source={x:Static vm:Preference.Instance}, Path=ShowHiddenSymbolsInDiffView}"
|
||||
CurrentChangeBlockIdx="{Binding #ThisControl.CurrentChangeBlockIdx}"
|
||||
EnableChunkSelection="{Binding #ThisControl.EnableChunkSelection}"
|
||||
SelectedChunk="{Binding #ThisControl.SelectedChunk, Mode=TwoWay}"/>
|
||||
SelectedChunk="{Binding #ThisControl.SelectedChunk, Mode=TwoWay}"
|
||||
BlockNavigation="{Binding #ThisControl.BlockNavigation, Mode=TwoWay}"/>
|
||||
|
||||
<Rectangle Grid.Column="1" Fill="{DynamicResource Brush.Border2}" Width="1" HorizontalAlignment="Center" VerticalAlignment="Stretch"/>
|
||||
|
||||
|
@ -62,9 +62,9 @@
|
|||
UseSyntaxHighlighting="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSyntaxHighlighting}"
|
||||
WordWrap="False"
|
||||
ShowHiddenSymbols="{Binding Source={x:Static vm:Preference.Instance}, Path=ShowHiddenSymbolsInDiffView}"
|
||||
CurrentChangeBlockIdx="{Binding #ThisControl.CurrentChangeBlockIdx}"
|
||||
EnableChunkSelection="{Binding #ThisControl.EnableChunkSelection}"
|
||||
SelectedChunk="{Binding #ThisControl.SelectedChunk, Mode=TwoWay}"/>
|
||||
SelectedChunk="{Binding #ThisControl.SelectedChunk, Mode=TwoWay}"
|
||||
BlockNavigation="{Binding #ThisControl.BlockNavigation, Mode=TwoWay}"/>
|
||||
|
||||
<Rectangle Grid.Column="1" Fill="{DynamicResource Brush.Border2}" Width="1" HorizontalAlignment="Center" VerticalAlignment="Stretch"/>
|
||||
|
||||
|
@ -84,9 +84,9 @@
|
|||
UseSyntaxHighlighting="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSyntaxHighlighting}"
|
||||
WordWrap="False"
|
||||
ShowHiddenSymbols="{Binding Source={x:Static vm:Preference.Instance}, Path=ShowHiddenSymbolsInDiffView}"
|
||||
CurrentChangeBlockIdx="{Binding #ThisControl.CurrentChangeBlockIdx}"
|
||||
EnableChunkSelection="{Binding #ThisControl.EnableChunkSelection}"
|
||||
SelectedChunk="{Binding #ThisControl.SelectedChunk, Mode=TwoWay}"/>
|
||||
SelectedChunk="{Binding #ThisControl.SelectedChunk, Mode=TwoWay}"
|
||||
BlockNavigation="{Binding #ThisControl.BlockNavigation, Mode=TwoWay}"/>
|
||||
|
||||
<Rectangle Grid.Column="3" Fill="{DynamicResource Brush.Border2}" Width="1" HorizontalAlignment="Center" VerticalAlignment="Stretch"/>
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Avalonia;
|
||||
|
@ -255,9 +255,9 @@ namespace SourceGit.Views
|
|||
if (_presenter.Document == null || !textView.VisualLinesValid)
|
||||
return;
|
||||
|
||||
var changeBlock = _presenter.GetCurrentChangeBlock();
|
||||
var changeBlock = _presenter.BlockNavigation?.GetCurrentBlock();
|
||||
Brush changeBlockBG = new SolidColorBrush(Colors.Gray, 0.25);
|
||||
Pen changeBlockFG = new Pen(Brushes.Gray, 1);
|
||||
Pen changeBlockFG = new Pen(Brushes.Gray);
|
||||
|
||||
var lines = _presenter.GetLines();
|
||||
var width = textView.Bounds.Width;
|
||||
|
@ -278,8 +278,7 @@ namespace SourceGit.Views
|
|||
var bg = GetBrushByLineType(info.Type);
|
||||
if (bg != null)
|
||||
{
|
||||
if (bg != null)
|
||||
drawingContext.DrawRectangle(bg, null, new Rect(0, startY, width, endY - startY));
|
||||
drawingContext.DrawRectangle(bg, null, new Rect(0, startY, width, endY - startY));
|
||||
|
||||
if (info.Highlights.Count > 0)
|
||||
{
|
||||
|
@ -323,9 +322,9 @@ namespace SourceGit.Views
|
|||
if (changeBlock != null && changeBlock.IsInRange(index))
|
||||
{
|
||||
drawingContext.DrawRectangle(changeBlockBG, null, new Rect(0, startY, width, endY - startY));
|
||||
if (index == changeBlock.StartLine)
|
||||
if (index == changeBlock.Start)
|
||||
drawingContext.DrawLine(changeBlockFG, new Point(0, startY), new Point(width, startY));
|
||||
if (index == changeBlock.EndLine)
|
||||
if (index == changeBlock.End)
|
||||
drawingContext.DrawLine(changeBlockFG, new Point(0, endY), new Point(width, endY));
|
||||
}
|
||||
}
|
||||
|
@ -503,13 +502,13 @@ namespace SourceGit.Views
|
|||
set => SetValue(DisplayRangeProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<int> CurrentChangeBlockIdxProperty =
|
||||
AvaloniaProperty.Register<ThemedTextDiffPresenter, int>(nameof(CurrentChangeBlockIdx));
|
||||
public static readonly StyledProperty<ViewModels.BlockNavigation> BlockNavigationProperty =
|
||||
AvaloniaProperty.Register<ThemedTextDiffPresenter, ViewModels.BlockNavigation>(nameof(BlockNavigation));
|
||||
|
||||
public int CurrentChangeBlockIdx
|
||||
public ViewModels.BlockNavigation BlockNavigation
|
||||
{
|
||||
get => GetValue(CurrentChangeBlockIdxProperty);
|
||||
set => SetValue(CurrentChangeBlockIdxProperty, value);
|
||||
get => GetValue(BlockNavigationProperty);
|
||||
set => SetValue(BlockNavigationProperty, value);
|
||||
}
|
||||
|
||||
protected override Type StyleKeyOverride => typeof(TextEditor);
|
||||
|
@ -546,6 +545,19 @@ namespace SourceGit.Views
|
|||
|
||||
public void GotoPrevChange()
|
||||
{
|
||||
var blockNavigation = BlockNavigation;
|
||||
if (blockNavigation != null)
|
||||
{
|
||||
var prev = blockNavigation.GotoPrev();
|
||||
if (prev != null)
|
||||
{
|
||||
TextArea.Caret.Line = prev.Start;
|
||||
ScrollToLine(prev.Start);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var firstLineIdx = DisplayRange.StartIdx;
|
||||
if (firstLineIdx <= 1)
|
||||
return;
|
||||
|
@ -588,7 +600,20 @@ namespace SourceGit.Views
|
|||
}
|
||||
|
||||
public void GotoNextChange()
|
||||
{
|
||||
{
|
||||
var blockNavigation = BlockNavigation;
|
||||
if (blockNavigation != null)
|
||||
{
|
||||
var next = blockNavigation.GotoNext();
|
||||
if (next != null)
|
||||
{
|
||||
TextArea.Caret.Line = next.Start;
|
||||
ScrollToLine(next.Start);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var lines = GetLines();
|
||||
var lastLineIdx = DisplayRange.EndIdx;
|
||||
if (lastLineIdx >= lines.Count - 1)
|
||||
|
@ -616,28 +641,6 @@ namespace SourceGit.Views
|
|||
}
|
||||
}
|
||||
|
||||
public Models.TextDiffChangeBlock GetCurrentChangeBlock()
|
||||
{
|
||||
return GetChangeBlock(CurrentChangeBlockIdx);
|
||||
}
|
||||
|
||||
public virtual Models.TextDiffChangeBlock GetChangeBlock(int changeBlockIdx)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public void JumpToChangeBlock(int changeBlockIdx)
|
||||
{
|
||||
var changeBlock = GetChangeBlock(changeBlockIdx);
|
||||
if (changeBlock != null)
|
||||
{
|
||||
TextArea.Caret.Line = changeBlock.StartLine;
|
||||
//TextArea.Caret.BringCaretToView(); // NOTE: Brings caret line (barely) into view.
|
||||
ScrollToLine(changeBlock.StartLine); // NOTE: Brings specified line into center of view.
|
||||
}
|
||||
TextArea.TextView.Redraw();
|
||||
}
|
||||
|
||||
public override void Render(DrawingContext context)
|
||||
{
|
||||
base.Render(context);
|
||||
|
@ -713,12 +716,24 @@ namespace SourceGit.Views
|
|||
{
|
||||
InvalidateVisual();
|
||||
}
|
||||
else if (change.Property == CurrentChangeBlockIdxProperty)
|
||||
else if (change.Property == BlockNavigationProperty)
|
||||
{
|
||||
var oldValue = change.OldValue as ViewModels.BlockNavigation;
|
||||
var newValue = change.NewValue as ViewModels.BlockNavigation;
|
||||
if (oldValue != null)
|
||||
oldValue.PropertyChanged -= OnBlockNavigationPropertyChanged;
|
||||
if (newValue != null)
|
||||
newValue.PropertyChanged += OnBlockNavigationPropertyChanged;
|
||||
|
||||
InvalidateVisual();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnBlockNavigationPropertyChanged(object _1, PropertyChangedEventArgs _2)
|
||||
{
|
||||
TextArea.TextView.Redraw();
|
||||
}
|
||||
|
||||
private void OnTextViewContextRequested(object sender, ContextRequestedEventArgs e)
|
||||
{
|
||||
var selection = TextArea.Selection;
|
||||
|
@ -1070,16 +1085,6 @@ namespace SourceGit.Views
|
|||
}
|
||||
}
|
||||
|
||||
public override Models.TextDiffChangeBlock GetChangeBlock(int changeBlockIdx)
|
||||
{
|
||||
if (DataContext is Models.TextDiff diff)
|
||||
{
|
||||
if (changeBlockIdx >= 0 && changeBlockIdx < diff.ChangeBlocks.Count)
|
||||
return diff.ChangeBlocks[changeBlockIdx];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected override void OnLoaded(RoutedEventArgs e)
|
||||
{
|
||||
base.OnLoaded(e);
|
||||
|
@ -1298,16 +1303,6 @@ namespace SourceGit.Views
|
|||
}
|
||||
}
|
||||
|
||||
public override Models.TextDiffChangeBlock GetChangeBlock(int changeBlockIdx)
|
||||
{
|
||||
if (DataContext is ViewModels.TwoSideTextDiff diff)
|
||||
{
|
||||
if (changeBlockIdx >= 0 && changeBlockIdx < diff.ChangeBlocks.Count)
|
||||
return diff.ChangeBlocks[changeBlockIdx];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected override void OnLoaded(RoutedEventArgs e)
|
||||
{
|
||||
base.OnLoaded(e);
|
||||
|
@ -1518,15 +1513,6 @@ namespace SourceGit.Views
|
|||
set => SetValue(UseSideBySideDiffProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<bool> UseFullTextDiffProperty =
|
||||
AvaloniaProperty.Register<TextDiffView, bool>(nameof(UseFullTextDiff));
|
||||
|
||||
public bool UseFullTextDiff
|
||||
{
|
||||
get => GetValue(UseFullTextDiffProperty);
|
||||
set => SetValue(UseFullTextDiffProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<TextDiffViewChunk> SelectedChunkProperty =
|
||||
AvaloniaProperty.Register<TextDiffView, TextDiffViewChunk>(nameof(SelectedChunk));
|
||||
|
||||
|
@ -1554,13 +1540,31 @@ namespace SourceGit.Views
|
|||
set => SetValue(EnableChunkSelectionProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<int> CurrentChangeBlockIdxProperty =
|
||||
AvaloniaProperty.Register<TextDiffView, int>(nameof(CurrentChangeBlockIdx));
|
||||
public static readonly StyledProperty<bool> UseBlockNavigationProperty =
|
||||
AvaloniaProperty.Register<TextDiffView, bool>(nameof(UseBlockNavigation));
|
||||
|
||||
public int CurrentChangeBlockIdx
|
||||
public bool UseBlockNavigation
|
||||
{
|
||||
get => GetValue(CurrentChangeBlockIdxProperty);
|
||||
set => SetValue(CurrentChangeBlockIdxProperty, value);
|
||||
get => GetValue(UseBlockNavigationProperty);
|
||||
set => SetValue(UseBlockNavigationProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<ViewModels.BlockNavigation> BlockNavigationProperty =
|
||||
AvaloniaProperty.Register<TextDiffView, ViewModels.BlockNavigation>(nameof(BlockNavigation));
|
||||
|
||||
public ViewModels.BlockNavigation BlockNavigation
|
||||
{
|
||||
get => GetValue(BlockNavigationProperty);
|
||||
set => SetValue(BlockNavigationProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<string> BlockNavigationIndicatorProperty =
|
||||
AvaloniaProperty.Register<TextDiffView, string>(nameof(BlockNavigationIndicator));
|
||||
|
||||
public string BlockNavigationIndicator
|
||||
{
|
||||
get => GetValue(BlockNavigationIndicatorProperty);
|
||||
set => SetValue(BlockNavigationIndicatorProperty, value);
|
||||
}
|
||||
|
||||
static TextDiffView()
|
||||
|
@ -1570,7 +1574,7 @@ namespace SourceGit.Views
|
|||
v.RefreshContent(v.DataContext as Models.TextDiff, false);
|
||||
});
|
||||
|
||||
UseFullTextDiffProperty.Changed.AddClassHandler<TextDiffView>((v, _) =>
|
||||
UseBlockNavigationProperty.Changed.AddClassHandler<TextDiffView>((v, _) =>
|
||||
{
|
||||
v.RefreshContent(v.DataContext as Models.TextDiff, false);
|
||||
});
|
||||
|
@ -1589,25 +1593,38 @@ namespace SourceGit.Views
|
|||
v.Popup.Margin = new Thickness(0, top, right, 0);
|
||||
v.Popup.IsVisible = true;
|
||||
});
|
||||
|
||||
CurrentChangeBlockIdxProperty.Changed.AddClassHandler<TextDiffView>((v, e) =>
|
||||
{
|
||||
if (v.Editor.Presenter != null)
|
||||
{
|
||||
foreach (var p in v.Editor.Presenter.GetVisualDescendants().OfType<ThemedTextDiffPresenter>())
|
||||
{
|
||||
p.JumpToChangeBlock((int)e.NewValue);
|
||||
if (p is SingleSideTextDiffPresenter ssp)
|
||||
ssp.ForceSyncScrollOffset();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public TextDiffView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void GotoPrevChange()
|
||||
{
|
||||
var presenter = this.FindDescendantOfType<ThemedTextDiffPresenter>();
|
||||
if (presenter == null)
|
||||
return;
|
||||
|
||||
presenter.GotoPrevChange();
|
||||
if (presenter is SingleSideTextDiffPresenter singleSide)
|
||||
singleSide.ForceSyncScrollOffset();
|
||||
|
||||
BlockNavigationIndicator = BlockNavigation?.Indicator ?? string.Empty;
|
||||
}
|
||||
|
||||
public void GotoNextChange()
|
||||
{
|
||||
var presenter = this.FindDescendantOfType<ThemedTextDiffPresenter>();
|
||||
if (presenter == null)
|
||||
return;
|
||||
|
||||
presenter.GotoNextChange();
|
||||
if (presenter is SingleSideTextDiffPresenter singleSide)
|
||||
singleSide.ForceSyncScrollOffset();
|
||||
|
||||
BlockNavigationIndicator = BlockNavigation?.Indicator ?? string.Empty;
|
||||
}
|
||||
|
||||
protected override void OnDataContextChanged(EventArgs e)
|
||||
{
|
||||
|
@ -1647,10 +1664,19 @@ namespace SourceGit.Views
|
|||
Editor.Content = diff;
|
||||
}
|
||||
|
||||
if (UseBlockNavigation)
|
||||
{
|
||||
BlockNavigation = new ViewModels.BlockNavigation(Editor.Content);
|
||||
BlockNavigationIndicator = BlockNavigation.Indicator;
|
||||
}
|
||||
else
|
||||
{
|
||||
BlockNavigation = null;
|
||||
BlockNavigationIndicator = "-/-";
|
||||
}
|
||||
|
||||
IsUnstagedChange = diff.Option.IsUnstaged;
|
||||
EnableChunkSelection = diff.Option.WorkingCopyChange != null;
|
||||
|
||||
diff.CurrentChangeBlockIdx = -1; // Unset current change block.
|
||||
}
|
||||
|
||||
private void OnStageChunk(object _1, RoutedEventArgs _2)
|
||||
|
|
Loading…
Reference in a new issue