Decorator iteration on click event

Hey there!
I wonder if there is a possibility to iterate through all decorations on click event.
Please take a look at the example below and the comments in the code

const DecoPlugin = ViewPlugin.fromClass(
  class {
    decorations: DecorationSet;

    constructor(view: EditorView) {
      this.decorations = deco(view);
    }

    update(update: ViewUpdate) {
      if (update.docChanged || update.viewportChanged) {
        this.decorations = deco(update.view);
      }
    }
  },
  {
    decorations: (v) => v.decorations,
    eventHandlers: {
      click: (e, view) => {
        const target = e.target as HTMLElement;

        // here I would like to check if the clicked element is a decorator
        // if YES, I want to take its coords (from, to)
      }
    }
  }
);

const deco = (view: EditorView) => {
  const widgets: Range<Decoration>[] = [];
  
  // here I add lots of decorators
  // widget.push(Decoration.replace(...)

  return Decoration.set(widgets, true);
};

Your event handler can access this.decorations, and you can use posAtCoords to get a position from a mouse event.

1 Like

thanks a lot!