I am trying to remove decorations I have made, but I don’t want to do it with StateField, as I am using ViewPlugin to create an extension, and StateField may not be optimal. I am guessing I need to use some kind of filter to remove such decorations, but I am just not sure how to. This example does remove decoration, but uses StateField: How to remove a decoration mark from state - discuss.CodeMirror
Heres the snippet of the code I am using, it creates a mark decoration at the header:
function headers(view) {
let headersList = []
for (let {from, to} of view.visibleRanges) {
syntaxTree(view.state).iterate({
from, to,
enter: (type, from, to) => {
if (type.name == "ATXHeading1") {
let deco1 = header1.range(from,to)
headersList.push(deco1)
}
}
})
}
return Decoration.set(headersList, true)
}
export const header1Plugin = ViewPlugin.fromClass(class { // this is imported onto extentions in EditorState in another file
constructor(view) {
this.decorations = headers(view)
}
update(update) {
if (update.docChanged || update.viewportChanged)
this.decorations = headers(update.view)
}
}, {
decorations: v => v.decorations,
})
How can I remove the decoration without StateField? And is there a better way to remove decoration which I am missing?