Changes dispatched to editor in Reading mode don't update the source markdown

Steps to reproduce

  1. Make a note with the text value

In my plugin I am using the following code to update a line in the source markdown:

function updateText(){
	const markdownView =
	   plugin.app.workspace.getActiveViewOfType(MarkdownView);
	  if (markdownView instanceof MarkdownView) {
		const editor = markdownView.editor;
                const value = "new value";
		updateEditorLine(editor, 0, 5, value); 
		await markdownView.save();
	}
}

export const updateEditorText = (
	editor: Editor,
        from: number,
        to: number,
	text: string
) => {
	const cm = (editor as any).cm;
	const state = cm.state.doc;
	cm.dispatch({
		changes: {
                    from,
                    to,
		    insert: text,
		},
		scrollIntoView: false,
	});
};

This code will update the source markdown while in editing mode, but if I got into reading mode, nothing is updated

//Editing mode
//markdown before
value
//markdown after
new value

//Reading mode
//markdown before
value

//markdown after
value

Expected result

Since the markdownView.editor object isn’t null, and I can dispatch calls to the editor and also call editor.save() in reading mode, I expect it to update the source markdown

Actual result

The source markdown is not updated

Environment

  • Operating system:
    Mac OS Big Sur - 11.6.4
  • Debug info:
    SYSTEM INFO:
    Obsidian version: v0.15.9
    Installer version: v0.15.8
    Operating system: Darwin Kernel Version 20.6.0: Wed Jan 12 22:22:45 PST 2022; root:xnu-7195.141.19~2/RELEASE_ARM64_T8101 20.6.0
    Login status: not logged in
    Insider build toggle: off
    Live preview: on
    Legacy editor: off
    Base theme: light
    Community theme: none
    Snippets enabled: 0
    Restricted mode: off
    Plugins installed: 9
    Plugins enabled: 1
    1: Sample Plugin v1.0.0

RECOMMENDATIONS:
Community plugins: for bugs, please first try updating all your plugins to latest. If still not fixed, please try to make the issue happen in the Sandbox Vault or disable community plugins.


Additional information

moved to developers and api.