How to use the medium-editor.selection function in medium-editor

To help you get started, we’ve selected a few medium-editor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bananaoomarang / chapters / shared / lib / cheeky-keys.js View on Github external
handleInput: function (e) {
    const sel      = MediumEditor.selection.getSelectionRange(this.document);
    const start    = sel.startContainer;
    const node     = getOuter(start);
    const offset   = MediumEditor.selection.exportSelection(node, document).start;
    const lastChar = node.textContent.charAt(offset - 1);


    for(let t of this.triggers) {
      if(t.key === lastChar) {
        t.handler(node, offset);

        break;
      }
    }
  },
});
github bananaoomarang / chapters / shared / lib / cheeky-keys.js View on Github external
handleInput: function (e) {
    const sel      = MediumEditor.selection.getSelectionRange(this.document);
    const start    = sel.startContainer;
    const node     = getOuter(start);
    const offset   = MediumEditor.selection.exportSelection(node, document).start;
    const lastChar = node.textContent.charAt(offset - 1);


    for(let t of this.triggers) {
      if(t.key === lastChar) {
        t.handler(node, offset);

        break;
      }
    }
  },
});
github brijeshb42 / kattappa / src / components / medium.js View on Github external
handleBeforeInput(e) {
    if (e.ctrlKey || e.metaKey || e.altKey || e.keyCode !== 222) {
      return;
    };
    e.preventDefault();
    const sel = MediumEditor.selection.getSelectionRange(this.medium.options.ownerDocument);
    if (sel.collapsed && sel.startOffset === sel.endOffset) {
      let pastable = '';
      const nodeText = sel.startContainer.textContent.replace(/\u00a0/g, " ");
      if (sel.startContainer.textContent === '' || sel.startOffset === 0 || nodeText[sel.startOffset - 1] === ' ') {
        if (e.shiftKey) {
          pastable = '“';
        } else {
          pastable = '‘';
        }
      } else if (nodeText[sel.startOffset - 1] !== ' ') {
        if (e.shiftKey) {
          pastable = '”';
        } else {
          pastable = '’';
        }
      } else {