From 6cd4d5f061b77b526d58d1adee6f2543b8e4bb6c Mon Sep 17 00:00:00 2001
From: Arne Stenkrona <arne.stenkrona@me.com@users.noreply.github.com>
Date: Sat, 28 May 2022 19:46:17 +0200
Subject: [PATCH] Ensure focus when dropping to script editor

This improves usability by making sure actions subsequent to drop
are performed within the script editor. For example, dropping a
node from the scene tree to the script editor and attempting undo
will now undo the drop instead of performing an undo in the scene
tree.

Fixes issue #61465
---
 editor/plugins/script_text_editor.cpp | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp
index a4bccf30e31..b0cc0bff636 100644
--- a/editor/plugins/script_text_editor.cpp
+++ b/editor/plugins/script_text_editor.cpp
@@ -1524,6 +1524,7 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data
 		te->set_caret_line(row);
 		te->set_caret_column(col);
 		te->insert_text_at_caret(res->get_path());
+		te->grab_focus();
 	}
 
 	if (d.has("type") && (String(d["type"]) == "files" || String(d["type"]) == "files_and_dirs")) {
@@ -1546,6 +1547,7 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data
 		te->set_caret_line(row);
 		te->set_caret_column(col);
 		te->insert_text_at_caret(text_to_drop);
+		te->grab_focus();
 	}
 
 	if (d.has("type") && String(d["type"]) == "nodes") {
@@ -1619,6 +1621,7 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data
 		te->set_caret_line(row);
 		te->set_caret_column(col);
 		te->insert_text_at_caret(text_to_drop);
+		te->grab_focus();
 	}
 
 	if (d.has("type") && String(d["type"]) == "obj_property") {
@@ -1627,6 +1630,7 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data
 		te->set_caret_line(row);
 		te->set_caret_column(col);
 		te->insert_text_at_caret(text_to_drop);
+		te->grab_focus();
 	}
 }