mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 19:57:07 +02:00
[PT Run] Resolve text alignment issues for RTL input languages (not for mixed strings) (#5170)
* Added logic to switch TextBox/TextBlock flow direction on language change * Move event handler to separate method * Moved code to function
This commit is contained in:
@@ -80,7 +80,7 @@
|
|||||||
x:FieldModifier="public"
|
x:FieldModifier="public"
|
||||||
Opacity="0.6"
|
Opacity="0.6"
|
||||||
Canvas.ZIndex="0"
|
Canvas.ZIndex="0"
|
||||||
Margin="24, 0, 0, 0"
|
Margin="24, 0, 14, 0"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
FontSize="24"
|
FontSize="24"
|
||||||
Foreground="{DynamicResource TextControlPlaceholderForeground}"
|
Foreground="{DynamicResource TextControlPlaceholderForeground}"
|
||||||
|
|||||||
@@ -83,6 +83,13 @@ namespace PowerLauncher
|
|||||||
SearchBox.QueryTextBox.DataContext = _viewModel;
|
SearchBox.QueryTextBox.DataContext = _viewModel;
|
||||||
SearchBox.QueryTextBox.PreviewKeyDown += _launcher_KeyDown;
|
SearchBox.QueryTextBox.PreviewKeyDown += _launcher_KeyDown;
|
||||||
SearchBox.QueryTextBox.TextChanged += QueryTextBox_TextChanged;
|
SearchBox.QueryTextBox.TextChanged += QueryTextBox_TextChanged;
|
||||||
|
|
||||||
|
// Set initial language flow direction
|
||||||
|
SearchBox_UpdateFlowDirection();
|
||||||
|
|
||||||
|
// Register language changed event
|
||||||
|
InputLanguageManager.Current.InputLanguageChanged += SearchBox_InputLanguageChanged;
|
||||||
|
|
||||||
SearchBox.QueryTextBox.Focus();
|
SearchBox.QueryTextBox.Focus();
|
||||||
|
|
||||||
ListBox.DataContext = _viewModel;
|
ListBox.DataContext = _viewModel;
|
||||||
@@ -395,6 +402,17 @@ namespace PowerLauncher
|
|||||||
Hide();
|
Hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SearchBox_UpdateFlowDirection()
|
||||||
|
{
|
||||||
|
SearchBox.QueryTextBox.FlowDirection = MainViewModel.GetLanguageFlowDirection();
|
||||||
|
SearchBox.AutoCompleteTextBlock.FlowDirection = MainViewModel.GetLanguageFlowDirection();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SearchBox_InputLanguageChanged(object sender, InputLanguageEventArgs e)
|
||||||
|
{
|
||||||
|
SearchBox_UpdateFlowDirection();
|
||||||
|
}
|
||||||
|
|
||||||
protected virtual void Dispose(bool disposing)
|
protected virtual void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (!disposedValue)
|
if (!disposedValue)
|
||||||
|
|||||||
@@ -273,7 +273,6 @@ namespace PowerLauncher.ViewModel
|
|||||||
|
|
||||||
public string QueryText { get; set; } = String.Empty;
|
public string QueryText { get; set; } = String.Empty;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// we need move cursor to end when we manually changed query
|
/// we need move cursor to end when we manually changed query
|
||||||
/// but we don't want to move cursor to end when query is updated from TextBox.
|
/// but we don't want to move cursor to end when query is updated from TextBox.
|
||||||
@@ -794,6 +793,20 @@ namespace PowerLauncher.ViewModel
|
|||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static FlowDirection GetLanguageFlowDirection()
|
||||||
|
{
|
||||||
|
bool isCurrentLanguageRightToLeft = System.Windows.Input.InputLanguageManager.Current.CurrentInputLanguage.TextInfo.IsRightToLeft;
|
||||||
|
|
||||||
|
if (isCurrentLanguageRightToLeft)
|
||||||
|
{
|
||||||
|
return FlowDirection.RightToLeft;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return FlowDirection.LeftToRight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected virtual void Dispose(bool disposing)
|
protected virtual void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (!_disposed)
|
if (!_disposed)
|
||||||
|
|||||||
Reference in New Issue
Block a user