Confused about the behavior of SyncToMark

I am currently reading the viewdesc code of prosemirror-view to figure out how prosemirror is render to dom.

And I found a case that would be a little stange. It shows like: syncToMark

When I add a mark and there is an identical mark at the last two positions of the current positions, prosemirror will desotroy between nodes and then rebuild them.

I found this to be handled by SyncToMark in order to reuse the mark.

 // here is the related code
// would it be better to change to `i < Math.min(this.index + 2,`
 for (let i = this.index; i < Math.min(this.index + 3,; i++) {
        if ([i].matchesMark(marks[depth])) { found = i; break }
// ...
if (found > -1) {
    if (found > this.index) {
        this.changed = true
        this.destroyBetween(this.index, found)

Would it be better only matchesMark at the next position?

Thanks for your greate work!

PS: I am new to community.What should I do if I want to contribute some code to prosemirror?

See this issue for context. Though maybe this can be further refined to avoid the redraw that you’re seeing.

If it’s something uncontroversial, open a pull request on github. For other things, open an issue on github or a thread here first.