Skip to content

Commit 065ec2a

Browse files
committed
feature: add option to turn off auto-updating current block while scrolling in diff view with Block-Navigation enabled
Signed-off-by: leo <[email protected]>
1 parent d3610d5 commit 065ec2a

File tree

7 files changed

+29
-6
lines changed

7 files changed

+29
-6
lines changed

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@
559559
<x:String x:Key="Text.Preferences.General.ShowChildren" xml:space="preserve">Show children in the commit details</x:String>
560560
<x:String x:Key="Text.Preferences.General.ShowTagsInGraph" xml:space="preserve">Show tags in commit graph</x:String>
561561
<x:String x:Key="Text.Preferences.General.SubjectGuideLength" xml:space="preserve">Subject Guide Length</x:String>
562+
<x:String x:Key="Text.Preferences.General.UpdateBlockNavigationOnScroll" xml:space="preserve">Update current block while scrolling in diff view (Block-Navigation)</x:String>
562563
<x:String x:Key="Text.Preferences.Git" xml:space="preserve">GIT</x:String>
563564
<x:String x:Key="Text.Preferences.Git.CRLF" xml:space="preserve">Enable Auto CRLF</x:String>
564565
<x:String x:Key="Text.Preferences.Git.DefaultCloneDir" xml:space="preserve">Default Clone Dir</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,7 @@
563563
<x:String x:Key="Text.Preferences.General.ShowChildren" xml:space="preserve">在提交详情页中显示子提交列表</x:String>
564564
<x:String x:Key="Text.Preferences.General.ShowTagsInGraph" xml:space="preserve">在提交路线图中显示标签</x:String>
565565
<x:String x:Key="Text.Preferences.General.SubjectGuideLength" xml:space="preserve">SUBJECT字数检测</x:String>
566+
<x:String x:Key="Text.Preferences.General.UpdateBlockNavigationOnScroll" xml:space="preserve">启用基于变更块的跳转后,在变更对比页面滚动时更新当前高亮块</x:String>
566567
<x:String x:Key="Text.Preferences.Git" xml:space="preserve">GIT配置</x:String>
567568
<x:String x:Key="Text.Preferences.Git.CRLF" xml:space="preserve">自动换行转换</x:String>
568569
<x:String x:Key="Text.Preferences.Git.DefaultCloneDir" xml:space="preserve">默认克隆路径</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,7 @@
563563
<x:String x:Key="Text.Preferences.General.ShowChildren" xml:space="preserve">在提交詳細資訊中顯示後續提交</x:String>
564564
<x:String x:Key="Text.Preferences.General.ShowTagsInGraph" xml:space="preserve">在路線圖中顯示標籤</x:String>
565565
<x:String x:Key="Text.Preferences.General.SubjectGuideLength" xml:space="preserve">提交標題字數偵測</x:String>
566+
<x:String x:Key="Text.Preferences.General.UpdateBlockNavigationOnScroll" xml:space="preserve">啟用「區塊切換變更」時,在變更對比檢視中捲動時更新目前反白的區塊</x:String>
566567
<x:String x:Key="Text.Preferences.Git" xml:space="preserve">Git 設定</x:String>
567568
<x:String x:Key="Text.Preferences.Git.CRLF" xml:space="preserve">自動換行轉換</x:String>
568569
<x:String x:Key="Text.Preferences.Git.DefaultCloneDir" xml:space="preserve">預設複製 (clone) 路徑</x:String>

src/ViewModels/BlockNavigation.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public Block GetCurrentBlock()
9393
if (_current >= 0 && _current < Blocks.Count)
9494
return Blocks[_current];
9595

96-
return Blocks.Count > 0 ? Blocks[0] : null;
96+
return null;
9797
}
9898

9999
public Block GotoFirst()
@@ -142,15 +142,15 @@ public Block GotoLast()
142142
return Blocks[_current];
143143
}
144144

