Something went wrong. Try again.
a tool for shared writing and social publishing
Something went wrong. Try again.
705 B · 27 lines
TypeScript
12345678910111213141516171819202122232425262728import { Decoration, DecorationSet } from "prosemirror-view";import { Plugin } from "prosemirror-state";export const highlightSelectionPlugin = new Plugin({ state: { init(_, { doc }) { return DecorationSet.empty; }, apply(tr, oldDecorations, oldState, newState) { let decorations = [];
// Check if there's a selection const { from, to } = newState.selection; if (from !== to) { decorations.push( Decoration.inline(from, to, { class: "selection-highlight" }), ); }
return DecorationSet.create(newState.doc, decorations); }, }, props: { decorations(state) { return this.getState(state); }, },});