Skip to content

Commit 9de2853

Browse files
committed
enhance: unify selection mode and hunk mode
1 parent 42f8e41 commit 9de2853

File tree

7 files changed

+478
-756
lines changed

7 files changed

+478
-756
lines changed

src/Models/DiffResult.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public partial class TextDiff
6969
public string Repo { get; set; } = null;
7070
public DiffOption Option { get; set; } = null;
7171

72-
public TextDiffSelection MakeSelection(int startLine, int endLine, bool isSideBySide, bool isOldSide)
72+
public TextDiffSelection MakeSelection(int startLine, int endLine, bool isCombined, bool isOldSide)
7373
{
7474
var rs = new TextDiffSelection();
7575
rs.StartLine = startLine;
@@ -95,7 +95,7 @@ public TextDiffSelection MakeSelection(int startLine, int endLine, bool isSideBy
9595
var line = Lines[i];
9696
if (line.Type == TextDiffLineType.Added)
9797
{
98-
if (!isSideBySide)
98+
if (isCombined)
9999
{
100100
rs.HasChanges = true;
101101
break;
@@ -111,7 +111,7 @@ public TextDiffSelection MakeSelection(int startLine, int endLine, bool isSideBy
111111
}
112112
else if (line.Type == TextDiffLineType.Deleted)
113113
{
114-
if (!isSideBySide)
114+
if (isCombined)
115115
{
116116
rs.HasChanges = true;
117117
break;

src/Resources/Locales/en_US.axaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,9 @@
307307
<x:String x:Key="Text.Hotkeys.TextEditor.GotoNextMatch" xml:space="preserve">Find next match</x:String>
308308
<x:String x:Key="Text.Hotkeys.TextEditor.GotoPrevMatch" xml:space="preserve">Find previous match</x:String>
309309
<x:String x:Key="Text.Hotkeys.TextEditor.Search" xml:space="preserve">Open search panel</x:String>
310-
<x:String x:Key="Text.Hunk.Stage" xml:space="preserve">Stage Hunk</x:String>
311-
<x:String x:Key="Text.Hunk.Unstage" xml:space="preserve">Unstage Hunk</x:String>
312-
<x:String x:Key="Text.Hunk.Discard" xml:space="preserve">Discard Hunk</x:String>
310+
<x:String x:Key="Text.Hunk.Stage" xml:space="preserve">Stage</x:String>
311+
<x:String x:Key="Text.Hunk.Unstage" xml:space="preserve">Unstage</x:String>
312+
<x:String x:Key="Text.Hunk.Discard" xml:space="preserve">Discard</x:String>
313313
<x:String x:Key="Text.Init" xml:space="preserve">Initialize Repository</x:String>
314314
<x:String x:Key="Text.Init.Path" xml:space="preserve">Path:</x:String>
315315
<x:String x:Key="Text.Init.Tip" xml:space="preserve">Invalid repository detected. Run `git init` under this path?</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,9 @@
310310
<x:String x:Key="Text.Hotkeys.TextEditor.GotoNextMatch" xml:space="preserve">定位到下一个匹配搜索的位置</x:String>
311311
<x:String x:Key="Text.Hotkeys.TextEditor.GotoPrevMatch" xml:space="preserve">定位到上一个匹配搜索的位置</x:String>
312312
<x:String x:Key="Text.Hotkeys.TextEditor.Search" xml:space="preserve">打开搜索</x:String>
313-
<x:String x:Key="Text.Hunk.Stage" xml:space="preserve">暂存片断</x:String>
313+
<x:String x:Key="Text.Hunk.Stage" xml:space="preserve">暂存</x:String>
314314
<x:String x:Key="Text.Hunk.Unstage" xml:space="preserve">移出暂存区</x:String>
315-
<x:String x:Key="Text.Hunk.Discard" xml:space="preserve">丢弃片断</x:String>
315+
<x:String x:Key="Text.Hunk.Discard" xml:space="preserve">丢弃</x:String>
316316
<x:String x:Key="Text.Init" xml:space="preserve">初始化新仓库</x:String>
317317
<x:String x:Key="Text.Init.Path" xml:space="preserve">路径 :</x:String>
318318
<x:String x:Key="Text.Init.Tip" xml:space="preserve">选择目录不是有效的Git仓库。是否需要在此目录执行`git init`操作?</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,9 @@
310310
<x:String x:Key="Text.Hotkeys.TextEditor.GotoNextMatch" xml:space="preserve">定位到下一個匹配搜尋的位置</x:String>
311311
<x:String x:Key="Text.Hotkeys.TextEditor.GotoPrevMatch" xml:space="preserve">定位到上一個匹配搜尋的位置</x:String>
312312
<x:String x:Key="Text.Hotkeys.TextEditor.Search" xml:space="preserve">開啟搜尋</x:String>
313-
<x:String x:Key="Text.Hunk.Stage" xml:space="preserve">暫存片斷</x:String>
313+
<x:String x:Key="Text.Hunk.Stage" xml:space="preserve">暫存</x:String>
314314
<x:String x:Key="Text.Hunk.Unstage" xml:space="preserve">移出暫存區</x:String>
315-
<x:String x:Key="Text.Hunk.Discard" xml:space="preserve">丟棄片斷</x:String>
315+
<x:String x:Key="Text.Hunk.Discard" xml:space="preserve">丟棄</x:String>
316316
<x:String x:Key="Text.Init" xml:space="preserve">初始化新倉庫</x:String>
317317
<x:String x:Key="Text.Init.Path" xml:space="preserve">路徑 :</x:String>
318318
<x:String x:Key="Text.Init.Tip" xml:space="preserve">選擇目錄不是有效的Git倉庫。是否需要在此目錄執行`git init`操作?</x:String>

src/ViewModels/TwoSideTextDiff.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ public TwoSideTextDiff(Models.TextDiff diff, TwoSideTextDiff previous = null)
5858

5959
public void ConvertsToCombinedRange(Models.TextDiff combined, ref int startLine, ref int endLine, bool isOldSide)
6060
{
61-
endLine = Math.Min(endLine, combined.Lines.Count);
61+
endLine = Math.Min(endLine, combined.Lines.Count - 1);
6262

6363
var oneSide = isOldSide ? Old : New;
6464
var firstContentLine = -1;
65-
for (int i = startLine - 1; i < endLine; i++)
65+
for (int i = startLine; i <= endLine; i++)
6666
{
6767
var line = oneSide[i];
6868
if (line.Type != Models.TextDiffLineType.None)
@@ -76,7 +76,7 @@ public void ConvertsToCombinedRange(Models.TextDiff combined, ref int startLine,
7676
return;
7777

7878
var endContentLine = -1;
79-
for (int i = Math.Min(endLine - 1, oneSide.Count - 1); i >= startLine - 1; i--)
79+
for (int i = Math.Min(endLine, oneSide.Count - 1); i >= startLine; i--)
8080
{
8181
var line = oneSide[i];
8282
if (line.Type != Models.TextDiffLineType.None)
@@ -91,8 +91,8 @@ public void ConvertsToCombinedRange(Models.TextDiff combined, ref int startLine,
9191

9292
var firstContent = oneSide[firstContentLine];
9393
var endContent = oneSide[endContentLine];
94-
startLine = combined.Lines.IndexOf(firstContent) + 1;
95-
endLine = combined.Lines.IndexOf(endContent) + 1;
94+
startLine = combined.Lines.IndexOf(firstContent);
95+
endLine = combined.Lines.IndexOf(endContent);
9696
}
9797

9898
private void FillEmptyLines()

src/Views/TextDiffView.axaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
UseSyntaxHighlighting="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSyntaxHighlighting}"
2727
WordWrap="{Binding Source={x:Static vm:Preference.Instance}, Path=EnableDiffViewWordWrap}"
2828
ShowHiddenSymbols="{Binding Source={x:Static vm:Preference.Instance}, Path=ShowHiddenSymbolsInDiffView}"
29-
HighlightChunk="{Binding #ThisControl.HighlightChunk, Mode=TwoWay}"/>
29+
SelectedChunk="{Binding #ThisControl.SelectedChunk, Mode=TwoWay}"/>
3030
</DataTemplate>
3131

3232
<DataTemplate DataType="vm:TwoSideTextDiff">
@@ -46,7 +46,7 @@
4646
UseSyntaxHighlighting="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSyntaxHighlighting}"
4747
WordWrap="{Binding Source={x:Static vm:Preference.Instance}, Path=EnableDiffViewWordWrap}"
4848
ShowHiddenSymbols="{Binding Source={x:Static vm:Preference.Instance}, Path=ShowHiddenSymbolsInDiffView}"
49-
HighlightChunk="{Binding #ThisControl.HighlightChunk, Mode=TwoWay}"/>
49+
SelectedChunk="{Binding #ThisControl.SelectedChunk, Mode=TwoWay}"/>
5050

5151
<Rectangle Grid.Column="1" Fill="{DynamicResource Brush.Border2}" Width="1" HorizontalAlignment="Center" VerticalAlignment="Stretch"/>
5252

@@ -65,7 +65,7 @@
6565
UseSyntaxHighlighting="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSyntaxHighlighting}"
6666
WordWrap="{Binding Source={x:Static vm:Preference.Instance}, Path=EnableDiffViewWordWrap}"
6767
ShowHiddenSymbols="{Binding Source={x:Static vm:Preference.Instance}, Path=ShowHiddenSymbolsInDiffView}"
68-
HighlightChunk="{Binding #ThisControl.HighlightChunk, Mode=TwoWay}"/>
68+
SelectedChunk="{Binding #ThisControl.SelectedChunk, Mode=TwoWay}"/>
6969
</Grid>
7070
</DataTemplate>
7171
</ContentControl.DataTemplates>

0 commit comments

Comments
 (0)