From bf8f838f018935cb0f6238514a1f3e80aa771386 Mon Sep 17 00:00:00 2001 From: Sinai Date: Sat, 15 May 2021 06:23:32 +1000 Subject: [PATCH] Remove Control Key requirement on autocomplete navigation --- .../Widgets/AutoComplete/AutoCompleteModal.cs | 64 +++++++++---------- 1 file changed, 29 insertions(+), 35 deletions(-) diff --git a/src/UI/Widgets/AutoComplete/AutoCompleteModal.cs b/src/UI/Widgets/AutoComplete/AutoCompleteModal.cs index 884e9c1..9a1eba9 100644 --- a/src/UI/Widgets/AutoComplete/AutoCompleteModal.cs +++ b/src/UI/Widgets/AutoComplete/AutoCompleteModal.cs @@ -93,44 +93,39 @@ namespace UnityExplorer.UI.Widgets.AutoComplete if (!Suggesting(handler)) return false; - if (InputManager.GetKey(KeyCode.LeftControl) || InputManager.GetKey(KeyCode.RightControl)) + bool up = InputManager.GetKey(KeyCode.UpArrow); + bool down = InputManager.GetKey(KeyCode.DownArrow); + + if (up || down) { - bool up = InputManager.GetKey(KeyCode.UpArrow); - bool down = InputManager.GetKey(KeyCode.DownArrow); - - if (up || down) + if (up) { - if (up) + if (InputManager.GetKeyDown(KeyCode.UpArrow)) { - if (InputManager.GetKeyDown(KeyCode.UpArrow)) - { - SetSelectedSuggestion(SelectedIndex - 1); - timeOfLastNavHold = Time.realtimeSinceStartup + 0.3f; - } - else if (timeOfLastNavHold.OccuredEarlierThan(0.05f)) - { - SetSelectedSuggestion(SelectedIndex - 1); - timeOfLastNavHold = Time.realtimeSinceStartup; - } + SetSelectedSuggestion(SelectedIndex - 1); + timeOfLastNavHold = Time.realtimeSinceStartup + 0.3f; } - else + else if (timeOfLastNavHold.OccuredEarlierThan(0.05f)) { - if (InputManager.GetKeyDown(KeyCode.DownArrow)) - { - SetSelectedSuggestion(SelectedIndex + 1); - timeOfLastNavHold = Time.realtimeSinceStartup + 0.3f; - } - else if (timeOfLastNavHold.OccuredEarlierThan(0.05f)) - { - SetSelectedSuggestion(SelectedIndex + 1); - timeOfLastNavHold = Time.realtimeSinceStartup; - } + SetSelectedSuggestion(SelectedIndex - 1); + timeOfLastNavHold = Time.realtimeSinceStartup; + } + } + else + { + if (InputManager.GetKeyDown(KeyCode.DownArrow)) + { + SetSelectedSuggestion(SelectedIndex + 1); + timeOfLastNavHold = Time.realtimeSinceStartup + 0.3f; + } + else if (timeOfLastNavHold.OccuredEarlierThan(0.05f)) + { + SetSelectedSuggestion(SelectedIndex + 1); + timeOfLastNavHold = Time.realtimeSinceStartup; } - - return true; } - return false; + return true; } return !timeOfLastNavHold.OccuredEarlierThan(0.2f); @@ -297,10 +292,9 @@ namespace UnityExplorer.UI.Widgets.AutoComplete protected internal override void DoSetDefaultPosAndAnchors() { - var mainRect = uiRoot.GetComponent(); - mainRect.pivot = new Vector2(0f, 1f); - mainRect.anchorMin = new Vector2(0.42f, 0.4f); - mainRect.anchorMax = new Vector2(0.68f, 0.6f); + mainPanelRect.pivot = new Vector2(0f, 1f); + mainPanelRect.anchorMin = new Vector2(0.42f, 0.4f); + mainPanelRect.anchorMax = new Vector2(0.68f, 0.6f); } public override void ConstructPanelContent() @@ -314,7 +308,7 @@ namespace UnityExplorer.UI.Widgets.AutoComplete navigationTipRow = UIFactory.CreateHorizontalGroup(this.content, "BottomRow", true, true, true, true, 0, new Vector4(2, 2, 2, 2)); UIFactory.SetLayoutElement(navigationTipRow, minHeight: 20, flexibleWidth: 9999); - UIFactory.CreateLabel(navigationTipRow, "HelpText", "Control+Up/Down to select, Enter to use", + UIFactory.CreateLabel(navigationTipRow, "HelpText", "Up/Down to select, Enter to use, Esc to close", TextAnchor.MiddleLeft, Color.grey, false, 13); UIRoot.SetActive(false);