mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-01-18 06:29:44 +08: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:
parent
ab0047a9b7
commit
c4ddb7d351
@ -80,7 +80,7 @@
|
||||
x:FieldModifier="public"
|
||||
Opacity="0.6"
|
||||
Canvas.ZIndex="0"
|
||||
Margin="24, 0, 0, 0"
|
||||
Margin="24, 0, 14, 0"
|
||||
VerticalAlignment="Center"
|
||||
FontSize="24"
|
||||
Foreground="{DynamicResource TextControlPlaceholderForeground}"
|
||||
|
@ -83,6 +83,13 @@ namespace PowerLauncher
|
||||
SearchBox.QueryTextBox.DataContext = _viewModel;
|
||||
SearchBox.QueryTextBox.PreviewKeyDown += _launcher_KeyDown;
|
||||
SearchBox.QueryTextBox.TextChanged += QueryTextBox_TextChanged;
|
||||
|
||||
// Set initial language flow direction
|
||||
SearchBox_UpdateFlowDirection();
|
||||
|
||||
// Register language changed event
|
||||
InputLanguageManager.Current.InputLanguageChanged += SearchBox_InputLanguageChanged;
|
||||
|
||||
SearchBox.QueryTextBox.Focus();
|
||||
|
||||
ListBox.DataContext = _viewModel;
|
||||
@ -395,6 +402,17 @@ namespace PowerLauncher
|
||||
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)
|
||||
{
|
||||
if (!disposedValue)
|
||||
|
@ -273,7 +273,6 @@ namespace PowerLauncher.ViewModel
|
||||
|
||||
public string QueryText { get; set; } = String.Empty;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
@ -794,6 +793,20 @@ namespace PowerLauncher.ViewModel
|
||||
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)
|
||||
{
|
||||
if (!_disposed)
|
||||
|
Loading…
Reference in New Issue
Block a user