#

API Docs for: 3.10.3
Show: Inherited Protected Private Deprecated

# EditorSelection Class

Defined in: `editor/js/editor-selection.js:1`
Module: selection
Parent Module: editor

Wraps some common Selection/Range functionality into a simple object

## Constructor

### `EditorSelection`

()

Defined in `editor/js/editor-selection.js:1`

- Index
- Methods
- Properties

## Item Index

### Methods

- _swap
- _wrap
- _wrapBlock static
- cleanCursor static
- createRange
- filter static
- filterBlocks static
- focusCursor
- getCursor
- getSelected
- getText static
- insertAtCursor
- insertContent
- remove
- removeCursor
- removeFontFamily static
- replace
- resolve static
- selectNode
- setCursor
- toString
- unfilter static
- wrapContent

### Properties

- _selection
- ALL static
- anchorNode
- anchorOffset
- anchorTextNode
- BLOCKS static
- CUR_WRAPID static
- CURSOR static
- DEFAULT_TAG static
- DEFAULT_TAG static
- focusNode
- focusOffset
- focusTextNode
- isCollapsed
- REG_CHAR static
- REG_FONTFAMILY static
- REG_NOHTML static
- REG_NON static
- text
- TMP static

## Methods

### `_swap`

(

- `n`
- `tag`

)
HTMLElement private

Defined in `editor/js/editor-selection.js:608`

Swap an element, with another element

#### Parameters:

- `n` HTMLElement

  The node to swap

- `tag` String

  The tag to use when creating the new element.

#### Returns:

HTMLElement: The new node

### `_wrap`

(

- `n`
- `tag`

)
HTMLElement private

Defined in `editor/js/editor-selection.js:593`

Wrap an element, with another element

#### Parameters:

- `n` HTMLElement

  The node to wrap

- `tag` String

  The tag to use when creating the new element.

#### Returns:

HTMLElement: The wrapped node

### `_wrapBlock`

() private static

Defined in `editor/js/editor-selection.js:331`

Wraps an array of elements in a Block level tag

### `cleanCursor`

() static

Defined in `editor/js/editor-selection.js:501`

Called from Editor keydown to remove the "extra" space before the cursor.

### `createRange`

() RangeObject

Defined in `editor/js/editor-selection.js:856`

Wrapper for the different range creation methods.

#### Returns:

RangeObject:

### `filter`

() static

Defined in `editor/js/editor-selection.js:140`

Performs a prefilter on all nodes in the editor. Looks for nodes with a style: fontFamily or font face It then creates a dynamic class assigns it and removed the property. This is so that we don't lose the fontFamily when selecting nodes.

### `filterBlocks`

() static

Defined in `editor/js/editor-selection.js:232`

Method attempts to replace all "orphined" text nodes in the main body by wrapping them with a

. Called from filter.

### `focusCursor`

() Node

Defined in `editor/js/editor-selection.js:944`

Gets a stored cursor and focuses it for editing, must be called sometime after setCursor

#### Returns:

Node:

### `getCursor`

() Node

Defined in `editor/js/editor-selection.js:918`

Get the placeholder in the DOM at the current cursor position.

#### Returns:

Node:

### `getSelected`

() NodeList

Defined in `editor/js/editor-selection.js:622`

Get all the nodes in the current selection. This method will actually perform a filter first. Then it calls doc.execCommand('fontname', null, 'yui-tmp') to touch all nodes in the selection. The it compiles a list of all nodes affected by the execCommand and builds a NodeList to return.

#### Returns:

NodeList: A NodeList of all items in the selection.

### `getText`

(

- `node`

)
String static

Defined in `editor/js/editor-selection.js:431`

Returns the innerHTML of a node with all HTML tags removed.

#### Parameters:

- `node` Node

  The Node instance to remove the HTML from

#### Returns:

String: The string of text

### `insertAtCursor`

(

- `html`
- `node`
- `offset`
- `collapse`

)
Node

Defined in `editor/js/editor-selection.js:655`

Insert HTML at the current cursor position, this method gives you control over the text node to insert into and the offset where to put it.

#### Parameters:

- `html` String

  The HTML to insert.

- `node` Node

  The text node to break when inserting.

- `offset` Number

  The left offset of the text node to break and insert the new content.

- `collapse` Boolean

  Should the range be collapsed after insertion. default: false

#### Returns:

Node: The inserted Node.

### `insertContent`

(

- `html`

)
Node

Defined in `editor/js/editor-selection.js:646`

Insert HTML at the current cursor position and return a Node instance of the newly inserted element.

#### Parameters:

- `html` String

  The HTML to insert.

#### Returns:

Node: The inserted Node.

### `remove`

() EditorSelection chainable

Defined in `editor/js/editor-selection.js:844`

Destroy the range.

#### Returns:

EditorSelection:

### `removeCursor`

(

- `keep`

)
Node

