From 44bdd8f16c348bd0b665a22d10fd3d4b5e8033fa Mon Sep 17 00:00:00 2001 From: Danil Alexeev Date: Mon, 14 Sep 2020 21:14:27 +0300 Subject: [PATCH] Improvement for the Copy button in the Output Log Now if no text is selected, pressing the Copy button copies the entire text. (cherry picked from commit fb6eb21afc0a98b2b1439268abb0facd53222a43) --- editor/editor_log.cpp | 9 ++++++++- scene/gui/rich_text_label.cpp | 14 ++++++++++---- scene/gui/rich_text_label.h | 1 + 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/editor/editor_log.cpp b/editor/editor_log.cpp index d80ccbd9a00..2a59bbc3fb1 100644 --- a/editor/editor_log.cpp +++ b/editor/editor_log.cpp @@ -82,8 +82,15 @@ void EditorLog::_clear_request() { } void EditorLog::_copy_request() { + String text = log->get_selected_text(); - log->selection_copy(); + if (text == "") { + text = log->get_text(); + } + + if (text != "") { + OS::get_singleton()->set_clipboard(text); + } } void EditorLog::clear() { diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 21cfa410eb1..0c1a7b13fa4 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -2578,10 +2578,10 @@ bool RichTextLabel::search(const String &p_string, bool p_from_selection, bool p return false; } -void RichTextLabel::selection_copy() { - - if (!selection.active || !selection.enabled) - return; +String RichTextLabel::get_selected_text() { + if (!selection.active || !selection.enabled) { + return ""; + } String text; @@ -2611,6 +2611,12 @@ void RichTextLabel::selection_copy() { item = _get_next_item(item, true); } + return text; +} + +void RichTextLabel::selection_copy() { + String text = get_selected_text(); + if (text != "") { OS::get_singleton()->set_clipboard(text); } diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h index 618ab4351be..179bb37b40b 100644 --- a/scene/gui/rich_text_label.h +++ b/scene/gui/rich_text_label.h @@ -473,6 +473,7 @@ public: void set_selection_enabled(bool p_enabled); bool is_selection_enabled() const; + String get_selected_text(); void selection_copy(); Error parse_bbcode(const String &p_bbcode);