Browse Source

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)
Danil Alexeev 5 years ago
parent
commit
44bdd8f16c
3 changed files with 19 additions and 5 deletions
  1. 8 1
      editor/editor_log.cpp
  2. 10 4
      scene/gui/rich_text_label.cpp
  3. 1 0
      scene/gui/rich_text_label.h

+ 8 - 1
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() {

+ 10 - 4
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);
 	}

+ 1 - 0
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);