[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:
Arjun Balgovind 2020-07-24 13:34:49 -07:00 committed by GitHub
parent ab0047a9b7
commit c4ddb7d351
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 2 deletions

View File

@ -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}"

View File

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

View File

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