From 8a2d2b4c6573c9f1454a767c8b5463267912912a Mon Sep 17 00:00:00 2001 From: desktop-maesty/steve Date: Fri, 14 Jul 2017 22:10:47 +1000 Subject: [PATCH] CommandByName text enter caches command for next frame to be added during the normal keyboard input section to avoid those events being eaten by other parts of the gui and us playing nice with what Unity GUILayout expects --- Assets/Fungus/Scripts/Editor/BlockEditor.cs | 32 ++++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/Assets/Fungus/Scripts/Editor/BlockEditor.cs b/Assets/Fungus/Scripts/Editor/BlockEditor.cs index 9aa852a6..63c74863 100644 --- a/Assets/Fungus/Scripts/Editor/BlockEditor.cs +++ b/Assets/Fungus/Scripts/Editor/BlockEditor.cs @@ -42,8 +42,10 @@ namespace Fungus.EditorUtils protected Texture2D addIcon; protected Texture2D duplicateIcon; protected Texture2D deleteIcon; + protected string commandTextFieldContents = string.Empty; protected int filteredCommandPreviewSelectedItem = 0; + protected Type commandSelectedByTextInput; static List commandTypes; static List eventHandlerTypes; @@ -300,6 +302,17 @@ namespace Fungus.EditorUtils { filteredCommandPreviewSelectedItem++; } + + if (commandSelectedByTextInput != null && + Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter) + { + AddCommandCallback(commandSelectedByTextInput); + commandSelectedByTextInput = null; + commandTextFieldContents = String.Empty; + //GUI.FocusControl("dummycontrol"); + Event.current.Use(); + filteredCommandPreviewSelectedItem = 0; + } } // Previous Command @@ -373,6 +386,10 @@ namespace Fungus.EditorUtils var filteredAttributes = GetFilteredSupportedCommands(flowchart); var upperCommandText = commandTextFieldContents.ToUpper().Trim(); + + if (upperCommandText.Length > 0) + return; + var tokens = upperCommandText.Split(SPLIT_INPUT_ON); //we want commands that have all the elements you have typed @@ -417,19 +434,12 @@ namespace Fungus.EditorUtils filteredCommandPreviewSelectedItem = GUILayout.SelectionGrid(filteredCommandPreviewSelectedItem, toShow, 1); + if (toShow[filteredCommandPreviewSelectedItem] != ELIPSIS) + commandSelectedByTextInput = filteredAttributes[filteredCommandPreviewSelectedItem].Key; + else + commandSelectedByTextInput = null; - // if enter is hit then create that command and reset the preview window - if ((Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter) && - filteredAttributes.Count > filteredCommandPreviewSelectedItem && toShow[filteredCommandPreviewSelectedItem] != ELIPSIS) - { - commandTextFieldContents = String.Empty; - //GUI.FocusControl("dummycontrol"); - //Event.current.Use(); - AddCommandCallback(filteredAttributes[filteredCommandPreviewSelectedItem].Key); - filteredCommandPreviewSelectedItem = 0; - } - GUILayout.EndHorizontal(); GUILayout.Space(5);