feature: add hotkey Alt/⌥+Up to goto child of selected commit (#2104)

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo
2026-02-24 16:51:03 +08:00
parent 32fce4f698
commit 4c772cafa8
11 changed files with 70 additions and 18 deletions

View File

@@ -471,7 +471,6 @@ $1, $2, … Werte der Eingabe-Steuerelemente</x:String>
<x:String x:Key="Text.GitLFS.Remote" xml:space="preserve">Remote:</x:String>
<x:String x:Key="Text.GitLFS.Track" xml:space="preserve">Verfolge alle {0} Dateien</x:String>
<x:String x:Key="Text.GitLFS.TrackByExtension" xml:space="preserve">Verfolge alle *{0} Dateien</x:String>
<x:String x:Key="Text.GotoParentSelector" xml:space="preserve">Vorgänger auswählen</x:String>
<x:String x:Key="Text.Histories" xml:space="preserve">VERLAUF</x:String>
<x:String x:Key="Text.Histories.Header.Author" xml:space="preserve">AUTOR</x:String>
<x:String x:Key="Text.Histories.Header.AuthorTime" xml:space="preserve">AUTOR-ZEITPUNKT</x:String>

View File

@@ -468,7 +468,7 @@
<x:String x:Key="Text.GitLFS.Remote" xml:space="preserve">Remote:</x:String>
<x:String x:Key="Text.GitLFS.Track" xml:space="preserve">Track files named '{0}'</x:String>
<x:String x:Key="Text.GitLFS.TrackByExtension" xml:space="preserve">Track all *{0} files</x:String>
<x:String x:Key="Text.GotoParentSelector" xml:space="preserve">Select Parent</x:String>
<x:String x:Key="Text.GotoRevisionSelector" xml:space="preserve">Select Commit</x:String>
<x:String x:Key="Text.Histories" xml:space="preserve">HISTORY</x:String>
<x:String x:Key="Text.Histories.Header.Author" xml:space="preserve">AUTHOR</x:String>
<x:String x:Key="Text.Histories.Header.AuthorTime" xml:space="preserve">AUTHOR TIME</x:String>
@@ -498,6 +498,7 @@
<x:String x:Key="Text.Hotkeys.Repo.CommitWithAutoStage" xml:space="preserve">Stage all changes and commit</x:String>
<x:String x:Key="Text.Hotkeys.Repo.Fetch" xml:space="preserve">Fetch, starts directly</x:String>
<x:String x:Key="Text.Hotkeys.Repo.GoHome" xml:space="preserve">Dashboard mode (Default)</x:String>
<x:String x:Key="Text.Hotkeys.Repo.GoToChild" xml:space="preserve">Goto child of selected commit</x:String>
<x:String x:Key="Text.Hotkeys.Repo.GoToParent" xml:space="preserve">Goto parent of selected commit</x:String>
<x:String x:Key="Text.Hotkeys.Repo.OpenCommandPalette" xml:space="preserve">Open command palette</x:String>
<x:String x:Key="Text.Hotkeys.Repo.OpenSearchCommits" xml:space="preserve">Commit search mode</x:String>

View File

@@ -472,7 +472,6 @@
<x:String x:Key="Text.GitLFS.Remote" xml:space="preserve">Remoto:</x:String>
<x:String x:Key="Text.GitLFS.Track" xml:space="preserve">Seguir archivos llamados '{0}'</x:String>
<x:String x:Key="Text.GitLFS.TrackByExtension" xml:space="preserve">Seguir todos los archivos *{0}</x:String>
<x:String x:Key="Text.GotoParentSelector" xml:space="preserve">Seleccionar Padre</x:String>
<x:String x:Key="Text.Histories" xml:space="preserve">Historias</x:String>
<x:String x:Key="Text.Histories.Header.Author" xml:space="preserve">AUTOR</x:String>
<x:String x:Key="Text.Histories.Header.AuthorTime" xml:space="preserve">HORA DEL AUTOR</x:String>

View File

@@ -472,7 +472,6 @@
<x:String x:Key="Text.GitLFS.Remote" xml:space="preserve">Внешнее хранилище:</x:String>
<x:String x:Key="Text.GitLFS.Track" xml:space="preserve">Отслеживать файлы с именем «{0}»</x:String>
<x:String x:Key="Text.GitLFS.TrackByExtension" xml:space="preserve">Отслеживать все файлы (*{0})</x:String>
<x:String x:Key="Text.GotoParentSelector" xml:space="preserve">Выбрать родительский</x:String>
<x:String x:Key="Text.Histories" xml:space="preserve">Истории</x:String>
<x:String x:Key="Text.Histories.Header.Author" xml:space="preserve">АВТОР</x:String>
<x:String x:Key="Text.Histories.Header.AuthorTime" xml:space="preserve">ВРЕМЯ АВТОРА</x:String>

View File

@@ -472,7 +472,7 @@
<x:String x:Key="Text.GitLFS.Remote" xml:space="preserve">远程 </x:String>
<x:String x:Key="Text.GitLFS.Track" xml:space="preserve">跟踪名为'{0}'的文件</x:String>
<x:String x:Key="Text.GitLFS.TrackByExtension" xml:space="preserve">跟踪所有 *{0} 文件</x:String>
<x:String x:Key="Text.GotoParentSelector" xml:space="preserve">选择前往的提交</x:String>
<x:String x:Key="Text.GotoRevisionSelector" xml:space="preserve">选择前往的提交</x:String>
<x:String x:Key="Text.Histories" xml:space="preserve">历史记录</x:String>
<x:String x:Key="Text.Histories.Header.Author" xml:space="preserve">作者</x:String>
<x:String x:Key="Text.Histories.Header.AuthorTime" xml:space="preserve">修改时间</x:String>
@@ -502,6 +502,7 @@
<x:String x:Key="Text.Hotkeys.Repo.CommitWithAutoStage" xml:space="preserve">自动暂存全部变更并提交</x:String>
<x:String x:Key="Text.Hotkeys.Repo.Fetch" xml:space="preserve">拉取 (fetch) 远程变更</x:String>
<x:String x:Key="Text.Hotkeys.Repo.GoHome" xml:space="preserve">切换左边栏为分支/标签等显示模式(默认)</x:String>
<x:String x:Key="Text.Hotkeys.Repo.GoToChild" xml:space="preserve">前往选中提交的子提交</x:String>
<x:String x:Key="Text.Hotkeys.Repo.GoToParent" xml:space="preserve">前往选中提交的父提交</x:String>
<x:String x:Key="Text.Hotkeys.Repo.OpenCommandPalette" xml:space="preserve">打开快捷命令面板</x:String>
<x:String x:Key="Text.Hotkeys.Repo.OpenSearchCommits" xml:space="preserve">切换左边栏为提交搜索模式</x:String>

View File

@@ -472,7 +472,7 @@
<x:String x:Key="Text.GitLFS.Remote" xml:space="preserve">遠端存放庫:</x:String>
<x:String x:Key="Text.GitLFS.Track" xml:space="preserve">追蹤名稱為「{0}」的檔案</x:String>
<x:String x:Key="Text.GitLFS.TrackByExtension" xml:space="preserve">追蹤所有 *{0} 檔案</x:String>
<x:String x:Key="Text.GotoParentSelector" xml:space="preserve">選取要前往的提交</x:String>
<x:String x:Key="Text.GotoRevisionSelector" xml:space="preserve">選取要前往的提交</x:String>
<x:String x:Key="Text.Histories" xml:space="preserve">歷史記錄</x:String>
<x:String x:Key="Text.Histories.Header.Author" xml:space="preserve">作者</x:String>
<x:String x:Key="Text.Histories.Header.AuthorTime" xml:space="preserve">修改時間</x:String>
@@ -502,6 +502,7 @@
<x:String x:Key="Text.Hotkeys.Repo.CommitWithAutoStage" xml:space="preserve">自動暫存全部變更並提交</x:String>
<x:String x:Key="Text.Hotkeys.Repo.Fetch" xml:space="preserve">提取 (fetch) 遠端的變更</x:String>
<x:String x:Key="Text.Hotkeys.Repo.GoHome" xml:space="preserve">切換左邊欄為分支/標籤等顯示模式 (預設)</x:String>
<x:String x:Key="Text.Hotkeys.Repo.GoToChild" xml:space="preserve">前往所選提交的子提交</x:String>
<x:String x:Key="Text.Hotkeys.Repo.GoToParent" xml:space="preserve">前往所選提交的父提交</x:String>
<x:String x:Key="Text.Hotkeys.Repo.OpenCommandPalette" xml:space="preserve">開啟命令面板</x:String>
<x:String x:Key="Text.Hotkeys.Repo.OpenSearchCommits" xml:space="preserve">切換左邊欄為歷史搜尋模式</x:String>

View File

@@ -6,10 +6,10 @@
xmlns:v="using:SourceGit.Views"
xmlns:c="using:SourceGit.Converters"
mc:Ignorable="d" d:DesignWidth="520" d:DesignHeight="230"
x:Class="SourceGit.Views.GotoParentSelector"
x:Class="SourceGit.Views.GotoRevisionSelector"
x:Name="ThisControl"
Icon="/App.ico"
Title="{DynamicResource Text.GotoParentSelector}"
Title="{DynamicResource Text.GotoRevisionSelector}"
Width="600" SizeToContent="Height"
CanResize="False"
WindowStartupLocation="CenterOwner">
@@ -27,7 +27,7 @@
IsVisible="{OnPlatform True, macOS=False}"/>
<TextBlock Classes="bold"
Text="{DynamicResource Text.GotoParentSelector}"
Text="{DynamicResource Text.GotoRevisionSelector}"
HorizontalAlignment="Center" VerticalAlignment="Center"
IsHitTestVisible="False"/>
@@ -37,7 +37,7 @@
</Grid>
<ListBox Grid.Row="1"
x:Name="ParentList"
x:Name="RevisionList"
Focusable="True"
Margin="8" Padding="4"
SelectionMode="AlwaysSelected"

View File

@@ -4,9 +4,9 @@ using Avalonia.Interactivity;
namespace SourceGit.Views
{
public partial class GotoParentSelector : ChromelessWindow
public partial class GotoRevisionSelector : ChromelessWindow
{
public GotoParentSelector()
public GotoRevisionSelector()
{
CloseOnESC = true;
InitializeComponent();
@@ -15,7 +15,7 @@ namespace SourceGit.Views
protected override void OnLoaded(RoutedEventArgs e)
{
base.OnLoaded(e);
ParentList.Focus();
RevisionList.Focus();
}
private void OnListKeyDown(object sender, KeyEventArgs e)

View File

@@ -29,6 +29,10 @@
Click="OnGotoParent"
HotKey="Alt+Down"
IsVisible="False"/>
<Button Width="0" Height="0"
Click="OnGotoChild"
HotKey="Alt+Up"
IsVisible="False"/>
<DataGrid x:Name="CommitListContainer"
Classes="static_scrollbar"

View File

@@ -194,8 +194,53 @@ namespace SourceGit.Views
}
else if (parents.Count > 1 && TopLevel.GetTopLevel(this) is Window owner)
{
var dialog = new GotoParentSelector();
dialog.ParentList.ItemsSource = parents;
var dialog = new GotoRevisionSelector();
dialog.RevisionList.ItemsSource = parents;
var c = await dialog.ShowDialog<Models.Commit>(owner);
if (c != null)
vm.NavigateTo(c.SHA);
}
e.Handled = true;
}
private async void OnGotoChild(object sender, RoutedEventArgs e)
{
if (DataContext is not ViewModels.Histories vm)
return;
if (!CommitListContainer.IsKeyboardFocusWithin)
return;
if (CommitListContainer.SelectedItems is not { Count: 1 } selected)
return;
if (selected[0] is not Models.Commit { Parents.Count: > 0 } commit)
return;
var children = new List<Models.Commit>();
var sha = commit.SHA;
foreach (var c in vm.Commits)
{
foreach (var p in c.Parents)
{
if (sha.StartsWith(p, StringComparison.Ordinal))
children.Add(c);
}
if (sha.Equals(c.SHA, StringComparison.Ordinal))
break;
}
if (children.Count == 1)
{
vm.NavigateTo(children[0].SHA);
}
else if (children.Count > 1 && TopLevel.GetTopLevel(this) is Window owner)
{
var dialog = new GotoRevisionSelector();
dialog.RevisionList.ItemsSource = children;
var c = await dialog.ShowDialog<Models.Commit>(owner);
if (c != null)

View File

@@ -83,7 +83,7 @@
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=DefaultFontSize, Converter={x:Static c:DoubleConverters.Increase}}"
Margin="0,8"/>
<Grid RowDefinitions="20,20,20,20,20,20,20,20,20,20,20,20,20,20" ColumnDefinitions="150,*">
<Grid RowDefinitions="20,20,20,20,20,20,20,20,20,20,20,20,20,20,20" ColumnDefinitions="150,*">
<TextBlock Grid.Row="0" Grid.Column="0" Classes="bold" Text="{OnPlatform Ctrl+Shift+H, macOS=⌘+⇧+H}"/>
<TextBlock Grid.Row="0" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Repo.GoHome}" />
@@ -123,8 +123,11 @@
<TextBlock Grid.Row="12" Grid.Column="0" Classes="bold" Text="{OnPlatform Alt+Down, macOS=⌥+Down}"/>
<TextBlock Grid.Row="12" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Repo.GoToParent}" />
<TextBlock Grid.Row="13" Grid.Column="0" Classes="bold" Text="F5"/>
<TextBlock Grid.Row="13" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Repo.Refresh}" />
<TextBlock Grid.Row="13" Grid.Column="0" Classes="bold" Text="{OnPlatform Alt+Up, macOS=⌥+Up}"/>
<TextBlock Grid.Row="13" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Repo.GoToChild}" />
<TextBlock Grid.Row="14" Grid.Column="0" Classes="bold" Text="F5"/>
<TextBlock Grid.Row="14" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Repo.Refresh}" />
</Grid>
<TextBlock Text="{DynamicResource Text.Hotkeys.TextEditor}"