feature: add option to turn off auto-updating current block while scrolling in diff view with Block-Navigation enabled

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo
2025-08-19 19:44:40 +08:00
parent d3610d57c8
commit 065ec2a909
7 changed files with 29 additions and 6 deletions

View File

@@ -559,6 +559,7 @@
<x:String x:Key="Text.Preferences.General.ShowChildren" xml:space="preserve">Show children in the commit details</x:String>
<x:String x:Key="Text.Preferences.General.ShowTagsInGraph" xml:space="preserve">Show tags in commit graph</x:String>
<x:String x:Key="Text.Preferences.General.SubjectGuideLength" xml:space="preserve">Subject Guide Length</x:String>
<x:String x:Key="Text.Preferences.General.UpdateBlockNavigationOnScroll" xml:space="preserve">Update current block while scrolling in diff view (Block-Navigation)</x:String>
<x:String x:Key="Text.Preferences.Git" xml:space="preserve">GIT</x:String>
<x:String x:Key="Text.Preferences.Git.CRLF" xml:space="preserve">Enable Auto CRLF</x:String>
<x:String x:Key="Text.Preferences.Git.DefaultCloneDir" xml:space="preserve">Default Clone Dir</x:String>

View File

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

View File

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

View File

@@ -93,7 +93,7 @@ namespace SourceGit.ViewModels
if (_current >= 0 && _current < Blocks.Count)
return Blocks[_current];
return Blocks.Count > 0 ? Blocks[0] : null;
return null;
}
public Block GotoFirst()
@@ -142,7 +142,7 @@ namespace SourceGit.ViewModels
return Blocks[_current];
}
public void AutoUpdate(int start, int end)
public bool AutoUpdate(int start, int end)
{
if (_current >= 0 && _current < Blocks.Count)
{
@@ -150,7 +150,7 @@ namespace SourceGit.ViewModels
if ((block.Start >= start && block.Start <= end) ||
(block.End >= start && block.End <= end) ||
(block.Start <= start && block.End >= end))
return;
return false;
}
for (var i = 0; i < Blocks.Count; i++)
@@ -162,9 +162,11 @@ namespace SourceGit.ViewModels
{
Current = i;
OnPropertyChanged(nameof(Indicator));
return;
return true;
}
}
return false;
}
private int _current = -1;

View File

@@ -261,6 +261,12 @@ namespace SourceGit.ViewModels
set => SetProperty(ref _useBlockNavigationInDiffView, value);
}
public bool UpdateBlockNavigationOnScroll
{
get => _updateBlockNavigationOnScroll;
set => SetProperty(ref _updateBlockNavigationOnScroll, value);
}
public int LFSImageActiveIdx
{
get => _lfsImageActiveIdx;
@@ -723,6 +729,7 @@ namespace SourceGit.ViewModels
private bool _showHiddenSymbolsInDiffView = false;
private bool _useFullTextDiff = false;
private bool _useBlockNavigationInDiffView = false;
private bool _updateBlockNavigationOnScroll = true;
private int _lfsImageActiveIdx = 0;
private bool _enableCompactFoldersInChangesTree = false;

View File

@@ -46,7 +46,7 @@
<TabItem.Header>
<TextBlock Classes="tab_header" Text="{DynamicResource Text.Preferences.General}"/>
</TabItem.Header>
<Grid Margin="8" RowDefinitions="32,32,32,32,32,32,32,32,Auto" ColumnDefinitions="Auto,*">
<Grid Margin="8" RowDefinitions="32,32,32,32,32,32,32,32,Auto,Auto" ColumnDefinitions="Auto,*">
<TextBlock Grid.Row="0" Grid.Column="0"
Text="{DynamicResource Text.Preferences.General.Locale}"
HorizontalAlignment="Right"
@@ -148,6 +148,11 @@
IsChecked="{Binding ShowChildren, Mode=TwoWay}"/>
<CheckBox Grid.Row="8" Grid.Column="1"
Height="32"
Content="{DynamicResource Text.Preferences.General.UpdateBlockNavigationOnScroll}"
IsChecked="{Binding UpdateBlockNavigationOnScroll, Mode=TwoWay}"/>
<CheckBox Grid.Row="9" Grid.Column="1"
Height="32"
Content="{DynamicResource Text.Preferences.General.Check4UpdatesOnStartup}"
IsVisible="{x:Static s:App.IsCheckForUpdateCommandVisible}"

View File

@@ -825,7 +825,13 @@ namespace SourceGit.Views
}
ctx.DisplayRange = new ViewModels.TextDiffDisplayRange(start, start + count);
BlockNavigation?.AutoUpdate(start + 1, start + count);
if (ViewModels.Preferences.Instance.UpdateBlockNavigationOnScroll)
{
var changed = BlockNavigation?.AutoUpdate(start + 1, start + count) ?? false;
if (changed)
TextArea?.TextView?.Redraw();
}
}
protected void TrySetChunk(ViewModels.TextDiffSelectedChunk chunk)