How to use the medium-editor.default.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 tomchentw / medium-editor-tc-mention / src / index.js View on Github external
range.setStart(range.startContainer, this.wordStart);
      range.setEnd(range.startContainer, nextWordEnd);
      // Instead, insert our own version of it.
      // TODO: Not sure why, but using <span> tag doens't work here
      const element = this.document.createElement(this.tagName);
      element.classList.add(this.triggerClassName);
      if (this.extraTriggerClassName) {
        element.classList.add(this.extraTriggerClassName);
      }
      this.activeMentionAt = element;
      //
      range.surroundContents(element);
      selection.removeAllRanges();
      selection.addRange(range);
      //
      MediumEditor.selection.select(
        this.document,
        this.activeMentionAt.firstChild,
        this.word.length
      );
    }
    this.activeMentionAt.classList.add(this.activeTriggerClassName);
    if (this.extraActiveTriggerClassName) {
      this.activeMentionAt.classList.add(this.extraActiveTriggerClassName);
    }
  },
</span>
github tomchentw / medium-editor-tc-mention / src / index.js View on Github external
}
      const lastEmptyWord = last(firstChild.textContent);
      const hasLastEmptyWord = lastEmptyWord.trim().length === 0;
      if (hasLastEmptyWord) {
        const { textContent } = firstChild;
        firstChild.textContent = textContent.substr(0, textContent.length - 1);
        textNode.textContent = `${lastEmptyWord}${textNode.textContent}`;
      } else {
        if (textNode.textContent.length === 0 &amp;&amp; firstChild.textContent.length &gt; 1) {
          textNode.textContent = `\u00A0`;
        }
      }
      if (isArrowTowardsLeft) {
        MediumEditor.selection.select(this.document, textNode, textNode.length);
      } else {
        MediumEditor.selection.select(this.document, textNode, Math.min(textNode.length, 1));
      }
      if (firstChild.textContent.length &lt;= 1) {
        // LIKE core#execAction
        this.base.saveSelection();
        unwrapForTextNode(this.activeMentionAt, this.document);
        this.base.restoreSelection();
      }
      //
      this.activeMentionAt = null;
    }
  },