From c70cc9d0cb82b73a5735cf4e221c60050a87d5f2 Mon Sep 17 00:00:00 2001 From: Muaz Date: Wed, 8 Jul 2026 16:31:05 +0300 Subject: [PATCH] Apply right to left mode after every layout build The window level right to left pass runs when the window opens, but the main layout is built later (posted to the dispatcher after the view attaches), so starting the app with right to left mode enabled walked a tree that did not contain the subtitle grid or the text boxes yet: the layout came up left to right and only looked correct in sessions where the mode was toggled by hand afterwards. Switching layouts had the same effect, since the rebuilt controls start left to right. The pass is now re-applied right after the deferred startup layout build, after a layout switch, and after the undocked video layout rebuild. All three call the same helper, and the pass is idempotent (the grid mirror tracks its state, directions are recomputed from content), so repeated application is safe. --- src/ui/Features/Main/MainView.cs | 10 ++++++++++ src/ui/Features/Main/MainViewModel.cs | 12 ++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/ui/Features/Main/MainView.cs b/src/ui/Features/Main/MainView.cs index c7c068dd60..28a3c9a84f 100644 --- a/src/ui/Features/Main/MainView.cs +++ b/src/ui/Features/Main/MainView.cs @@ -100,6 +100,16 @@ protected override object Build() Dispatcher.UIThread.Post(() => { InitLayout.MakeLayout(this, _vm, Se.Settings.General.LayoutNumber); + + // The window level right to left pass runs when the window opens, + // which is before this deferred layout build, so the freshly built + // grid and text boxes would stay left to right until the mode is + // toggled. Re-apply after building. + if (Se.Settings.Appearance.RightToLeft && TopLevel.GetTopLevel(this) is Window rtlWindow) + { + MainHelpers.RightToLeftHelper.SetRightToLeftForDataGridAndText(rtlWindow); + } + _vm.ContentGrid.InvalidateMeasure(); _vm.ContentGrid.InvalidateArrange(); Dispatcher.UIThread.Post(() => _vm.SubtitleGrid.Focus()); diff --git a/src/ui/Features/Main/MainViewModel.cs b/src/ui/Features/Main/MainViewModel.cs index 78d0836c14..f05e942c96 100644 --- a/src/ui/Features/Main/MainViewModel.cs +++ b/src/ui/Features/Main/MainViewModel.cs @@ -888,6 +888,12 @@ private void SetLayout(int layoutNumber) var idx = SubtitleGrid.SelectedIndex; var savedAudioTrack = _audioTrack; Se.Settings.General.LayoutNumber = InitLayout.MakeLayout(MainView!, this, layoutNumber); + if (Se.Settings.Appearance.RightToLeft && Window != null) + { + // The rebuilt layout starts left to right; re-apply the mode. + RightToLeftHelper.SetRightToLeftForDataGridAndText(Window); + } + SelectAndScrollToRow(Math.Max(0, idx)); Dispatcher.UIThread.Post(() => SubtitleGrid.Focus()); RefreshSubtitlePreview(); @@ -5765,6 +5771,12 @@ private void VideoUndockControls() }); InitLayout.MakeLayout12KeepVideo(MainView!, this); + if (Se.Settings.Appearance.RightToLeft && Window != null) + { + // The rebuilt layout starts left to right; re-apply the mode. + RightToLeftHelper.SetRightToLeftForDataGridAndText(Window); + } + RefreshSubtitlePreview(); }); }