Persistent editor extension

hi guys, I’m just wondering how to get an editor extension to remain persistent while activated? I have written a plugin based on the starter code from the editor extensions documentation with the following code:

export default class CM3 extends Plugin {
settings: MyPluginSettings;

async onload() {
	await this.loadSettings();

	const activeView = this.getActiveView()
	if(!activeView) {console.log('no active view !'); return;} 		
	// @ts-expect-error not typed									
	const activeEditorView = as EditorView;
	const fieldExists = activeEditorView.state.field(emojiListField, false);

	if (!fieldExists) {
		// If the field doesn't exist, add it to the state
		const addFieldEffect = StateEffect.appendConfig.of(emojiListField);
		  effects: addFieldEffect

getActiveView() {
	const activeView =;
	if (activeView) return activeView;
	return null;

which works great within editor view after i toggle the plugin on and off, unfortunately if I switch active notes or switch to a canvas then the plugin breaks until I toggle it on and off again. Not sure how to make the plugin persistent when switching active notes?

Thanks for any guidance :sweat_smile: i’m new to plugin development!

As mentioned in this section of the docs, use this.registerEditorExtension to add an extension. Then, it will be activated for all editor instances while the plugin is enabled, and will be deactivated when the plugin gets disabled.

1 Like

this is what i was missing :sweat_smile:
thanks so much!!