diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 9c57dd53f11..f705970d795 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -644,6 +644,43 @@ void ScriptTextEditor::_validate_script() { emit_signal("edited_script_changed"); } +void ScriptTextEditor::_update_bookmark_list() { + + bookmarks_menu->get_popup()->clear(); + + bookmarks_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_bookmark"), BOOKMARK_TOGGLE); + bookmarks_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/remove_all_bookmarks"), BOOKMARK_REMOVE_ALL); + bookmarks_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_next_bookmark"), BOOKMARK_GOTO_NEXT); + bookmarks_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_previous_bookmark"), BOOKMARK_GOTO_PREV); + + Array bookmark_list = code_editor->get_text_edit()->get_bookmarks_array(); + if (bookmark_list.size() == 0) { + return; + } + + bookmarks_menu->get_popup()->add_separator(); + + for (int i = 0; i < bookmark_list.size(); i++) { + String line = code_editor->get_text_edit()->get_line(bookmark_list[i]).strip_edges(); + // Limit the size of the line if too big. + if (line.length() > 50) { + line = line.substr(0, 50); + } + + bookmarks_menu->get_popup()->add_item(String::num((int)bookmark_list[i] + 1) + " - \"" + line + "\""); + bookmarks_menu->get_popup()->set_item_metadata(bookmarks_menu->get_popup()->get_item_count() - 1, bookmark_list[i]); + } +} + +void ScriptTextEditor::_bookmark_item_pressed(int p_idx) { + + if (p_idx < 4) { // Any item before the separator. + _edit_option(bookmarks_menu->get_popup()->get_item_id(p_idx)); + } else { + code_editor->goto_line(bookmarks_menu->get_popup()->get_item_metadata(p_idx)); + } +} + static Vector _find_all_node_for_script(Node *p_base, Node *p_current, const Ref