145-
public void AutoUpdate(int start, int end)
145+
public bool AutoUpdate(int start, int end)
146146
{
147147
if (_current >= 0 && _current < Blocks.Count)
148148
{
149149
var block = Blocks[_current];
150150
if ((block.Start >= start && block.Start <= end) ||
151151
(block.End >= start && block.End <= end) ||
152152
(block.Start <= start && block.End >= end))
153-
return;
153+
return false;
154154
}
155155

156156
for (var i = 0; i < Blocks.Count; i++)
@@ -162,9 +162,11 @@ public void AutoUpdate(int start, int end)
162162
{
163163
Current = i;
164164
OnPropertyChanged(nameof(Indicator));
165-
return;
165+
return true;
166166
}
167167
}
168+
169+
return false;
168170
}
169171

170172
private int _current = -1;

src/ViewModels/Preferences.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,12 @@ public bool UseBlockNavigationInDiffView
261261
set => SetProperty(ref _useBlockNavigationInDiffView, value);
262262
}
263263

264+
public bool UpdateBlockNavigationOnScroll
265+
{
266+
get => _updateBlockNavigationOnScroll;
267+
set => SetProperty(ref _updateBlockNavigationOnScroll, value);
268+
}
269+
264270
public int LFSImageActiveIdx
265271
{
266272
get => _lfsImageActiveIdx;
@@ -723,6 +729,7 @@ private bool RemoveInvalidRepositoriesRecursive(List<RepositoryNode> collection)
723729
private bool _showHiddenSymbolsInDiffView = false;
724730
private bool _useFullTextDiff = false;
725731
private bool _useBlockNavigationInDiffView = false;
732+
private bool _updateBlockNavigationOnScroll = true;
726733
private int _lfsImageActiveIdx = 0;
727734
private bool _enableCompactFoldersInChangesTree = false;
728735

src/Views/Preferences.axaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
<TabItem.Header>
4747
<TextBlock Classes="tab_header" Text="{DynamicResource Text.Preferences.General}"/>
4848
</TabItem.Header>
49-
<Grid Margin="8" RowDefinitions="32,32,32,32,32,32,32,32,Auto" ColumnDefinitions="Auto,*">
49+
<Grid Margin="8" RowDefinitions="32,32,32,32,32,32,32,32,Auto,Auto" ColumnDefinitions="Auto,*">
5050
<TextBlock Grid.Row="0" Grid.Column="0"
5151
Text="{DynamicResource Text.Preferences.General.Locale}"
5252
HorizontalAlignment="Right"
@@ -148,6 +148,11 @@
148148
IsChecked="{Binding ShowChildren, Mode=TwoWay}"/>
149149

150150
<CheckBox Grid.Row="8" Grid.Column="1"
151+
Height="32"
152+
Content="{DynamicResource Text.Preferences.General.UpdateBlockNavigationOnScroll}"
153+
IsChecked="{Binding UpdateBlockNavigationOnScroll, Mode=TwoWay}"/>
154+
155+
<CheckBox Grid.Row="9" Grid.Column="1"
151156
Height="32"
152157
Content="{DynamicResource Text.Preferences.General.Check4UpdatesOnStartup}"
153158
IsVisible="{x:Static s:App.IsCheckForUpdateCommandVisible}"

src/Views/TextDiffView.axaml.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,13 @@ private void OnTextViewVisualLinesChanged(object sender, EventArgs e)
825825
}
826826

827827
ctx.DisplayRange = new ViewModels.TextDiffDisplayRange(start, start + count);
828-
BlockNavigation?.AutoUpdate(start + 1, start + count);
828+
829+
if (ViewModels.Preferences.Instance.UpdateBlockNavigationOnScroll)
830+
{
831+
var changed = BlockNavigation?.AutoUpdate(start + 1, start + count) ?? false;
832+
if (changed)
833+
TextArea?.TextView?.Redraw();
834+
}
829835
}
830836

831837
protected void TrySetChunk(ViewModels.TextDiffSelectedChunk chunk)

0 commit comments

Comments
 (0)