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:

view :EditorView #

The CodeMirror view.

Type:

Source:

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.

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' and 'splitlines' options.

Returns:

Type
jQuery

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

getContents() → {string} #

Get the contents of the editor.

Source:

Returns:

Type
string

getSelection() → {string} #

Get the selected text.

Source:

Returns:

Type
string

replaceSelection(value) → {jQuery} #

Replace the selected text with the given value.

Parameters:

Name Type Description
value string
Source:

Returns:

Type
jQuery

scrollToCaretPosition() → {jQuery} #

Scroll the editor to the current caret position.

Source:

Returns:

Type
jQuery

setContents(content) → {jQuery} #

Set the contents of the editor.

Parameters:

Name Type Description
content string
Source:

Returns:

Type
jQuery

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