Skip to content

Commit

Permalink
Avoid issue where active content views are inappropriately destroyed
Browse files Browse the repository at this point in the history
FIX: Fix a bug that corrupts the editor's internal view tree data structure on some
types of edits, putting the editor in a broken state.

Closes codemirror/dev#1306
  • Loading branch information
marijnh committed Dec 8, 2023
1 parent d5a8035 commit 5a2a1fa
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/blockview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class LineView extends ContentView implements BlockView {
if (!this.dom) source.transferDOM(this) // Reuse source.dom when appropriate
}
if (hasStart) this.setDeco(source ? source.attrs : null)
mergeChildrenInto(this, from, to, source ? source.children : [], openStart, openEnd)
mergeChildrenInto(this, from, to, source ? source.children.slice() : [], openStart, openEnd)
return true
}

Expand Down
2 changes: 1 addition & 1 deletion src/contentview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ export abstract class ContentView {
getSide() { return 0 }

destroy() {
for (let child of this.children) child.destroy()
for (let child of this.children) if (child.parent == this) child.destroy()
this.parent = null
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/inlineview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class MarkView extends ContentView {
if (source && (!(source instanceof MarkView && source.mark.eq(this.mark)) ||
(from && openStart <= 0) || (to < this.length && openEnd <= 0)))
return false
mergeChildrenInto(this, from, to, source ? source.children : [], openStart - 1, openEnd - 1)
mergeChildrenInto(this, from, to, source ? source.children.slice() : [], openStart - 1, openEnd - 1)
this.markDirty()
return true
}
Expand Down

0 comments on commit 5a2a1fa

Please sign in to comment.