From a7c89d7e690a8b6d116a839e14fc4180da50f6d3 Mon Sep 17 00:00:00 2001 From: ema Date: Fri, 27 Jun 2025 06:56:43 +0800 Subject: [PATCH] Add keyboard shortcuts for text direction #1612 Implemented Ctrl+LShift and Ctrl+RShift shortcuts to switch text flow direction between LTR and RTL in TextViewerPanel --- .../TextViewerPanel.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/QuickLook.Plugin/QuickLook.Plugin.TextViewer/TextViewerPanel.cs b/QuickLook.Plugin/QuickLook.Plugin.TextViewer/TextViewerPanel.cs index 5a449f9..0b65957 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.TextViewer/TextViewerPanel.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.TextViewer/TextViewerPanel.cs @@ -66,6 +66,7 @@ public partial class TextViewerPanel : TextEditor, IDisposable ManipulationInertiaStarting += Viewer_ManipulationInertiaStarting; ManipulationStarting += Viewer_ManipulationStarting; ManipulationDelta += Viewer_ManipulationDelta; + KeyDown += Viewer_KeyDown; PreviewMouseWheel += Viewer_MouseWheel; @@ -111,6 +112,20 @@ public partial class TextViewerPanel : TextEditor, IDisposable e.Mode = ManipulationModes.Translate; } + private void Viewer_KeyDown(object sender, KeyEventArgs e) + { + // Support keyboard shortcuts for RTL and LTR text direction + if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)) + { + // RTL: Ctrl + RShift + // LTR: Ctrl + LShift + if (Keyboard.IsKeyDown(Key.RightShift)) + FlowDirection = System.Windows.FlowDirection.RightToLeft; + else if (Keyboard.IsKeyDown(Key.LeftShift)) + FlowDirection = System.Windows.FlowDirection.LeftToRight; + } + } + private class TruncateLongLines : VisualLineElementGenerator { private const int MAX_LENGTH = 10000; @@ -206,6 +221,7 @@ public partial class TextViewerPanel : TextEditor, IDisposable : Brushes.Transparent; } + // Support automatic RTL for text files if (extension.Equals(".txt", StringComparison.OrdinalIgnoreCase)) { if (CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft)