From fb6eb21afc0a98b2b1439268abb0facd53222a43 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. --- editor/editor_log.cpp | 10 +++++++++- scene/gui/rich_text_label.cpp | 10 ++++++++-- scene/gui/rich_text_label.h | 1 + 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/editor/editor_log.cpp b/editor/editor_log.cpp index 9595eb8a72..6fbafc7ff3 100644 --- a/editor/editor_log.cpp +++ b/editor/editor_log.cpp @@ -79,7 +79,15 @@ void EditorLog::_clear_request() { } void EditorLog::_copy_request() { - log->selection_copy(); + String text = log->get_selected_text(); + + if (text == "") { + text = log->get_text(); + } + + if (text != "") { + DisplayServer::get_singleton()->clipboard_set(text); + } } void EditorLog::clear() { diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index fb4931ea91..e8acac172c 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -2529,9 +2529,9 @@ bool RichTextLabel::search(const String &p_string, bool p_from_selection, bool p return false; } -void RichTextLabel::selection_copy() { +String RichTextLabel::get_selected_text() { if (!selection.active || !selection.enabled) { - return; + return ""; } String text; @@ -2561,6 +2561,12 @@ void RichTextLabel::selection_copy() { item = _get_next_item(item, true); } + return text; +} + +void RichTextLabel::selection_copy() { + String text = get_selected_text(); + if (text != "") { DisplayServer::get_singleton()->clipboard_set(text); } diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h index 2bda7c7fce..c5ed1cb3ef 100644 --- a/scene/gui/rich_text_label.h +++ b/scene/gui/rich_text_label.h @@ -475,6 +475,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);