Defined in `editor/js/editor-selection.js:926`

Remove the cursor placeholder from the DOM.

#### Parameters:

- `keep` Boolean

  Setting this to true will keep the node, but remove the unique parts that make it the cursor.

#### Returns:

Node:

### `removeFontFamily`

() static

Defined in `editor/js/editor-selection.js:123`

Utility method to remove dead font-family styles from an element.

### `replace`

(

- `se`
- `re`

)
Node

Defined in `editor/js/editor-selection.js:815`

Find and replace a string inside a text node and replace it with HTML focusing the node after to allow you to continue to type.

#### Parameters:

- `se` String

  The string to search for.

- `re` String

  The string of HTML to replace it with.

#### Returns:

Node: The node inserted.

### `resolve`

(

- `n`

)
Node static

Defined in `editor/js/editor-selection.js:410`

Resolve a node from the selection object and return a Node instance

#### Parameters:

- `n` HTMLElement

  The HTMLElement to resolve. Might be a TextNode, gives parentNode.

#### Returns:

Node: The Resolved node

### `selectNode`

(

- `node`
- `collapse`

)
EditorSelection chainable

Defined in `editor/js/editor-selection.js:868`

Select a Node (hilighting it).

#### Parameters:

- `node` Node

  The node to select

- `collapse` Boolean

  Should the range be collapsed after insertion. default: false

#### Returns:

EditorSelection:

### `setCursor`

() Node

Defined in `editor/js/editor-selection.js:909`

Put a placeholder in the DOM at the current cursor position.

#### Returns:

Node:

### `toString`

() String

Defined in `editor/js/editor-selection.js:963`

Generic toString for logging.

#### Returns:

String:

### `unfilter`

() String static

Defined in `editor/js/editor-selection.js:351`

Undoes what filter does enough to return the HTML from the Editor, then re-applies the filter.

#### Returns:

String: The filtered HTML

### `wrapContent`

(

- `tag`

)
NodeList

Defined in `editor/js/editor-selection.js:764`

Get all elements inside a selection and wrap them with a new element and return a NodeList of all elements touched.

#### Parameters:

- `tag` String

  The tag to wrap all selected items with.

#### Returns:

NodeList: A NodeList of all items in the selection.

## Properties

### `_selection`

Unknown private

Defined in `editor/js/editor-selection.js:587`

The actual Selection/Range object

### `ALL`

Unknown static

Defined in `editor/js/editor-selection.js:448`

The selector to use when looking for Nodes to cache the value of: [style],font[face]

### `anchorNode`

Node

Defined in `editor/js/editor-selection.js:551`

A Node instance of the parentNode of the anchorNode of the range

### `anchorOffset`

Number

Defined in `editor/js/editor-selection.js:557`

The offset from the range object

### `anchorTextNode`

Node

Defined in `editor/js/editor-selection.js:563`

A Node instance of the actual textNode of the range.

### `BLOCKS`

Unknown static

Defined in `editor/js/editor-selection.js:455`

The selector to use when looking for block level items.

### `CUR_WRAPID`

Unknown static

Defined in `editor/js/editor-selection.js:481`

The id used to wrap the inner space of the cursor position

### `CURSOR`

Unknown static

Defined in `editor/js/editor-selection.js:488`

The default HTML used to focus the cursor..

### `DEFAULT_TAG`

Unknown static

Defined in `editor/js/editor-selection.js:474`

The id of the outer cursor wrapper

### `DEFAULT_TAG`

Unknown static

Defined in `editor/js/editor-selection.js:467`

The default tag to use when creating elements: span

### `focusNode`

Node

Defined in `editor/js/editor-selection.js:569`

A Node instance of the parentNode of the focusNode of the range

### `focusOffset`

Number

Defined in `editor/js/editor-selection.js:575`

The offset from the range object

### `focusTextNode`

Node

Defined in `editor/js/editor-selection.js:581`

A Node instance of the actual textNode of the range.

### `isCollapsed`

Boolean

Defined in `editor/js/editor-selection.js:545`

Flag to show if the range is collapsed or not

### `REG_CHAR`

Unknown static

Defined in `editor/js/editor-selection.js:309`

Regular Expression to determine if a string has a character in it

### `REG_FONTFAMILY`

Unknown static

Defined in `editor/js/editor-selection.js:302`

Regular Expression used to find dead font-family styles

### `REG_NOHTML`

Unknown static

Defined in `editor/js/editor-selection.js:323`

Regular Expression to remove all HTML from a string

### `REG_NON`

Unknown static

Defined in `editor/js/editor-selection.js:316`

Regular Expression to determine if a string has a non-character in it

### `text`

String

Defined in `editor/js/editor-selection.js:539`

Range text value

### `TMP`

Unknown static

Defined in `editor/js/editor-selection.js:461`

The temporary fontname applied to a selection to retrieve their values: yui-tmp