Content on the viewer side is not updated

Hi, I am writing a plugin to sync the content across block. The content on the viewer side is not updated as editor side. For example, I edit the last "test2" block to test12345, the content of another 2 "test2" blocks will be changed to test12345. But the content on the viewer side is not updated until I make another change. It is like one step behind. Is it a known bug? How can I resolve it?

<label for="test2"></label>test1234<label>

<label for="test2"></label>test1234<label>

<label for="test1"></label>end
<label for="test2"></label>test1234<label>

CodeMirror.defineExtension("updateContent", function (regex: RegExp, replace_text: string) {
	let cm = this;
	let doc = cm.getDoc();
	cm.operation(function () {
		var cursor = cm.getCursor();
		var note_content = doc.getValue();
		var new_note_content = note_content.replace(regex, replace_text);

Joplin 2.8.8 (prod, win32)

Client ID: 18f3292857b948518bbaafd25b4218b0
Sync Version: 3
Profile Version: 41
Keychain Supported: Yes

Revision: c2a6a13