Documentation

Selection

get #

Returns the selection object:

  • is Boolean
    • selection is in the editor.
  • selection Boolean, Object
    • selection object
  • range Boolean, Object
    • range object
  • collapsed Boolean
    • selection is collapsed or not
  • current Boolean, Node
    • current selected node
  • parent Boolean, Node
    • parent selected node
var sel = this.app.selection.get();

getNodes #

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

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

getCurrent #

Returns the current selected node.

var node = this.app.selection.getCurrent();

getParent #

Returns the parent of the selected node.

var node = this.app.selection.getParent();

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.

var node = this.app.selection.getElement();
var node = this.app.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.

var node = this.app.selection.getInline();
var node = this.app.selection.getInline(element);

getHtml #

Returns the selection as a HTML string.

var html = this.app.selection.getHtml();

getText #

Returns the selection as a text string.

var text = this.app.selection.getText();

getRange #

Returns the range object.

var range = this.app.selection.getRange();

setRange #

Arguments
range Object

Updates the selection by the specified range object.

var node = document.createTextNode('My node');
var sel = this.app.selection.get();
sel.range.collapse(true);
sel.range.insertNode(node);
sel.range.setEndBefore(node);
this.app.selection.setRange(sel.range);

is #

Checks if the selection is in the editor.

var is = this.app.selection.is();

isCollapsed #

Checks if the selection is collapsed.

var isCollapsed = this.app.selection.isCollapsed();

isAll #

Arguments
element (optional) Node, Element, Dom

Checks if all content of the element is selected.

var is = this.app.selection.isAll(element);

save #

Arguments
element Node, Element, Dom

Saves the current selection.

this.app.selection.save(element);

restore #

Arguments
element Node, Element, Dom

Restores the selection if it was saved before by the save method.

this.app.selection.restore(element);