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
This commit is contained in:
ema
2025-06-27 06:56:43 +08:00
parent 32e45da1d6
commit a7c89d7e69

View File

@@ -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)