Skip to content

Instantly share code, notes, and snippets.

@ThariqS
Created January 16, 2017 18:04
Show Gist options
  • Select an option

  • Save ThariqS/72cb138d33e7bcfd15d0440cc4bd555a to your computer and use it in GitHub Desktop.

Select an option

Save ThariqS/72cb138d33e7bcfd15d0440cc4bd555a to your computer and use it in GitHub Desktop.

Revisions

  1. Thariq Shihipar created this gist Jan 16, 2017.
    36 changes: 36 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    import {Decoration, DecorationSet} from "prosemirror-view";

    import {Plugin} from 'prosemirror-state';

    const SelectPlugin = new Plugin({
    state: {
    init(config, instance) {
    return { deco: DecorationSet.empty };
    },
    apply(transaction, state, prevEditorState, editorState) {
    const sel = transaction.curSelection;
    if (sel) {
    const decos = [Decoration.inline(sel.$from.pos, sel.$to.pos,
    {class: 'selection-marker'},
    { inclusiveLeft: true,
    inclusiveRight: true,
    }
    )];
    const deco = DecorationSet.create(editorState.doc, decos);
    return {deco};
    }

    return state;
    }
    },
    props: {
    decorations(state) {
    if (state && this.getState(state)) {
    return this.getState(state).deco;
    }
    return null;
    }
    }
    });

    export default SelectPlugin;