How to change value of CodeMirror by TS code and HTMLElement referenced to it?

In your code, I’d say. The ‘echo’ change isn’t part of the undo transaction, so it’s recorded as a new change. This seems entirely reasonable. I’d look into a less heavy-handed way to do whatever you’re doing. For one thing, updating the document at all when the content you’re putting in matches the current document doesn’t seem like a useful thing. On top of that, when you do have an actual change to push into the editor, you could compute a matching prefix/suffix and apply only the minimal change, to give the editor some actual information about what’s changing.

@marijn not really sure what you are suggesting here, sorry.

What do you mean with “heavy-handed way”? What I need is exactly what you see: when I write somethings on the Area, it should trigger an external function (a sort of updateDataFromElement, so I can update a DataBindCustomObject); this than, will refresh Area (since its like I directly change somethings on DataBindCustomObject, and it reflects change on UI).

I feel it such as usual approch, if I want to pass-through a custom filter.

The question is: should I change the way I update content? Which way its correct?

Your code will, every time the user changes the content of the editor, replace the entire document with the new content (which was already in there). As you found, this causes issues.

Thanks. I’ll work it out to find a more better way, and in case return to you.

Thanks.

Seems I find a workaround, and now calling updateContent only when I need to reset “state/doc” is working.

BUT

How can I reset the history?
I basically can’t create a new State, since (as show above) I attach some updateListener events to the State, and I don’t want to lost them (which happens, recreating a new State from scratch).

@marijn any option to do this? Tried this (read on some post in the forum):

// clean history
const historyCompartment = new Compartment();
view.dispatch({
	effects: [historyCompartment.reconfigure([])],
});

But nothing happens (I still undo history).