diff --git a/doc/classes/LineEdit.xml b/doc/classes/LineEdit.xml
index d218f720a380..3f4cb2f1d49f 100644
--- a/doc/classes/LineEdit.xml
+++ b/doc/classes/LineEdit.xml
@@ -8,7 +8,7 @@
- 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.
+ - Check [method edit], [method unedit], [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):
@@ -75,6 +75,13 @@
Clears the current selection.
+
+
+
+ Allows entering edit mode whether the [LineEdit] is focused or not.
+ Use [method Callable.call_deferred] if you want to enter edit mode on [signal text_submitted].
+
+
@@ -211,6 +218,12 @@
Selects the whole [String].
+
+
+
+ Allows exiting edit mode and preserve focus.
+
+
diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp
index dd8aa523c46b..3ed347992b0e 100644
--- a/editor/code_editor.cpp
+++ b/editor/code_editor.cpp
@@ -629,6 +629,8 @@ void FindReplaceBar::_search_text_submitted(const String &p_text) {
} else {
search_next();
}
+
+ callable_mp(search_text, &LineEdit::edit).call_deferred();
}
void FindReplaceBar::_replace_text_submitted(const String &p_text) {
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index 1a066b07286c..13fb2baa65a3 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -45,7 +45,7 @@
#include "editor/editor_settings.h"
#endif
-void LineEdit::_edit() {
+void LineEdit::edit() {
if (!is_inside_tree()) {
return;
}
@@ -63,10 +63,9 @@ void LineEdit::_edit() {
show_virtual_keyboard();
queue_redraw();
- emit_signal(SNAME("editing_toggled"), true);
}
-void LineEdit::_unedit() {
+void LineEdit::unedit() {
if (!editing) {
return;
}
@@ -84,8 +83,6 @@ void LineEdit::_unedit() {
if (deselect_on_focus_loss_enabled && !selection.drag_attempt) {
deselect();
}
-
- emit_signal(SNAME("editing_toggled"), false);
}
bool LineEdit::is_editing() const {
@@ -390,7 +387,8 @@ void LineEdit::gui_input(const Ref &p_event) {
}
if (editable && !editing) {
- _edit();
+ edit();
+ emit_signal(SNAME("editing_toggled"), true);
}
accept_event();
@@ -406,7 +404,8 @@ void LineEdit::gui_input(const Ref &p_event) {
set_caret_at_pixel_pos(b->get_position().x);
if (!editing) {
- _edit();
+ edit();
+ emit_signal(SNAME("editing_toggled"), true);
}
if (!paste_buffer.is_empty()) {
@@ -506,7 +505,8 @@ void LineEdit::gui_input(const Ref &p_event) {
}
if (editable && !editing) {
- _edit();
+ edit();
+ emit_signal(SNAME("editing_toggled"), true);
return;
}
queue_redraw();
@@ -599,7 +599,8 @@ void LineEdit::gui_input(const Ref &p_event) {
}
if (editable && !editing && k->is_action_pressed("ui_text_submit", false)) {
- _edit();
+ edit();
+ emit_signal(SNAME("editing_toggled"), true);
return;
}
@@ -734,7 +735,8 @@ void LineEdit::gui_input(const Ref &p_event) {
}
if (editing) {
- _unedit();
+ unedit();
+ emit_signal(SNAME("editing_toggled"), false);
}
accept_event();
@@ -743,7 +745,8 @@ void LineEdit::gui_input(const Ref &p_event) {
if (k->is_action("ui_cancel")) {
if (editing) {
- _unedit();
+ unedit();
+ emit_signal(SNAME("editing_toggled"), false);
}
accept_event();
@@ -1342,13 +1345,15 @@ void LineEdit::_notification(int p_what) {
// Only allow editing if the LineEdit is not focused with arrow keys.
if (!(Input::get_singleton()->is_action_pressed("ui_up") || Input::get_singleton()->is_action_pressed("ui_down") || Input::get_singleton()->is_action_pressed("ui_left") || Input::get_singleton()->is_action_pressed("ui_right"))) {
- _edit();
+ edit();
+ emit_signal(SNAME("editing_toggled"), true);
}
} break;
case NOTIFICATION_FOCUS_EXIT: {
if (editing) {
- _unedit();
+ unedit();
+ emit_signal(SNAME("editing_toggled"), false);
}
} break;
@@ -2137,7 +2142,8 @@ void LineEdit::set_editable(bool p_editable) {
editable = p_editable;
if (!editable && editing) {
- _unedit();
+ unedit();
+ emit_signal(SNAME("editing_toggled"), false);
}
_validate_caret_can_draw();
@@ -2758,6 +2764,8 @@ void LineEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_horizontal_alignment", "alignment"), &LineEdit::set_horizontal_alignment);
ClassDB::bind_method(D_METHOD("get_horizontal_alignment"), &LineEdit::get_horizontal_alignment);
+ ClassDB::bind_method(D_METHOD("edit"), &LineEdit::edit);
+ ClassDB::bind_method(D_METHOD("unedit"), &LineEdit::unedit);
ClassDB::bind_method(D_METHOD("is_editing"), &LineEdit::is_editing);
ClassDB::bind_method(D_METHOD("clear"), &LineEdit::clear);
ClassDB::bind_method(D_METHOD("select", "from", "to"), &LineEdit::select, DEFVAL(0), DEFVAL(-1));
diff --git a/scene/gui/line_edit.h b/scene/gui/line_edit.h
index ac7436646b54..9253dd871197 100644
--- a/scene/gui/line_edit.h
+++ b/scene/gui/line_edit.h
@@ -207,9 +207,6 @@ class LineEdit : public Control {
float base_scale = 1.0;
} theme_cache;
- void _edit();
- void _unedit();
-
void _close_ime_window();
void _update_ime_window_position();
@@ -265,6 +262,8 @@ class LineEdit : public Control {
virtual void gui_input(const Ref &p_event) override;
public:
+ void edit();
+ void unedit();
bool is_editing() const;
bool has_ime_text() const;