Ejemplo n.º 1
0
 note.addEventListener("click", () => {
   if (delay == null) {
     let doc = view.state.doc
     view.dispatch(view.state.tr.setSelection(TextSelection.create(doc, prob.from, prob.to)).scrollIntoView())
     view.focus()
   }
 })
FocusPlugin.prototype.click = function(view, pos, e) {
	var tr = view.state.tr;
	var sel = State.TextSelection.create(tr.doc, pos);
	var custom = false;
	if (!e.ctrlKey) {
		var dom = e.target;
		while (!dom.pmViewDesc && !dom._pcAttrs) {
			dom = dom.parentNode;
			custom = true;
		}
		if (custom && dom) {
			pos = this.editor.utils.posFromDOM(dom);
			sel = State.NodeSelection.create(tr.doc, pos);
			tr.setSelection(sel);
		} else {
			custom = false;
		}
	}
	if (this.focus(tr, sel)) {
		view.dispatch(tr);
		return custom;
	}
};
Ejemplo n.º 3
0
// plugin{
import {Plugin, TextSelection} from "prosemirror-state"

let lintPlugin = new Plugin({
  state: {
    init(_, {doc}) { return lintDeco(doc) },
    apply(tr, old) { return tr.docChanged ? lintDeco(tr.doc) : old }
  },
  props: {
    decorations(state) { return this.getState(state) },
    handleClick(view, _, event) {
      if (/lint-icon/.test(event.target.className)) {
        let {from, to} = event.target.problem
        view.dispatch(
          view.state.tr
            .setSelection(TextSelection.create(view.state.doc, from, to))
            .scrollIntoView())
        return true
      }
    },
    handleDoubleClick(view, _, event) {
      if (/lint-icon/.test(event.target.className)) {
        let prob = event.target.problem
        if (prob.fix) {
          prob.fix(view)
          view.focus()
          return true
        }
      }
    }
  }