Decoration Removal Behavior

Hello, I have a set of decorations and I’m trying to remove a single decoration. When I remove a single decoration, it seems to remove all of the decorations from the parent paragraph node. Here is a remix link where I was able to reproduce the issue based on the linting example with the widgets removed so it’s just inline decorations. There are three paragraphs, with one decoration in each of the first two paragraphs, and then three decorations in the last paragraph. I just put a breakpoint on L91, and then in the console typed:

decorationSet = decorationSet = view.state.plugin$

It returned a decorationSet with just the first two decorations. The same happens if I try deleting the fourth and fifth decorations. If I do the same thing with either of the first 2 decorations, those are each only deleted as expected. Is this behavior normal, or am I simply using this remove function incorrectly? I found that adding a unique identifier on the spec of each decoration (like it’s from pos or some id) fixed this behavior. Thank you!

1 Like

I’ve run into the same issue, but I assumed I’d misunderstood how they were meant to be used.

Glitch seems to be down so I can’t access the code right now. Can this be reproduced in a few lines by directly creating and updating a decoration set, without involving an actual editor, or does it require more moving parts to occur?

It seems to be back up again, but I tried this and was able to reproduce the behavior.

const {Decoration, DecorationSet} = require("prosemirror-view");
const {schema} = require("prosemirror-schema-basic")
let decos = [];
let doc = schema.node("doc", null, [
  schema.node("paragraph", null, [schema.text("One.")]),
  schema.node("paragraph", null, [schema.text("Two Three ")])
decos.push(Decoration.inline(1, 2, {class: "test"}));
decos.push(Decoration.inline(10, 12, {class: "test"}));
decos.push(Decoration.inline(13, 15, {class: "test"}));
const decorationSet = DecorationSet.create(doc, decos);
const newDecorationSet = decorationSet.remove(decorationSet.find()[2]);
// Only one decoration is left in newDecorationSet

Thanks, that was indeed a bug, and should be fixed by this patch.


Great, thank you!