Stumped with a plugin again

Godot Version

v4.6.2.stable.official [71f334935]

Question

Okay I’m stumped again with plugins. Hopefully someone might be able to point out my rookie mistake. Why do I always get a null value when calling

.get_base_editor()

It seems as though the script_editor is not getting set and is always null. My parent code for creating the dock with the UI dock works, (at the bottom), I just can’t seen to get the CodeEdit object bit right.

@tool
extends Control

class_name bookmark_browser

@onready var item_list: ItemList = $ItemList
@onready var script_editor: ScriptEditor = EditorInterface.get_script_editor()
@onready var code_editor: CodeEdit

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	code_editor = script_editor.get_current_editor().get_base_editor()
	code_editor.caret_changed.connect(script_edited)

func script_edited() -> void:
	if code_editor:
		print(code_editor.get_bookmarked_lines())
@tool
extends EditorPlugin

# Dock reference.
var dock: EditorDock

# Plugin initialization.
func _enter_tree() -> void:
	dock = EditorDock.new()
	dock.title = "Bookmarks"
	dock.default_slot = EditorDock.DOCK_SLOT_RIGHT_UL
	var dock_content: bookmark_browser = preload("./bookmarks_scene.tscn").instantiate()
	dock.add_child(dock_content)
	add_dock(dock)


# Plugin clean-up.
func _exit_tree() -> void:
	remove_dock(dock)
	dock.queue_free()
	dock = null

Hm, looks like it should work. What gets printed if you do print(code_editor) in _ready()?

I got it working with the following which I call with a timer every five seconds, just to populate a list of assembly functions if changed, would love to find a bookmarks changed event, but a start.

func _on_timer_timeout() -> void:
	if Engine.is_editor_hint():
		if EditorInterface.get_script_editor().get_current_editor() != null:
			var code_editor: CodeEdit = EditorInterface.get_script_editor().get_current_editor().get_base_editor()
			if code_editor.KIND_PLAIN_TEXT and code_editor.editable:
				if code_editor.get_bookmarked_lines() != bookmarked_lines:
					bookmarked_lines = code_editor.get_bookmarked_lines()
					item_list.clear()
					for i: int in bookmarked_lines.size():
						item_list.add_item(code_editor.get_line(bookmarked_lines[i]))

Well I got it working with the above, and now I can navigate around the assembly code with a simple click. There is probably a better way, but this works for the moment.

Since bookmarks in CodeEdit are settable only through code, the node doesn’t emit any signals regarding them.
I wouldn’t like a timer node permanently ticking in the editor.
You can pluck two menus (bar and popup) that have “Toggle Bookmark” option from the script editor and connect to their signals. It’s a bit hacky but totally doable.