insert order precedence ?

Suppose we have the following document


and we want to make it balanced into ()[]

So we want to insert a “)” and a “[” at the exact same location.

Furthermore, suppose that instead of making a single change of “)[” we want to make two separate changes of “)” and “[”.

Can this be done in one update, or do we have to make two separate update calls. If within one update call, how does CodeMirror determine precedence ? (Since both the “)” and the “[” want to insert to the same location).

Changes are applied in the order in which they are provided. Later changes have their positions mapped through earlier changes, so if you apply [{from, insert: ")"}, {from, insert: "["}], the position of the [ will be adjusted to be after the ), and you’ll insert ")[".

Thank you for the clarification. I’m not sure if this question is answerable given there is so much context in my brain that is not written down, but if we were to “insert (){}{} to balance them”, based on what you wrote above, the algorithm would look something like this right:

visit(node) {
  push if we need to insert one of "([{"

  for c in node.childs_left_to_right() {

  push if we need to insert one of ")]}"



The key point being: if both a parent and a child are missing a left-delimiter; the parent should make the change first; then the child.

If both a parent and a child are missing a right-delimiter, the child should make the change first, then the parent.

Does the gist of this vague argument make sense?