Created
January 16, 2017 18:04
-
-
Save ThariqS/72cb138d33e7bcfd15d0440cc4bd555a to your computer and use it in GitHub Desktop.
Revisions
-
Thariq Shihipar created this gist
Jan 16, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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;