but it triggers for a wider set of events than I need. Is there another event I can use, or is there a way to somehow detect within the layout-change event that it’s a note-change within a specific view that triggered it?
You would not want to listen to “layout-change” here - it’s for detecting the workspace’s change.
If you want to trigger a callback when the user types something in the editor, use workspace.on(“editor-change”). If you want to detect any changes to the file in the disk (including external ones), use vault.on(“modify”).
Or, you can create CodeMirror extension for this. This is for instance:
import { EditorView, type ViewUpdate } from "@codemirror/view";
import { type Extension } from "@codemirror/state";
// Example...
function handleNoteChange(update: ViewUpdate) {
// Execute when there is a change in the note...
}
const noteChangeHandler: Extension = EditorView.updateListener.of((update: ViewUpdate) => {
if (update.docChanged) {
handleNoteChange(update);
}
});
Then, register it as an editor extension:
// Assume 'this' is your plugin instance
this.registerEditorExtension(noteChangeHandler);
This will allow you to get specific range that has been changed.