Skip to content

Commit 7088115

Browse files
committed
fix: Fix an issue where the url title field can't input Chinese characters
1 parent 19d738f commit 7088115

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

Editor/Scripts/IMGUITextField.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ public string value
4545
public Label HintElement { get; }
4646
public IMGUIContainer InputFieldElement { get; }
4747

48+
private const string TextFieldControlName = "IMGUITextField.TextField";
4849
private string _value;
50+
private bool _focusTextFieldOnce;
4951

5052

5153
public IMGUITextField(string labelText = null, string hintText = null)
@@ -120,10 +122,16 @@ public void RefreshLabelElementStyle()
120122
}
121123
}
122124

125+
public void FocusTextField()
126+
{
127+
_focusTextFieldOnce = true;
128+
}
129+
123130
private void DrawTextField()
124131
{
125132
string previousValue = _value;
126133
EditorGUI.BeginChangeCheck();
134+
GUI.SetNextControlName(TextFieldControlName);
127135
_value = EditorGUILayout.TextField(_value);
128136
if (EditorGUI.EndChangeCheck())
129137
{
@@ -134,6 +142,13 @@ private void DrawTextField()
134142
SendEvent(evt);
135143
}
136144
}
145+
146+
if (_focusTextFieldOnce)
147+
{
148+
EditorGUI.FocusTextInControl(TextFieldControlName);
149+
}
150+
151+
_focusTextFieldOnce = false;
137152
}
138153
}
139154
}

Editor/Scripts/UrlEditWindow.cs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public static UrlEditWindow Open(Vector2 centerPosition, SubmitTitleHandler onSu
2828

2929

3030
private SubmitTitleHandler _onSubmit;
31-
private TextField _urlField;
32-
private TextField _titleField;
31+
private IMGUITextField _urlField;
32+
private IMGUITextField _titleField;
3333
private Button _getTitleButton;
3434
private Label _getTitleStatusLabel;
3535

@@ -50,10 +50,10 @@ private void OnEnable()
5050
rootVisualElement.RegisterCallback<KeyUpEvent>(HandleKeyUp);
5151

5252
// Url field
53-
_urlField = new TextField
53+
_urlField = new IMGUITextField
5454
{
5555
name = "UrlField",
56-
label = "Url",
56+
LabelText = "Url",
5757
};
5858
_urlField.Q<Label>().style.minWidth = 40;
5959
_urlField.Q<Label>().style.maxWidth = 40;
@@ -68,10 +68,10 @@ private void OnEnable()
6868
}
6969
};
7070
rootVisualElement.Add(horizontal1);
71-
_titleField = new TextField
71+
_titleField = new IMGUITextField
7272
{
7373
name = "TitleField",
74-
label = "Title",
74+
LabelText = "Title",
7575
style =
7676
{
7777
flexGrow = 1,
@@ -148,16 +148,12 @@ private void Update()
148148

149149
private void FocusUrlField()
150150
{
151-
// _urlField.Focus();
152-
VisualElement textInput = _urlField.Q(className: TextField.inputUssClassName);
153-
_urlField.schedule.Execute(textInput.Focus);
151+
_urlField.FocusTextField();
154152
}
155153

156154
private void FocusTitleField()
157155
{
158-
// _titleField.Focus();
159-
VisualElement textInput = _titleField.Q(className: TextField.inputUssClassName);
160-
_titleField.schedule.Execute(textInput.Focus);
156+
_titleField.FocusTextField();
161157
}
162158

163159

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "com.greenbamboogames.assetquickaccess",
3-
"version": "1.4.1",
3+
"version": "1.4.2",
44
"displayName": "Asset Quick Access!",
55
"description": "Pin frequently used objects to a separate editor window. An enhanced version of Unity's Favorites feature.",
66
"unity": "2019.4",

0 commit comments

Comments
 (0)