summaryrefslogtreecommitdiffstats
path: root/editor/plugins
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-04-26 15:12:47 +0200
committerRémi Verschelde <rverschelde@gmail.com>2024-04-26 15:12:47 +0200
commit7cb52a676f3f3dbfb22a67b69810b6056e6ecc9d (patch)
tree92e972a873251d77af94b5953ef07231d5a5b019 /editor/plugins
parent610a9bed1345c7336eb2dc5d969d7b75ac0067c2 (diff)
parent3a1246c198ac819edaf0d3f0c52f2255af0c8977 (diff)
downloadredot-engine-7cb52a676f3f3dbfb22a67b69810b6056e6ecc9d.tar.gz
Merge pull request #63515 from KoBeWi/script_jumper
Store line change in script navigation history
Diffstat (limited to 'editor/plugins')
-rw-r--r--editor/plugins/script_editor_plugin.cpp50
-rw-r--r--editor/plugins/script_editor_plugin.h2
-rw-r--r--editor/plugins/script_text_editor.cpp27
-rw-r--r--editor/plugins/script_text_editor.h6
4 files changed, 77 insertions, 8 deletions
diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp
index cc9e887448..c48af90622 100644
--- a/editor/plugins/script_editor_plugin.cpp
+++ b/editor/plugins/script_editor_plugin.cpp
@@ -273,6 +273,7 @@ void ScriptEditorBase::_bind_methods() {
ADD_SIGNAL(MethodInfo("request_help", PropertyInfo(Variant::STRING, "topic")));
ADD_SIGNAL(MethodInfo("request_open_script_at_line", PropertyInfo(Variant::OBJECT, "script"), PropertyInfo(Variant::INT, "line")));
ADD_SIGNAL(MethodInfo("request_save_history"));
+ ADD_SIGNAL(MethodInfo("request_save_previous_state", PropertyInfo(Variant::INT, "line")));
ADD_SIGNAL(MethodInfo("go_to_help", PropertyInfo(Variant::STRING, "what")));
ADD_SIGNAL(MethodInfo("search_in_files_requested", PropertyInfo(Variant::STRING, "text")));
ADD_SIGNAL(MethodInfo("replace_in_files_requested", PropertyInfo(Variant::STRING, "text")));
@@ -639,6 +640,32 @@ void ScriptEditor::_save_history() {
_update_history_arrows();
}
+void ScriptEditor::_save_previous_state(Dictionary p_state) {
+ if (lock_history) {
+ // Done as a result of a deferred call triggered by set_edit_state().
+ lock_history = false;
+ return;
+ }
+
+ if (history_pos >= 0 && history_pos < history.size() && history[history_pos].control == tab_container->get_current_tab_control()) {
+ Node *n = tab_container->get_current_tab_control();
+
+ if (Object::cast_to<ScriptTextEditor>(n)) {
+ history.write[history_pos].state = p_state;
+ }
+ }
+
+ history.resize(history_pos + 1);
+ ScriptHistory sh;
+ sh.control = tab_container->get_current_tab_control();
+ sh.state = Variant();
+
+ history.push_back(sh);
+ history_pos++;
+
+ _update_history_arrows();
+}
+
void ScriptEditor::_go_to_tab(int p_idx) {
ScriptEditorBase *current = _get_current_editor();
if (current) {
@@ -668,8 +695,10 @@ void ScriptEditor::_go_to_tab(int p_idx) {
sh.control = c;
sh.state = Variant();
- history.push_back(sh);
- history_pos++;
+ if (!lock_history && (history.is_empty() || history[history.size() - 1].control != sh.control)) {
+ history.push_back(sh);
+ history_pos++;
+ }
tab_container->set_current_tab(p_idx);
@@ -2185,8 +2214,11 @@ void ScriptEditor::_update_script_names() {
sd.index = i;
sedata.set(i, sd);
}
+
+ lock_history = true;
_go_to_tab(new_prev_tab);
_go_to_tab(new_cur_tab);
+ lock_history = false;
_sort_list_on_update = false;
}
@@ -2474,6 +2506,10 @@ bool ScriptEditor::edit(const Ref<Resource> &p_resource, int p_line, int p_col,
if (script_editor_cache->has_section(p_resource->get_path())) {
se->set_edit_state(script_editor_cache->get_value(p_resource->get_path(), "state"));
+ ScriptTextEditor *ste = Object::cast_to<ScriptTextEditor>(se);
+ if (ste) {
+ ste->store_previous_state();
+ }
}
_sort_list_on_update = true;
@@ -2485,6 +2521,7 @@ bool ScriptEditor::edit(const Ref<Resource> &p_resource, int p_line, int p_col,
se->connect("request_open_script_at_line", callable_mp(this, &ScriptEditor::_goto_script_line));
se->connect("go_to_help", callable_mp(this, &ScriptEditor::_help_class_goto));
se->connect("request_save_history", callable_mp(this, &ScriptEditor::_save_history));
+ se->connect("request_save_previous_state", callable_mp(this, &ScriptEditor::_save_previous_state));
se->connect("search_in_files_requested", callable_mp(this, &ScriptEditor::_on_find_in_files_requested));
se->connect("replace_in_files_requested", callable_mp(this, &ScriptEditor::_on_replace_in_files_requested));
se->connect("go_to_method", callable_mp(this, &ScriptEditor::script_goto_method));
@@ -3421,6 +3458,7 @@ void ScriptEditor::_help_class_open(const String &p_class) {
_go_to_tab(tab_container->get_tab_count() - 1);
eh->go_to_class(p_class);
eh->connect("go_to_help", callable_mp(this, &ScriptEditor::_help_class_goto));
+ eh->connect("request_save_history", callable_mp(this, &ScriptEditor::_save_history));
_add_recent_script(p_class);
_sort_list_on_update = true;
_update_script_names();
@@ -3549,6 +3587,7 @@ void ScriptEditor::_update_history_pos(int p_new_pos) {
ScriptEditorBase *seb = Object::cast_to<ScriptEditorBase>(n);
if (seb) {
+ lock_history = true;
seb->set_edit_state(history[history_pos].state);
seb->ensure_focus();
@@ -3558,9 +3597,10 @@ void ScriptEditor::_update_history_pos(int p_new_pos) {
}
}
- if (Object::cast_to<EditorHelp>(n)) {
- Object::cast_to<EditorHelp>(n)->set_scroll(history[history_pos].state);
- Object::cast_to<EditorHelp>(n)->set_focused();
+ EditorHelp *eh = Object::cast_to<EditorHelp>(n);
+ if (eh) {
+ eh->set_scroll(history[history_pos].state);
+ eh->set_focused();
}
n->set_meta("__editor_pass", ++edit_pass);
diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h
index f87cb0958c..de3ab3fd5a 100644
--- a/editor/plugins/script_editor_plugin.h
+++ b/editor/plugins/script_editor_plugin.h
@@ -472,12 +472,14 @@ class ScriptEditor : public PanelContainer {
void _history_back();
bool waiting_update_names;
+ bool lock_history = false;
void _help_class_open(const String &p_class);
void _help_class_goto(const String &p_desc);
bool _help_tab_goto(const String &p_name, const String &p_desc);
void _update_history_arrows();
void _save_history();
+ void _save_previous_state(Dictionary p_state);
void _go_to_tab(int p_idx);
void _update_history_pos(int p_new_pos);
void _update_script_colors();
diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp
index 0a6eacf11d..a642f35d6f 100644
--- a/editor/plugins/script_text_editor.cpp
+++ b/editor/plugins/script_text_editor.cpp
@@ -412,6 +412,14 @@ Variant ScriptTextEditor::get_navigation_state() {
return code_editor->get_navigation_state();
}
+Variant ScriptTextEditor::get_previous_state() {
+ return code_editor->get_previous_state();
+}
+
+void ScriptTextEditor::store_previous_state() {
+ return code_editor->store_previous_state();
+}
+
void ScriptTextEditor::_convert_case(CodeTextEditor::CaseStyle p_case) {
code_editor->convert_case(p_case);
}
@@ -904,6 +912,18 @@ void ScriptTextEditor::_breakpoint_toggled(int p_row) {
EditorDebuggerNode::get_singleton()->set_breakpoint(script->get_path(), p_row + 1, code_editor->get_text_editor()->is_line_breakpointed(p_row));
}
+void ScriptTextEditor::_on_caret_moved() {
+ int current_line = code_editor->get_text_editor()->get_caret_line();
+ if (ABS(current_line - previous_line) >= 10) {
+ Dictionary nav_state = get_navigation_state();
+ nav_state["row"] = previous_line;
+ nav_state["scroll_position"] = -1;
+ emit_signal(SNAME("request_save_previous_state"), nav_state);
+ store_previous_state();
+ }
+ previous_line = current_line;
+}
+
void ScriptTextEditor::_lookup_symbol(const String &p_symbol, int p_row, int p_column) {
Node *base = get_tree()->get_edited_scene_root();
if (base) {
@@ -1344,12 +1364,12 @@ void ScriptTextEditor::_edit_option(int p_op) {
code_editor->get_text_editor()->duplicate_lines();
} break;
case EDIT_TOGGLE_FOLD_LINE: {
- int previous_line = -1;
+ int prev_line = -1;
for (int caret_idx : tx->get_caret_index_edit_order()) {
int line_idx = tx->get_caret_line(caret_idx);
- if (line_idx != previous_line) {
+ if (line_idx != prev_line) {
tx->toggle_foldable_line(line_idx);
- previous_line = line_idx;
+ prev_line = line_idx;
}
}
tx->queue_redraw();
@@ -2352,6 +2372,7 @@ ScriptTextEditor::ScriptTextEditor() {
code_editor->get_text_editor()->set_draw_breakpoints_gutter(true);
code_editor->get_text_editor()->set_draw_executing_lines_gutter(true);
code_editor->get_text_editor()->connect("breakpoint_toggled", callable_mp(this, &ScriptTextEditor::_breakpoint_toggled));
+ code_editor->get_text_editor()->connect("caret_changed", callable_mp(this, &ScriptTextEditor::_on_caret_moved));
connection_gutter = 1;
code_editor->get_text_editor()->add_gutter(connection_gutter);
diff --git a/editor/plugins/script_text_editor.h b/editor/plugins/script_text_editor.h
index 2ea73d4c73..de89fe458c 100644
--- a/editor/plugins/script_text_editor.h
+++ b/editor/plugins/script_text_editor.h
@@ -99,6 +99,7 @@ class ScriptTextEditor : public ScriptEditorBase {
Color marked_line_color = Color(1, 1, 1);
Color folded_code_region_color = Color(1, 1, 1);
+ int previous_line = 0;
PopupPanel *color_panel = nullptr;
ColorPicker *color_picker = nullptr;
@@ -164,6 +165,8 @@ protected:
void _breakpoint_item_pressed(int p_idx);
void _breakpoint_toggled(int p_row);
+ void _on_caret_moved();
+
void _validate_script(); // No longer virtual.
void _update_warnings();
void _update_errors();
@@ -260,6 +263,9 @@ public:
virtual void validate() override;
+ Variant get_previous_state();
+ void store_previous_state();
+
ScriptTextEditor();
~ScriptTextEditor();
};