mirror of
https://github.com/godotengine/godot.git
synced 2024-11-22 12:12:28 +00:00
Merge pull request #54166 from ConteZero/unique_selection
This commit is contained in:
commit
21529c90f8
@ -184,6 +184,9 @@
|
||||
<member name="context_menu_enabled" type="bool" setter="set_context_menu_enabled" getter="is_context_menu_enabled" default="true">
|
||||
If [code]true[/code], the context menu will appear when right-clicked.
|
||||
</member>
|
||||
<member name="deselect_on_focus_loss_enabled" type="bool" setter="set_deselect_on_focus_loss_enabled" getter="is_deselect_on_focus_loss_enabled" default="true">
|
||||
If [code]true[/code], the selected text will be deselected when focus is lost.
|
||||
</member>
|
||||
<member name="draw_control_chars" type="bool" setter="set_draw_control_chars" getter="get_draw_control_chars" default="false">
|
||||
If [code]true[/code], control characters are displayed.
|
||||
</member>
|
||||
|
@ -379,6 +379,9 @@
|
||||
The currently installed custom effects. This is an array of [RichTextEffect]s.
|
||||
To add a custom effect, it's more convenient to use [method install_effect].
|
||||
</member>
|
||||
<member name="deselect_on_focus_loss_enabled" type="bool" setter="set_deselect_on_focus_loss_enabled" getter="is_deselect_on_focus_loss_enabled" default="true">
|
||||
If [code]true[/code], the selected text will be deselected when focus is lost.
|
||||
</member>
|
||||
<member name="fit_content_height" type="bool" setter="set_fit_content_height" getter="is_fit_content_height_enabled" default="false">
|
||||
If [code]true[/code], the label's height will be automatically updated to fit its content.
|
||||
[b]Note:[/b] This property is used as a workaround to fix issues with [RichTextLabel] in [Container]s, but it's unreliable in some cases and will be removed in future versions.
|
||||
|
@ -922,6 +922,9 @@
|
||||
<member name="context_menu_enabled" type="bool" setter="set_context_menu_enabled" getter="is_context_menu_enabled" default="true">
|
||||
If [code]true[/code], a right-click displays the context menu.
|
||||
</member>
|
||||
<member name="deselect_on_focus_loss_enabled" type="bool" setter="set_deselect_on_focus_loss_enabled" getter="is_deselect_on_focus_loss_enabled" default="true">
|
||||
If [code]true[/code], the selected text will be deselected when focus is lost.
|
||||
</member>
|
||||
<member name="draw_control_chars" type="bool" setter="set_draw_control_chars" getter="get_draw_control_chars" default="false">
|
||||
If [code]true[/code], control characters are displayed.
|
||||
</member>
|
||||
|
@ -1824,6 +1824,7 @@ CodeTextEditor::CodeTextEditor() {
|
||||
text_editor->set_draw_line_numbers(true);
|
||||
text_editor->set_highlight_matching_braces_enabled(true);
|
||||
text_editor->set_auto_indent_enabled(true);
|
||||
text_editor->set_deselect_on_focus_loss_enabled(false);
|
||||
|
||||
status_bar = memnew(HBoxContainer);
|
||||
add_child(status_bar);
|
||||
|
@ -920,6 +920,9 @@ void LineEdit::_notification(int p_what) {
|
||||
DisplayServer::get_singleton()->virtual_keyboard_hide();
|
||||
}
|
||||
|
||||
if (deselect_on_focus_loss_enabled) {
|
||||
deselect();
|
||||
}
|
||||
} break;
|
||||
case MainLoop::NOTIFICATION_OS_IME_UPDATE: {
|
||||
if (has_focus()) {
|
||||
@ -1938,6 +1941,17 @@ bool LineEdit::is_selecting_enabled() const {
|
||||
return selecting_enabled;
|
||||
}
|
||||
|
||||
void LineEdit::set_deselect_on_focus_loss_enabled(const bool p_enabled) {
|
||||
deselect_on_focus_loss_enabled = p_enabled;
|
||||
if (p_enabled && selection.enabled && !has_focus()) {
|
||||
deselect();
|
||||
}
|
||||
}
|
||||
|
||||
bool LineEdit::is_deselect_on_focus_loss_enabled() const {
|
||||
return deselect_on_focus_loss_enabled;
|
||||
}
|
||||
|
||||
void LineEdit::set_right_icon(const Ref<Texture2D> &p_icon) {
|
||||
if (right_icon == p_icon) {
|
||||
return;
|
||||
@ -2196,6 +2210,8 @@ void LineEdit::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("is_middle_mouse_paste_enabled"), &LineEdit::is_middle_mouse_paste_enabled);
|
||||
ClassDB::bind_method(D_METHOD("set_selecting_enabled", "enable"), &LineEdit::set_selecting_enabled);
|
||||
ClassDB::bind_method(D_METHOD("is_selecting_enabled"), &LineEdit::is_selecting_enabled);
|
||||
ClassDB::bind_method(D_METHOD("set_deselect_on_focus_loss_enabled", "enable"), &LineEdit::set_deselect_on_focus_loss_enabled);
|
||||
ClassDB::bind_method(D_METHOD("is_deselect_on_focus_loss_enabled"), &LineEdit::is_deselect_on_focus_loss_enabled);
|
||||
ClassDB::bind_method(D_METHOD("set_right_icon", "icon"), &LineEdit::set_right_icon);
|
||||
ClassDB::bind_method(D_METHOD("get_right_icon"), &LineEdit::get_right_icon);
|
||||
|
||||
@ -2251,6 +2267,7 @@ void LineEdit::_bind_methods() {
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shortcut_keys_enabled"), "set_shortcut_keys_enabled", "is_shortcut_keys_enabled");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "middle_mouse_paste_enabled"), "set_middle_mouse_paste_enabled", "is_middle_mouse_paste_enabled");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "selecting_enabled"), "set_selecting_enabled", "is_selecting_enabled");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "deselect_on_focus_loss_enabled"), "set_deselect_on_focus_loss_enabled", "is_deselect_on_focus_loss_enabled");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "right_icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_right_icon", "get_right_icon");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "text_direction", PROPERTY_HINT_ENUM, "Auto,Left-to-Right,Right-to-Left,Inherited"), "set_text_direction", "get_text_direction");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "language"), "set_language", "get_language");
|
||||
|
@ -97,6 +97,7 @@ private:
|
||||
float full_width = 0.0;
|
||||
|
||||
bool selecting_enabled = true;
|
||||
bool deselect_on_focus_loss_enabled = true;
|
||||
|
||||
bool context_menu_enabled = true;
|
||||
PopupMenu *menu = nullptr;
|
||||
@ -325,6 +326,9 @@ public:
|
||||
void set_selecting_enabled(bool p_enabled);
|
||||
bool is_selecting_enabled() const;
|
||||
|
||||
void set_deselect_on_focus_loss_enabled(const bool p_enabled);
|
||||
bool is_deselect_on_focus_loss_enabled() const;
|
||||
|
||||
void set_right_icon(const Ref<Texture2D> &p_icon);
|
||||
Ref<Texture2D> get_right_icon();
|
||||
|
||||
|
@ -1491,7 +1491,13 @@ void RichTextLabel::_notification(int p_what) {
|
||||
_update_fx(main, dt);
|
||||
update();
|
||||
}
|
||||
}
|
||||
} break;
|
||||
case NOTIFICATION_FOCUS_EXIT: {
|
||||
if (deselect_on_focus_loss_enabled) {
|
||||
selection.active = false;
|
||||
update();
|
||||
}
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -3609,6 +3615,14 @@ void RichTextLabel::set_selection_enabled(bool p_enabled) {
|
||||
}
|
||||
}
|
||||
|
||||
void RichTextLabel::set_deselect_on_focus_loss_enabled(const bool p_enabled) {
|
||||
deselect_on_focus_loss_enabled = p_enabled;
|
||||
if (p_enabled && selection.active && !has_focus()) {
|
||||
selection.active = false;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
bool RichTextLabel::_search_table(ItemTable *p_table, List<Item *>::Element *p_from, const String &p_string, bool p_reverse_search) {
|
||||
List<Item *>::Element *E = p_from;
|
||||
while (E != nullptr) {
|
||||
@ -3858,6 +3872,10 @@ bool RichTextLabel::is_selection_enabled() const {
|
||||
return selection.enabled;
|
||||
}
|
||||
|
||||
bool RichTextLabel::is_deselect_on_focus_loss_enabled() const {
|
||||
return deselect_on_focus_loss_enabled;
|
||||
}
|
||||
|
||||
int RichTextLabel::get_selection_from() const {
|
||||
if (!selection.active || !selection.enabled) {
|
||||
return -1;
|
||||
@ -4111,6 +4129,9 @@ void RichTextLabel::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_selection_enabled", "enabled"), &RichTextLabel::set_selection_enabled);
|
||||
ClassDB::bind_method(D_METHOD("is_selection_enabled"), &RichTextLabel::is_selection_enabled);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_deselect_on_focus_loss_enabled", "enable"), &RichTextLabel::set_deselect_on_focus_loss_enabled);
|
||||
ClassDB::bind_method(D_METHOD("is_deselect_on_focus_loss_enabled"), &RichTextLabel::is_deselect_on_focus_loss_enabled);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_selection_from"), &RichTextLabel::get_selection_from);
|
||||
ClassDB::bind_method(D_METHOD("get_selection_to"), &RichTextLabel::get_selection_to);
|
||||
|
||||
@ -4162,6 +4183,8 @@ void RichTextLabel::_bind_methods() {
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "selection_enabled"), "set_selection_enabled", "is_selection_enabled");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "override_selected_font_color"), "set_override_selected_font_color", "is_overriding_selected_font_color");
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "deselect_on_focus_loss_enabled"), "set_deselect_on_focus_loss_enabled", "is_deselect_on_focus_loss_enabled");
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "custom_effects", PROPERTY_HINT_ARRAY_TYPE, vformat("%s/%s:%s", Variant::OBJECT, PROPERTY_HINT_RESOURCE_TYPE, "RichTextEffect"), (PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE)), "set_effects", "get_effects");
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "text_direction", PROPERTY_HINT_ENUM, "Auto,Left-to-Right,Right-to-Left,Inherited"), "set_text_direction", "get_text_direction");
|
||||
|
@ -399,6 +399,7 @@ private:
|
||||
};
|
||||
|
||||
Selection selection;
|
||||
bool deselect_on_focus_loss_enabled = true;
|
||||
|
||||
int visible_characters = -1;
|
||||
float percent_visible = 1.0;
|
||||
@ -551,6 +552,8 @@ public:
|
||||
int get_selection_to() const;
|
||||
String get_selected_text() const;
|
||||
void selection_copy();
|
||||
void set_deselect_on_focus_loss_enabled(const bool p_enabled);
|
||||
bool is_deselect_on_focus_loss_enabled() const;
|
||||
|
||||
void parse_bbcode(const String &p_bbcode);
|
||||
void append_text(const String &p_bbcode);
|
||||
|
@ -1364,6 +1364,10 @@ void TextEdit::_notification(int p_what) {
|
||||
if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD) && virtual_keyboard_enabled) {
|
||||
DisplayServer::get_singleton()->virtual_keyboard_hide();
|
||||
}
|
||||
|
||||
if (deselect_on_focus_loss_enabled) {
|
||||
deselect();
|
||||
}
|
||||
} break;
|
||||
case MainLoop::NOTIFICATION_OS_IME_UPDATE: {
|
||||
if (has_focus()) {
|
||||
@ -3669,6 +3673,17 @@ bool TextEdit::is_selecting_enabled() const {
|
||||
return selecting_enabled;
|
||||
}
|
||||
|
||||
void TextEdit::set_deselect_on_focus_loss_enabled(const bool p_enabled) {
|
||||
deselect_on_focus_loss_enabled = p_enabled;
|
||||
if (p_enabled && selection.active && !has_focus()) {
|
||||
deselect();
|
||||
}
|
||||
}
|
||||
|
||||
bool TextEdit::is_deselect_on_focus_loss_enabled() const {
|
||||
return deselect_on_focus_loss_enabled;
|
||||
}
|
||||
|
||||
void TextEdit::set_override_selected_font_color(bool p_override_selected_font_color) {
|
||||
override_selected_font_color = p_override_selected_font_color;
|
||||
}
|
||||
@ -4716,6 +4731,9 @@ void TextEdit::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_selecting_enabled", "enable"), &TextEdit::set_selecting_enabled);
|
||||
ClassDB::bind_method(D_METHOD("is_selecting_enabled"), &TextEdit::is_selecting_enabled);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_deselect_on_focus_loss_enabled", "enable"), &TextEdit::set_deselect_on_focus_loss_enabled);
|
||||
ClassDB::bind_method(D_METHOD("is_deselect_on_focus_loss_enabled"), &TextEdit::is_deselect_on_focus_loss_enabled);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_override_selected_font_color", "override"), &TextEdit::set_override_selected_font_color);
|
||||
ClassDB::bind_method(D_METHOD("is_overriding_selected_font_color"), &TextEdit::is_overriding_selected_font_color);
|
||||
|
||||
@ -4875,9 +4893,9 @@ void TextEdit::_bind_methods() {
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "context_menu_enabled"), "set_context_menu_enabled", "is_context_menu_enabled");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shortcut_keys_enabled"), "set_shortcut_keys_enabled", "is_shortcut_keys_enabled");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "selecting_enabled"), "set_selecting_enabled", "is_selecting_enabled");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "deselect_on_focus_loss_enabled"), "set_deselect_on_focus_loss_enabled", "is_deselect_on_focus_loss_enabled");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "virtual_keyboard_enabled"), "set_virtual_keyboard_enabled", "is_virtual_keyboard_enabled");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "middle_mouse_paste_enabled"), "set_middle_mouse_paste_enabled", "is_middle_mouse_paste_enabled");
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "wrap_mode", PROPERTY_HINT_ENUM, "None,Boundary"), "set_line_wrapping_mode", "get_line_wrapping_mode");
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "override_selected_font_color"), "set_override_selected_font_color", "is_overriding_selected_font_color");
|
||||
|
@ -395,6 +395,7 @@ private:
|
||||
} selection;
|
||||
|
||||
bool selecting_enabled = true;
|
||||
bool deselect_on_focus_loss_enabled = true;
|
||||
|
||||
Color font_selected_color = Color(1, 1, 1);
|
||||
Color selection_color = Color(1, 1, 1);
|
||||
@ -753,6 +754,9 @@ public:
|
||||
void set_selecting_enabled(const bool p_enabled);
|
||||
bool is_selecting_enabled() const;
|
||||
|
||||
void set_deselect_on_focus_loss_enabled(const bool p_enabled);
|
||||
bool is_deselect_on_focus_loss_enabled() const;
|
||||
|
||||
void set_override_selected_font_color(bool p_override_selected_font_color);
|
||||
bool is_overriding_selected_font_color() const;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user