Skip to content

Commit 48ebbc4

Browse files
committed
Merge pull request #111117 from YeldhamDev/focus_corner_cases_fix
Fix cases where `LineEdit` can still show focus with mouse events
2 parents f1f9f54 + 984b52a commit 48ebbc4

File tree

5 files changed

+68
-13
lines changed

5 files changed

+68
-13
lines changed

doc/classes/LineEdit.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@
8282
</method>
8383
<method name="edit">
8484
<return type="void" />
85+
<param index="0" name="hide_focus" type="bool" default="false" />
8586
<description>
86-
Allows entering edit mode whether the [LineEdit] is focused or not.
87+
Allows entering edit mode whether the [LineEdit] is focused or not. If [param hide_focus] is [code]true[/code], the focused state will not be shown (see [method Control.grab_focus]).
8788
See also [member keep_editing_on_text_submit].
8889
</description>
8990
</method>

misc/extension_api_validation/4.5-stable.expected

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,10 @@ GH-110867
3333
ERROR: Validate extension JSON: Missing field in current API 'classes/FileAccess/methods/get_as_text': arguments. This is a bug.
3434

3535
Optional argument removed. Compatibility method registered.
36+
37+
38+
GH-111117
39+
---------
40+
Validate extension JSON: JSON file: Field was added in a way that breaks compatibility 'classes/LineEdit/methods/edit': arguments
41+
42+
Optional argument added. Compatibility method registered.

scene/gui/line_edit.compat.inc

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**************************************************************************/
2+
/* line_edit.compat.inc */
3+
/**************************************************************************/
4+
/* This file is part of: */
5+
/* GODOT ENGINE */
6+
/* https://godotengine.org */
7+
/**************************************************************************/
8+
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9+
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10+
/* */
11+
/* Permission is hereby granted, free of charge, to any person obtaining */
12+
/* a copy of this software and associated documentation files (the */
13+
/* "Software"), to deal in the Software without restriction, including */
14+
/* without limitation the rights to use, copy, modify, merge, publish, */
15+
/* distribute, sublicense, and/or sell copies of the Software, and to */
16+
/* permit persons to whom the Software is furnished to do so, subject to */
17+
/* the following conditions: */
18+
/* */
19+
/* The above copyright notice and this permission notice shall be */
20+
/* included in all copies or substantial portions of the Software. */
21+
/* */
22+
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23+
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24+
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25+
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26+
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27+
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28+
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29+
/**************************************************************************/
30+
31+
#ifndef DISABLE_DEPRECATED
32+
33+
void LineEdit::_edit_bind_compat_111117() {
34+
edit(false);
35+
}
36+
37+
void LineEdit::_bind_compatibility_methods() {
38+
ClassDB::bind_compatibility_method(D_METHOD("edit"), &LineEdit::_edit_bind_compat_111117);
39+
}
40+
41+
#endif // DISABLE_DEPRECATED

scene/gui/line_edit.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
/**************************************************************************/
3030

3131
#include "line_edit.h"
32+
#include "line_edit.compat.inc"
3233

3334
#include "core/input/input_map.h"
3435
#include "core/os/keyboard.h"
@@ -45,17 +46,17 @@
4546
#include "editor/settings/editor_settings.h"
4647
#endif
4748

48-
void LineEdit::edit() {
49-
_edit(true);
49+
void LineEdit::edit(bool p_hide_focus) {
50+
_edit(true, p_hide_focus);
5051
}
5152

52-
void LineEdit::_edit(bool p_show_virtual_keyboard) {
53+
void LineEdit::_edit(bool p_show_virtual_keyboard, bool p_hide_focus) {
5354
if (!is_inside_tree()) {
5455
return;
5556
}
5657

5758
if (!has_focus()) {
58-
grab_focus();
59+
grab_focus(p_hide_focus);
5960
return;
6061
}
6162

@@ -415,7 +416,7 @@ void LineEdit::gui_input(const Ref<InputEvent> &p_event) {
415416
}
416417

417418
if (editable && !editing) {
418-
edit();
419+
edit(true);
419420
emit_signal(SNAME("editing_toggled"), true);
420421
}
421422

@@ -432,7 +433,7 @@ void LineEdit::gui_input(const Ref<InputEvent> &p_event) {
432433
set_caret_at_pixel_pos(b->get_position().x);
433434

434435
if (!editing) {
435-
edit();
436+
edit(true);
436437
emit_signal(SNAME("editing_toggled"), true);
437438
}
438439

@@ -535,7 +536,7 @@ void LineEdit::gui_input(const Ref<InputEvent> &p_event) {
535536
}
536537

537538
if (editable && !editing) {
538-
edit();
539+
edit(true);
539540
emit_signal(SNAME("editing_toggled"), true);
540541
return;
541542
}
@@ -1099,10 +1100,10 @@ void LineEdit::drop_data(const Point2 &p_point, const Variant &p_data) {
10991100
selection_delete();
11001101
set_caret_column(caret_column_tmp);
11011102
insert_text_at_caret(p_data);
1102-
grab_focus();
1103+
grab_focus(true);
11031104
} else {
11041105
insert_text_at_caret(p_data);
1105-
grab_focus();
1106+
grab_focus(true);
11061107
}
11071108
select(caret_column_tmp, caret_column);
11081109
if (!text_changed_dirty) {
@@ -3196,7 +3197,7 @@ void LineEdit::_bind_methods() {
31963197
ClassDB::bind_method(D_METHOD("set_horizontal_alignment", "alignment"), &LineEdit::set_horizontal_alignment);
31973198
ClassDB::bind_method(D_METHOD("get_horizontal_alignment"), &LineEdit::get_horizontal_alignment);
31983199

3199-
ClassDB::bind_method(D_METHOD("edit"), &LineEdit::edit);
3200+
ClassDB::bind_method(D_METHOD("edit", "hide_focus"), &LineEdit::edit, DEFVAL(false));
32003201
ClassDB::bind_method(D_METHOD("unedit"), &LineEdit::unedit);
32013202
ClassDB::bind_method(D_METHOD("is_editing"), &LineEdit::is_editing);
32023203
ClassDB::bind_method(D_METHOD("set_keep_editing_on_text_submit", "enable"), &LineEdit::set_keep_editing_on_text_submit);

scene/gui/line_edit.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ class LineEdit : public Control {
263263
void _delete(bool p_word = false, bool p_all_to_right = false);
264264
void _texture_changed();
265265

266-
void _edit(bool p_show_virtual_keyboard = true);
266+
void _edit(bool p_show_virtual_keyboard = true, bool p_hide_focus = false);
267267

268268
protected:
269269
bool _is_over_clear_button(const Point2 &p_pos) const;
@@ -274,6 +274,11 @@ class LineEdit : public Control {
274274
void _validate_property(PropertyInfo &p_property) const;
275275
static void _bind_methods();
276276

277+
#ifndef DISABLE_DEPRECATED
278+
void _edit_bind_compat_111117();
279+
static void _bind_compatibility_methods();
280+
#endif
281+
277282
virtual void unhandled_key_input(const Ref<InputEvent> &p_event) override;
278283
virtual void gui_input(const Ref<InputEvent> &p_event) override;
279284

@@ -283,7 +288,7 @@ class LineEdit : public Control {
283288
void _accessibility_action_menu(const Variant &p_data);
284289

285290
public:
286-
void edit();
291+
void edit(bool p_hide_focus = false);
287292
void unedit();
288293
bool is_editing() const;
289294
void set_keep_editing_on_text_submit(bool p_enabled);

0 commit comments

Comments
 (0)