Browse Source

GUI: Copy all text in `RichTextLabel` if nothing is selected

Danil Alexeev 3 months ago
parent
commit
decf5bf865
2 changed files with 12 additions and 11 deletions
  1. 12 10
      scene/gui/rich_text_label.cpp
  2. 0 1
      scene/gui/rich_text_label.h

+ 12 - 10
scene/gui/rich_text_label.cpp

@@ -2821,7 +2821,10 @@ void RichTextLabel::gui_input(const Ref<InputEvent> &p_event) {
 					handled = true;
 				}
 				if (k->is_action("ui_copy", true)) {
-					selection_copy();
+					const String txt = get_selected_text();
+					if (!txt.is_empty()) {
+						DisplayServer::get_singleton()->clipboard_set(txt);
+					}
 					handled = true;
 				}
 			}
@@ -6634,14 +6637,6 @@ void RichTextLabel::deselect() {
 	queue_redraw();
 }
 
-void RichTextLabel::selection_copy() {
-	String txt = get_selected_text();
-
-	if (!txt.is_empty()) {
-		DisplayServer::get_singleton()->clipboard_set(txt);
-	}
-}
-
 void RichTextLabel::select_all() {
 	_validate_line_caches();
 
@@ -7618,7 +7613,14 @@ Key RichTextLabel::_get_menu_action_accelerator(const String &p_action) {
 void RichTextLabel::menu_option(int p_option) {
 	switch (p_option) {
 		case MENU_COPY: {
-			selection_copy();
+			String txt = get_selected_text();
+			if (txt.is_empty()) {
+				txt = get_parsed_text();
+			}
+
+			if (!txt.is_empty()) {
+				DisplayServer::get_singleton()->clipboard_set(txt);
+			}
 		} break;
 		case MENU_SELECT_ALL: {
 			select_all();

+ 0 - 1
scene/gui/rich_text_label.h

@@ -866,7 +866,6 @@ public:
 	float get_selection_line_offset() const;
 	String get_selected_text() const;
 	void select_all();
-	void selection_copy();
 
 	_FORCE_INLINE_ void set_selection_modifier(const Callable &p_modifier) {
 		selection_modifier = p_modifier;