Table of contents

Selection

This module provides several helpful methods working with browser selection.

findParentTag — looks ahead from selection and finds passed tag with class name

expandToTag — expands selection to the passed tag

Finds parent tag with passed class name

String tag's name that will be found
String tag's class name must match this argument
?HTMLElement found HTML element or null if not found
findParentTag(tagName: string, className?: string): HTMLElement|null
class MyInlineTool { constructor({api}) { this.api = api; } surround(range) { if (range) { const parentAnchor = this.selection.findParentTag('A'); if (parentAnchor) { // found closest 'A' tag that wraps current selection // do something } } } }

Wraps current selection with passed tag

HTMLElement HTML element that will wrap the selection

Method does not return anything

expandToTag(node: HTMLElement): void
class MyInlineTool { constructor({api}) { this.api = api; } surround(range) { if (range) { const parentAnchor = this.api.selection.findParentTag('A'); if (parentAnchor) { // found closest 'A' tag that wraps current selection this.api.selection.expandToTag(parentAnchor); } } } }