Skip to content

Commit

Permalink
Merge pull request #87674 from WhalesState/line-edit
Browse files Browse the repository at this point in the history
Prevent `LineEdit` focus loss when text is submitted or rejected and allow selecting without editing with arrow keys.
  • Loading branch information
akien-mga committed Sep 11, 2024
2 parents e919470 + c36f466 commit b032899
Show file tree
Hide file tree
Showing 6 changed files with 361 additions and 260 deletions.
21 changes: 20 additions & 1 deletion doc/classes/LineEdit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
An input field for single-line text.
</brief_description>
<description>
[LineEdit] provides an input field for editing a single line of text. It features many built-in shortcuts that are always available ([kbd]Ctrl[/kbd] here maps to [kbd]Cmd[/kbd] on macOS):
[LineEdit] provides an input field for editing a single line of text.
- When the [LineEdit] control is focused using the keyboard arrow keys, it will only gain focus and not enter edit mode.
- To enter edit mode, click on the control with the mouse or press the "ui_text_submit" action (default: [kbd]Enter[/kbd] or [kbd]Kp Enter[/kbd]).
- To exit edit mode, press "ui_text_submit" or "ui_cancel" (default: [kbd]Escape[/kbd]) actions.
- Check [method is_editing] and [signal editing_toggled] for more information.
[b]Important:[/b]
- Focusing the [LineEdit] with "ui_focus_next" (default: [kbd]Tab[/kbd]) or "ui_focus_prev" (default: [kbd]Shift + Tab[/kbd]) or [method Control.grab_focus] still enters edit mode (for compatibility).
[LineEdit] features many built-in shortcuts that are always available ([kbd]Ctrl[/kbd] here maps to [kbd]Cmd[/kbd] on macOS):
- [kbd]Ctrl + C[/kbd]: Copy
- [kbd]Ctrl + X[/kbd]: Cut
- [kbd]Ctrl + V[/kbd] or [kbd]Ctrl + Y[/kbd]: Paste/"yank"
Expand Down Expand Up @@ -139,6 +146,12 @@
Inserts [param text] at the caret. If the resulting value is longer than [member max_length], nothing happens.
</description>
</method>
<method name="is_editing" qualifiers="const">
<return type="bool" />
<description>
Returns whether the [LineEdit] is being edited.
</description>
</method>
<method name="is_menu_visible" qualifiers="const">
<return type="bool" />
<description>
Expand Down Expand Up @@ -301,6 +314,12 @@
</member>
</members>
<signals>
<signal name="editing_toggled">
<param index="0" name="toggled_on" type="bool" />
<description>
Emitted when the [LineEdit] switches in or out of edit mode.
</description>
</signal>
<signal name="text_change_rejected">
<param index="0" name="rejected_substring" type="String" />
<description>
Expand Down
1 change: 0 additions & 1 deletion editor/editor_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ void EditorPropertyText::_text_submitted(const String &p_string) {
}

if (text->has_focus()) {
text->release_focus();
_text_changed(p_string);
}
}
Expand Down
Loading

0 comments on commit b032899

Please sign in to comment.