diff --git a/src/modules/AdvancedPaste/AdvancedPaste/AdvancedPasteXAML/MainWindow.xaml.cs b/src/modules/AdvancedPaste/AdvancedPaste/AdvancedPasteXAML/MainWindow.xaml.cs
index 7d90cf62dc..bc3325edc4 100644
--- a/src/modules/AdvancedPaste/AdvancedPaste/AdvancedPasteXAML/MainWindow.xaml.cs
+++ b/src/modules/AdvancedPaste/AdvancedPaste/AdvancedPasteXAML/MainWindow.xaml.cs
@@ -125,7 +125,17 @@ namespace AdvancedPaste
public void SetFocus()
{
- MainPage.CustomFormatTextBox.InputTxtBox.Focus(FocusState.Programmatic);
+ // Set initial focus based on AI enabled state:
+ // - If AI is enabled, focus the prompt textbox
+ // - If AI is disabled, focus the paste options list for keyboard navigation
+ if (_optionsViewModel.IsCustomAIServiceEnabled)
+ {
+ MainPage.CustomFormatTextBox.InputTxtBox.Focus(FocusState.Programmatic);
+ }
+ else
+ {
+ MainPage.SetInitialFocusToPasteOptions();
+ }
}
public void ClearInputText()
diff --git a/src/modules/AdvancedPaste/AdvancedPaste/AdvancedPasteXAML/Pages/MainPage.xaml b/src/modules/AdvancedPaste/AdvancedPaste/AdvancedPasteXAML/Pages/MainPage.xaml
index bddfab733d..294108aafa 100644
--- a/src/modules/AdvancedPaste/AdvancedPaste/AdvancedPasteXAML/Pages/MainPage.xaml
+++ b/src/modules/AdvancedPaste/AdvancedPaste/AdvancedPasteXAML/Pages/MainPage.xaml
@@ -163,11 +163,13 @@
@@ -181,15 +183,19 @@
Glyph="" />
@@ -317,10 +323,13 @@
ItemContainerTransitions="{x:Null}"
ItemTemplateSelector="{StaticResource PasteFormatTemplateSelector}"
ItemsSource="{x:Bind ViewModel.StandardPasteFormats, Mode=OneWay}"
+ KeyDown="PasteOptionsListView_KeyDown"
ScrollViewer.VerticalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollMode="Disabled"
- SelectionMode="None"
- TabIndex="1" />
+ SelectionMode="Single"
+ SingleSelectionFollowsFocus="True"
+ TabIndex="1"
+ XYFocusKeyboardNavigation="Enabled" />
+ SelectionMode="Single"
+ SingleSelectionFollowsFocus="True"
+ TabIndex="2"
+ XYFocusKeyboardNavigation="Enabled" />
diff --git a/src/modules/AdvancedPaste/AdvancedPaste/AdvancedPasteXAML/Pages/MainPage.xaml.cs b/src/modules/AdvancedPaste/AdvancedPaste/AdvancedPasteXAML/Pages/MainPage.xaml.cs
index 5bef6389f0..9583ab5bc2 100644
--- a/src/modules/AdvancedPaste/AdvancedPaste/AdvancedPasteXAML/Pages/MainPage.xaml.cs
+++ b/src/modules/AdvancedPaste/AdvancedPaste/AdvancedPasteXAML/Pages/MainPage.xaml.cs
@@ -15,6 +15,7 @@ using ManagedCommon;
using Microsoft.PowerToys.Telemetry;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
+using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Media.Imaging;
using Windows.ApplicationModel.DataTransfer;
using Windows.Storage.Streams;
@@ -208,5 +209,103 @@ namespace AdvancedPaste.Pages
Clipboard.SetHistoryItemAsContent(item.Item);
}
}
+
+ ///
+ /// Sets initial focus to the paste options list when AI is disabled.
+ ///
+ public void SetInitialFocusToPasteOptions()
+ {
+ try
+ {
+ if (PasteOptionsListView.Items.Count > 0)
+ {
+ PasteOptionsListView.SelectedIndex = 0;
+ PasteOptionsListView.Focus(FocusState.Programmatic);
+ Logger.LogTrace("Focus set to PasteOptionsListView");
+ }
+ }
+ catch (Exception ex)
+ {
+ Logger.LogError("Failed to set focus to paste options", ex);
+ }
+ }
+
+ ///
+ /// Gets the appropriate arrow key for "forward" direction based on RTL settings.
+ ///
+ private VirtualKey GetForwardKey()
+ {
+ return FlowDirection == FlowDirection.RightToLeft ? VirtualKey.Left : VirtualKey.Right;
+ }
+
+ ///
+ /// Gets the appropriate arrow key for "backward" direction based on RTL settings.
+ ///
+ private VirtualKey GetBackwardKey()
+ {
+ return FlowDirection == FlowDirection.RightToLeft ? VirtualKey.Right : VirtualKey.Left;
+ }
+
+ ///
+ /// Handles keyboard navigation on the paste options ListViews.
+ /// Enter key invokes the selected item.
+ ///
+ private async void PasteOptionsListView_KeyDown(object sender, Microsoft.UI.Xaml.Input.KeyRoutedEventArgs e)
+ {
+ if (sender is ListView listView && e.Key == VirtualKey.Enter)
+ {
+ if (listView.SelectedItem is PasteFormat format)
+ {
+ e.Handled = true;
+ await ViewModel.ExecutePasteFormatAsync(format, PasteActionSource.ContextMenu);
+ }
+ }
+ }
+
+ ///
+ /// Handles keyboard navigation on the clipboard history button.
+ /// Right arrow (or Left in RTL) opens the flyout.
+ ///
+ private void ClipboardHistoryButton_KeyDown(object sender, Microsoft.UI.Xaml.Input.KeyRoutedEventArgs e)
+ {
+ if (e.Key == GetForwardKey())
+ {
+ e.Handled = true;
+ if (ClipboardHistoryButton.Flyout is Flyout flyout)
+ {
+ flyout.ShowAt(ClipboardHistoryButton);
+ Logger.LogTrace("Clipboard history flyout opened via keyboard");
+ }
+ }
+ }
+
+ ///
+ /// Handles keyboard navigation within the clipboard history flyout.
+ /// Escape or Left arrow (Right in RTL) closes the flyout and returns focus to the button.
+ ///
+ private void ClipboardHistoryItemsView_KeyDown(object sender, Microsoft.UI.Xaml.Input.KeyRoutedEventArgs e)
+ {
+ if (e.Key == VirtualKey.Escape || e.Key == GetBackwardKey())
+ {
+ e.Handled = true;
+ ClipboardHistoryFlyout.Hide();
+ }
+ }
+
+ ///
+ /// Handles the clipboard history flyout closing event.
+ /// Returns focus to the clipboard history button.
+ ///
+ private void ClipboardHistoryFlyout_Closed(object sender, object e)
+ {
+ try
+ {
+ ClipboardHistoryButton.Focus(FocusState.Programmatic);
+ }
+ catch (Exception ex)
+ {
+ Logger.LogError("Failed to return focus to clipboard history button", ex);
+ }
+ }
}
}