public void FocusLine(ScriptLineView lineView, bool focusFirstField = false) { ScriptLineView.SetFocused(lineView); if (focusFirstField) { EditorApplication.update += FocusFieldDelayed; } void FocusFieldDelayed() // Otherwise editor steals the focus. { lineView?.Q <TextField>()?.Q <VisualElement>(TextInputBaseField <string> .textInputUssName)?.Focus(); EditorApplication.update -= FocusFieldDelayed; } }
private void ShowSearcher(Vector2 position, int insertIndex, int insertViewIndex) { SearcherWindow.Show(EditorWindow.focusedWindow, searchItems, "Insert Line", item => { if (item is null) { return(true); // Prevent nullref when focus is lost before item is selected. } var lineText = string.Empty; var lineView = default(ScriptLineView); switch (item.Name) { case "Commands": return(false); // Do nothing. case "Comment": lineText = CommentScriptLine.IdentifierLiteral; break; case "Label": lineText = LabelScriptLine.IdentifierLiteral; break; case "Generic Text": var genericTextScriptLine = new GenericTextScriptLine(null, -1, string.Empty, null, true); lineView = new GenericTextLineView(genericTextScriptLine, linesContainer); break; case "Define": lineText = DefineScriptLine.IdentifierLiteral; break; default: lineText = CommandScriptLine.IdentifierLiteral + item.Name; break; } if (lineView is null) { lineView = CreateLineView(lineText, -1, true); } InsertLine(lineView, insertIndex, insertViewIndex); ScriptLineView.SetFocused(lineView); lineView.Q <TextField>().Q <VisualElement>(TextInputBaseField <string> .textInputUssName).Focus(); return(true); }, position); }