From 5fe3dc6d13ff116bf6ab96d56c2b7d49f868424d Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Fri, 24 Sep 2021 13:14:07 +0200 Subject: [PATCH] Add value auto-select when focusing or clicking on input field in Editor --- Source/Editor/GUI/Input/ValueBox.cs | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/Source/Editor/GUI/Input/ValueBox.cs b/Source/Editor/GUI/Input/ValueBox.cs index b1b0408bd..4b7b0bc00 100644 --- a/Source/Editor/GUI/Input/ValueBox.cs +++ b/Source/Editor/GUI/Input/ValueBox.cs @@ -55,6 +55,7 @@ namespace FlaxEditor.GUI.Input protected string _startEditText; private Vector2 _startSlideLocation; + private double _clickStartTime = -1; /// /// Occurs when value gets changed. @@ -196,6 +197,14 @@ namespace FlaxEditor.GUI.Input } } + /// + public override void OnGotFocus() + { + base.OnGotFocus(); + + SelectAll(); + } + /// public override void OnLostFocus() { @@ -231,6 +240,9 @@ namespace FlaxEditor.GUI.Input return true; } + if (button == MouseButton.Left && !IsFocused) + _clickStartTime = Platform.TimeSeconds; + return base.OnMouseDown(location, button); } @@ -242,11 +254,10 @@ namespace FlaxEditor.GUI.Input // Update sliding Vector2 slideLocation = location + Root.TrackingMouseOffset; ApplySliding(Mathf.RoundToInt(slideLocation.X - _startSlideLocation.X) * _slideSpeed); + return; } - else - { - base.OnMouseMove(location); - } + + base.OnMouseMove(location); } /// @@ -259,6 +270,14 @@ namespace FlaxEditor.GUI.Input return true; } + if (button == MouseButton.Left && _clickStartTime > 0 && (Platform.TimeSeconds - _clickStartTime) < 0.2f) + { + _clickStartTime = -1; + OnSelectingEnd(); + SelectAll(); + return true; + } + return base.OnMouseUp(location, button); }