enhance: add Views.StealHotKey.Enter to use hotkey Enter to start popup directly without checking focused TextBox (#1606)

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo
2025-07-25 17:06:30 +08:00
parent 70be81f650
commit d7ce01072b
5 changed files with 22 additions and 5 deletions

View File

@@ -27,7 +27,8 @@
ScrollViewer.VerticalScrollBarVisibility="Disabled"
Text="{Binding #ThisControl.Subject, Mode=TwoWay}"
Watermark="{DynamicResource Text.CommitMessageTextBox.SubjectPlaceholder}"
PreviewKeyDown="OnSubjectTextBoxPreviewKeyDown"/>
PreviewKeyDown="OnSubjectTextBoxPreviewKeyDown"
Tag="{Binding Source={x:Static v:StealHotKey.Enter}}"/>
<Rectangle Grid.Row="1"
Height="1"
@@ -51,7 +52,8 @@
ScrollViewer.VerticalScrollBarVisibility="Auto"
Text="{Binding #ThisControl.Description, Mode=TwoWay}"
Watermark="{DynamicResource Text.CommitMessageTextBox.MessagePlaceholder}"
PreviewKeyDown="OnDescriptionTextBoxPreviewKeyDown"/>
PreviewKeyDown="OnDescriptionTextBoxPreviewKeyDown"
Tag="{Binding Source={x:Static v:StealHotKey.Enter}}"/>
<Rectangle Grid.Row="3"
Height="1"

View File

@@ -74,7 +74,8 @@
CornerRadius="2"
Watermark="{DynamicResource Text.CreateTag.Message.Placeholder}"
Text="{Binding Message, Mode=TwoWay}"
IsVisible="{Binding Annotated}"/>
IsVisible="{Binding Annotated}"
Tag="{Binding Source={x:Static v:StealHotKey.Enter}}"/>
<CheckBox Grid.Row="4" Grid.Column="1"
Height="32" Margin="0,4,0,0"

View File

@@ -20,7 +20,8 @@ namespace SourceGit.Views
var children = this.GetLogicalDescendants();
foreach (var child in children)
{
if (child is TextBox { IsFocused: true } textBox)
if (child is TextBox { IsFocused: true, Tag: StealHotKey steal } textBox &&
steal is { Key: Key.Enter, KeyModifiers: KeyModifiers.None })
{
var fake = new KeyEventArgs()
{

View File

@@ -47,7 +47,8 @@
AcceptsTab="True"
VerticalContentAlignment="Top"
Padding="4"
v:AutoFocusBehaviour.IsEnabled="True"/>
v:AutoFocusBehaviour.IsEnabled="True"
Tag="{Binding Source={x:Static v:StealHotKey.Enter}}"/>
<CheckBox Grid.Row="2" Grid.Column="1"
Height="32"

12
src/Views/StealHotKey.cs Normal file
View File

@@ -0,0 +1,12 @@
using Avalonia.Input;
namespace SourceGit.Views
{
public class StealHotKey(Key key, KeyModifiers keyModifiers = KeyModifiers.None)
{
public Key Key { get; } = key;
public KeyModifiers KeyModifiers { get; } = keyModifiers;
public static StealHotKey Enter { get; } = new StealHotKey(Key.Enter);
}
}