Skip to content

Commit d7ce010

Browse files
committed
enhance: add Views.StealHotKey.Enter to use hotkey Enter to start popup directly without checking focused TextBox (#1606)
Signed-off-by: leo <[email protected]>
1 parent 70be81f commit d7ce010

File tree

5 files changed

+22
-5
lines changed

5 files changed

+22
-5
lines changed

src/Views/CommitMessageTextBox.axaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
ScrollViewer.VerticalScrollBarVisibility="Disabled"
2828
Text="{Binding #ThisControl.Subject, Mode=TwoWay}"
2929
Watermark="{DynamicResource Text.CommitMessageTextBox.SubjectPlaceholder}"
30-
PreviewKeyDown="OnSubjectTextBoxPreviewKeyDown"/>
30+
PreviewKeyDown="OnSubjectTextBoxPreviewKeyDown"
31+
Tag="{Binding Source={x:Static v:StealHotKey.Enter}}"/>
3132

3233
<Rectangle Grid.Row="1"
3334
Height="1"
@@ -51,7 +52,8 @@
5152
ScrollViewer.VerticalScrollBarVisibility="Auto"
5253
Text="{Binding #ThisControl.Description, Mode=TwoWay}"
5354
Watermark="{DynamicResource Text.CommitMessageTextBox.MessagePlaceholder}"
54-
PreviewKeyDown="OnDescriptionTextBoxPreviewKeyDown"/>
55+
PreviewKeyDown="OnDescriptionTextBoxPreviewKeyDown"
56+
Tag="{Binding Source={x:Static v:StealHotKey.Enter}}"/>
5557

5658
<Rectangle Grid.Row="3"
5759
Height="1"

src/Views/CreateTag.axaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@
7474
CornerRadius="2"
7575
Watermark="{DynamicResource Text.CreateTag.Message.Placeholder}"
7676
Text="{Binding Message, Mode=TwoWay}"
77-
IsVisible="{Binding Annotated}"/>
77+
IsVisible="{Binding Annotated}"
78+
Tag="{Binding Source={x:Static v:StealHotKey.Enter}}"/>
7879

7980
<CheckBox Grid.Row="4" Grid.Column="1"
8081
Height="32" Margin="0,4,0,0"

src/Views/LauncherPage.axaml.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ private void OnPopupSureByHotKey(object sender, RoutedEventArgs e)
2020
var children = this.GetLogicalDescendants();
2121
foreach (var child in children)
2222
{
23-
if (child is TextBox { IsFocused: true } textBox)
23+
if (child is TextBox { IsFocused: true, Tag: StealHotKey steal } textBox &&
24+
steal is { Key: Key.Enter, KeyModifiers: KeyModifiers.None })
2425
{
2526
var fake = new KeyEventArgs()
2627
{

src/Views/StashChanges.axaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
AcceptsTab="True"
4848
VerticalContentAlignment="Top"
4949
Padding="4"
50-
v:AutoFocusBehaviour.IsEnabled="True"/>
50+
v:AutoFocusBehaviour.IsEnabled="True"
51+
Tag="{Binding Source={x:Static v:StealHotKey.Enter}}"/>
5152

5253
<CheckBox Grid.Row="2" Grid.Column="1"
5354
Height="32"

src/Views/StealHotKey.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Avalonia.Input;
2+
3+
namespace SourceGit.Views
4+
{
5+
public class StealHotKey(Key key, KeyModifiers keyModifiers = KeyModifiers.None)
6+
{
7+
public Key Key { get; } = key;
8+
public KeyModifiers KeyModifiers { get; } = keyModifiers;
9+
10+
public static StealHotKey Enter { get; } = new StealHotKey(Key.Enter);
11+
}
12+
}

0 commit comments

Comments
 (0)