Expand all

CodeMirrorTextSelection

jQuery.textSelection implementation for CodeMirror. This is registered to both the textarea and the .cm-editor element.

Constructor

new CodeMirrorTextSelection(view) #

Parameters:

Name Type Description
view EditorView
Source:
See:

Properties

$cmDom :jQuery #

The CodeMirror DOM.

Type:

Source:
The CodeMirror DOM.

view :EditorView #

The CodeMirror view.

Type:

Source:
The CodeMirror view.

Methods

encapsulateSelection(options) → {jQuery} #

Encapsulate the selected text with the given values.

This is intentionally a near-identical implementation to jQuery.textSelection, except it uses CodeMirror's EditorState.changeByRange when there are multiple selections.

Parameters:

Name Type Description
options Object
Properties:
Name Type Attributes Default Description
pre string optional

The text to insert before the cursor/selection.

post string optional

The text to insert after the cursor/selection.

peri string optional

Text to insert between pre and post and select afterwards.

replace boolean optional
false

If there is a selection, replace it with peri instead of leaving it alone.

selectPeri boolean optional
true

Select the peri text if it was inserted.

splitlines boolean optional
false

If multiple lines are selected, encapsulate each line individually.

selectionStart number optional

Position to start selection at.

selectionEnd number optional
options.selectionStart

Position to end selection at.

Source:
To do:
  • Add support for 'ownline' option, and complete support for 'selectPeri'.

Returns:

Type
jQuery
Encapsulate the selected text with the given values.

getCaretPosition([options]) → {Array.<number>|number} #

Get the current caret position.

Parameters:

Name Type Attributes Description
options Object optional
Properties:
Name Type Attributes Description
startAndEnd boolean optional

Whether to return the start and end of the selection instead of the caret position.

Source:

Returns:

Type
Array.<number> | number
Get the current caret position.

getContents() → {string} #

Get the contents of the editor.

Source:

Returns:

Type
string
Get the contents of the editor.

getSelection() → {string} #

Get the selected text.

Source:

Returns:

Type
string
Get the selected text.

replaceSelection(value) → {jQuery} #

Replace the selected text with the given value.

Parameters:

Name Type Description
value string
Source:

Returns:

Type
jQuery
Replace the selected text with the given value.

scrollToCaretPosition() → {jQuery} #

Scroll the editor to the current caret position.

Source:

Returns:

Type
jQuery
Scroll the editor to the current caret position.

setContents(content) → {jQuery} #

Set the contents of the editor.

Parameters:

Name Type Description
content string
Source:

Returns:

Type
jQuery
Set the contents of the editor.

setSelection(options) → {jQuery} #

Set the selected text.

Parameters:

Name Type Description
options Object
Properties:
Name Type Attributes Default Description
start number

The start of the selection.

end number optional
options.start

The end of the selection.

Source:

Returns:

Type
jQuery
Set the selected text.