CodeBlockEditor(el, eventManager)

Class Code Block Editor

new CodeBlockEditor(el, eventManager)

Creates an instance of CodeBlockEditor.

Parameters:
Name Type Description
el HTMLElement

code block editor container element

eventManager EventManager

event manager

Extends

Methods

addWidget(selection, node, style, offset)

Add widget

Parameters:
Name Type Description
selection object

Selection object

node HTMLElement

Widget node

style string

Adding style "over" or "bottom"

offset number

Adding offset

Inherited From:

blur()

blur focus to current Editor

Inherited From:

clear()

clear code and language

focus()

Set focus to current Editor

Inherited From:

getCaretPosition() → {Object}

Get current caret position

Returns:
Object
Inherited From:

getCurrentRange() → {Object}

getCurrentRange

Returns:
Object -
  • selection range
Inherited From:

getCursor(startopt) → {Cursor}

get code mirror cursor

Parameters:
Name Type Attributes Default Description
start string <optional>
'head'

which end of the selection. 'from'|'to'|'head'|'anchor'

Returns:
Cursor -
  • code mirror cursor
Inherited From:

getEditor() → {CodeMirror}

Get CodeMirror instance

Returns:
CodeMirror
Inherited From:

getEditorCodeText() → {string}

get code text

Returns:
string -
  • code text

getLanguage() → {string}

get code language

Returns:
string -
  • code language

getRange() → {Object}

Get start, end position of current selection

Returns:
Object
Inherited From:

getValue() → {string}

Get editor value

Returns:
string -
  • codeMirror text value
Inherited From:

getWrapperElement() → {HTMLElement}

get code mirror wrapper element

Returns:
HTMLElement -
  • code mirror wrapper element
Inherited From:

load(codeBlockElement)

load code from code block element

Parameters:
Name Type Description
codeBlockElement HTMLElement

code block element

moveCursorToEnd()

Set cursor position to end

Inherited From:

moveCursorToStart()

Set cursor position to start

Inherited From:

off(type, func)

remove codemirror event handler

Parameters:
Name Type Description
type string

event type

func function

handler function

Inherited From:

on(type, func)

add codemirror event handler

Parameters:
Name Type Description
type string

event type

func function

handler function

Inherited From:

refresh()

refresh. call if codemirror resized

remove()

Remove Editor from document

Inherited From:

replaceRelativeOffset(content, offset, overwriteLength)

Replace selection with replacement content and offset

Parameters:
Name Type Description
content string

Replacement content text

offset number

Offset

overwriteLength number

Length to overwrite

Inherited From:

replaceSelection(content, selection)

Replace selection with given replacement content

Parameters:
Name Type Description
content string

Replacement content text

selection object

Selection object

Inherited From:

reset()

Reset Editor

Inherited From:

save(codeBlockElement)

save code to code block element

Parameters:
Name Type Description
codeBlockElement HTMLElement

code block element

scrollTop(value) → {number}

Scroll Editor content to Top

Parameters:
Name Type Description
value number

Scroll amount

Returns:
number -
  • changed scroll top
Inherited From:

setEditorCodeText(codeopt)

set code text

Parameters:
Name Type Attributes Default Description
code string <optional>
''

code text

setHeight(height)

Set Editor height

Parameters:
Name Type Description
height number

Editor height

Inherited From:

setLanguage(languageopt)

set code language

Parameters:
Name Type Attributes Default Description
language string <optional>
''

code language

setMinHeight(minHeight)

set min height

Parameters:
Name Type Description
minHeight number

min height

Inherited From:

setValue(markdown, cursorToEndopt)

Set Editor value

Parameters:
Name Type Attributes Default Description
markdown string

Markdown syntax text

cursorToEnd boolean <optional>
true

move cursor to contents end

Inherited From: