From 48760735ee0cf8ed08eced2c6fa5335850f64656 Mon Sep 17 00:00:00 2001 From: Robbie Knuth Date: Sun, 18 Sep 2016 09:56:50 -0700 Subject: [PATCH] When a textbox gets focus via the tab key, select all text if the textbox is single line. --- src/Avalonia.Controls/TextBox.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/TextBox.cs b/src/Avalonia.Controls/TextBox.cs index ed73472c49..e9bf25bd48 100644 --- a/src/Avalonia.Controls/TextBox.cs +++ b/src/Avalonia.Controls/TextBox.cs @@ -239,7 +239,21 @@ namespace Avalonia.Controls protected override void OnGotFocus(GotFocusEventArgs e) { base.OnGotFocus(e); - _presenter.ShowCaret(); + + // when navigating to a textbox via the tab key, select all text if + // 1) this textbox is *not* a multiline textbox + // 2) this textbox has any text to select + if (e.NavigationMethod == NavigationMethod.Tab && + !AcceptsReturn && + Text?.Length > 0) + { + SelectionStart = 0; + SelectionEnd = Text.Length; + } + else + { + _presenter.ShowCaret(); + } } protected override void OnLostFocus(RoutedEventArgs e)