Selection

getNodes #

Returns the array of the selected block, inline and text nodes.


let selection = this.app.create('selection');

let allnodes = selection.getNodes();
let inlines = selection.getNodes({ type: 'inline' });
let nodes = selection.getNodes({ tags: ['a', 'b'] });

getElement #

Arguments
element (optional) Node, Element, Dom

Returns the first element (not text node) relative to the caret or the specified element. Return false if the editor does not have a focus.


let selection = this.app.create('selection');

let node = selection.getElement();
let node = selection.getElement(element);

getInline #

Arguments
element (optional) Node, Element, Dom

Returns the parent inline tag relative to the caret position or the specified element. If the inline tag has nested inline tags, returns the first level inline. Returns false if the parent inline tag is not found or the editor does not have a focus.


let selection = this.app.create('selection');

let node = selection.getInline();
let node = selection.getInline(element);

getBlock #

Arguments
element (optional) Node, Element, Dom

Returns the first block tag relative to the caret or the specified element. Returns false if the editor does not have a focus.


let selection = this.app.create('selection');

let node = selection.getBlock();
let node = selection.getBlock(element);

getHtml #

Returns the selection as a HTML string.


let selection = this.app.create('selection');
let html = selection.getHtml();

getText #

Returns the selection as a text string.


let selection = this.app.create('selection');
let text = selection.getText();

setRange #

Arguments
range Object

Updates the selection by the specified range object.


let selection = this.app.create('selection');

let node = document.createTextNode('My node');
let sel = selection.get();
sel.range.collapse(true);
sel.range.insertNode(node);
sel.range.setEndBefore(node);

// set range
selection.setRange(sel.range);

is #

Checks if the selection is in the editor.


let selection = this.app.create('selection');
let is = selection.is();

isFullySelected #

Arguments
element (optional) Node, Element, Dom

Checks if all content of the element is selected.


let selection = this.app.create('selection');
let is = selection.isFullySelected(element);