Skip to content

Commit 993c785

Browse files
committed
fix: hotkey to stage/unstage/discard selected hunk only works in the very FIRST text diff view instance (#2410)
Signed-off-by: leo <longshuang@msn.cn>
1 parent bba1f0c commit 993c785

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

src/Views/TextDiffView.axaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
</ContentControl>
101101

102102
<StackPanel x:Name="Popup" IsVisible="False" Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Right" Effect="drop-shadow(0 0 8 #80000000)">
103-
<Button Classes="flat" BorderBrush="{DynamicResource Brush.FlatButton.FloatingBorder}" Click="OnStageChunk" HotKey="{OnPlatform Ctrl+S, macOS=⌘+S}" IsVisible="{Binding Option.IsUnstaged}">
103+
<Button Classes="flat" x:Name="BtnStageChunk" BorderBrush="{DynamicResource Brush.FlatButton.FloatingBorder}" Click="OnStageChunk" IsVisible="{Binding Option.IsUnstaged}">
104104
<TextBlock>
105105
<Run Text="{DynamicResource Text.Hunk.Stage}"/>
106106
<Run Text=" "/>
@@ -111,7 +111,7 @@
111111
</TextBlock>
112112
</Button>
113113

114-
<Button Classes="flat" BorderBrush="{DynamicResource Brush.FlatButton.FloatingBorder}" Click="OnUnstageChunk" HotKey="{OnPlatform Ctrl+U, macOS=⌘+U}" IsVisible="{Binding Option.IsUnstaged, Converter={x:Static BoolConverters.Not}}">
114+
<Button Classes="flat" x:Name="BtnUnstageChunk" BorderBrush="{DynamicResource Brush.FlatButton.FloatingBorder}" Click="OnUnstageChunk" IsVisible="{Binding Option.IsUnstaged, Converter={x:Static BoolConverters.Not}}">
115115
<TextBlock>
116116
<Run Text="{DynamicResource Text.Hunk.Unstage}"/>
117117
<Run Text=" "/>
@@ -122,7 +122,7 @@
122122
</TextBlock>
123123
</Button>
124124

125-
<Button Classes="flat" BorderBrush="{DynamicResource Brush.FlatButton.FloatingBorder}" Margin="8,0,0,0" HotKey="{OnPlatform Ctrl+D, macOS=⌘+D}" Click="OnDiscardChunk" IsVisible="{Binding Option.IsUnstaged}">
125+
<Button Classes="flat" x:Name="BtnDiscardChunk" BorderBrush="{DynamicResource Brush.FlatButton.FloatingBorder}" Margin="8,0,0,0" Click="OnDiscardChunk" IsVisible="{Binding Option.IsUnstaged}">
126126
<TextBlock>
127127
<Run Text="{DynamicResource Text.Hunk.Discard}"/>
128128
<Run Text=" "/>

src/Views/TextDiffView.axaml.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,14 +1467,21 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
14671467
{
14681468
if (SelectedChunk is { } chunk)
14691469
{
1470+
var syscmd = OperatingSystem.IsMacOS() ? "Cmd" : "Ctrl";
14701471
var top = chunk.Y + 4;
14711472
var right = (chunk.Combined || !chunk.IsOldSide) ? 26 : (Bounds.Width * 0.5f) + 26;
14721473
Popup.Margin = new Thickness(0, top, right, 0);
14731474
Popup.IsVisible = true;
1475+
BtnStageChunk.HotKey = KeyGesture.Parse($"{syscmd}+S");
1476+
BtnUnstageChunk.HotKey = KeyGesture.Parse($"{syscmd}+U");
1477+
BtnDiscardChunk.HotKey = KeyGesture.Parse($"{syscmd}+D");
14741478
}
14751479
else
14761480
{
14771481
Popup.IsVisible = false;
1482+
BtnStageChunk.HotKey = null;
1483+
BtnUnstageChunk.HotKey = null;
1484+
BtnDiscardChunk.HotKey = null;
14781485
}
14791486
}
14801487
}

0 commit comments

Comments
 (0)