Class: MaiaEditor

MaiaEditor(container, language, options) → {object}

new MaiaEditor(container, language, options) → {object}

MaiaScript code editor.
Parameters:
Name Type Description
container string HTML element to setup as an editor.
language string Programming language to highlight the syntax.
options object Object containing options for configuring the editor.
Source:
Returns:
Element configured as source code editor.
Type
object

Methods

appendText(text)

Appends text in terminal.
Parameters:
Name Type Description
text string Text to be set in the terminal.
Source:
Returns:
The text is appended to terminal.

commentSelection(element)

Comments the selected text.
Parameters:
Name Type Description
element object Element where the selection is.
Source:
Returns:
The selected text commented.

copySelection()

Copy the selected text to clipboard.
Source:
Returns:
The selected text copied to clipboard.

cutSelection()

Cut the selected text from clipboard.
Source:
Returns:
The selected text cuted from clipboard.

getCursorPosition() → {number}

Gets the current position of the cursor.
Source:
Returns:
The current position of the cursor.
Type
number

getEditorHistoryLength() → {string}

Gets the editor's text.
Source:
Returns:
The text in the editor.
Type
string

getHtml() → {string}

Gets the editor's text.
Source:
Returns:
The text in the editor.
Type
string

getIndicesOf(pattern, text, caseSensitive) → {object}

Gets the indexes of all occurrences of a pattern in text.
Parameters:
Name Type Description
pattern string Search pattern.
text string Text where to look for the pattern.
caseSensitive boolear True if case sensitive. False, otherwise.
Source:
Returns:
All occurrences of a pattern in text.
Type
object

getSelectedText() → {string}

Returns the selected text.
Source:
Returns:
The selected text.
Type
string

getText() → {string}

Gets the editor's text.
Source:
Returns:
The text in the editor.
Type
string

getTextAfterCursor() → {string}

Gets the text of the line after the cursor.
Source:
Returns:
The text of the line where the cursor is.
Type
string

getTextAtCursor() → {string}

Gets the text of the line where the cursor is.
Source:
Returns:
The text of the line where the cursor is.
Type
string

getTextBeforeCursor() → {string}

Gets the text of the line before the cursor.
Source:
Returns:
The text of the line where the cursor is.
Type
string

highlightCode(element)

Highlights the code syntax in the editor.
Parameters:
Name Type Description
element object Element to do code syntax highlighte.
Source:
Returns:
The content of the editor is Highlighted.

indentSelection(element)

Indents the selected text.
Parameters:
Name Type Description
element object Element where the selection is.
Source:
Returns:
The selected text indented.

insertText(text)

Inserts text in terminal at cursor position.
Parameters:
Name Type Description
text string Text to be inserted at cursor position
Source:
Returns:
The text is inserted at cursor position.

moveCursorToEndOfSelection(editor)

Place the cursor after the selected text.
Parameters:
Name Type Description
editor object Editor object.
Source:
Returns:
Place the cursor after the selected text.

pasteSelection()

Paste the selected text to clipboard.
Source:
Returns:
The selected text pasted to clipboard.

regSub(pattern, text, flags)

Replaces text in the editor, based on a regular expression.
Parameters:
Name Type Description
pattern string Search pattern (regular expression).
text string Substitute text.
flags boolear Regular expression flags (g, i, m, u, y).
Source:
Returns:
Pattern occurrences replaced.

replaceSelectedText(text)

Replaces the selected text with one provided as a parameter.
Parameters:
Name Type Description
text string Text provided.
Source:
Returns:
The selected text replaced.

restoreEditorContent(element)

Restores the editor's previous content.
Parameters:
Name Type Description
element object Element where to restore content.
Source:
Returns:
The editor's previous content is restored.

saveEditorContent(element)

Saves the current content of the editor.
Parameters:
Name Type Description
element object Element where to save content.
Source:
Returns:
The current content of the editor is saved.
Search and highlight text in the editor.
Parameters:
Name Type Description
text string Search pattern.
caseSensitive boolear True if case sensitive. False, otherwise.
Source:
Returns:
Pattern occurrence highlighted.

setCursorPosition(position)

Sets the cursor position.
Parameters:
Name Type Description
position object The cursor position.
Source:
Returns:
The current position of the cursor is set.

setEditorHistoryLength(length)

Sets the editor history length.
Parameters:
Name Type Description
length number Editor history length.
Source:
Returns:
Sets the editor history length.

setHtml(html)

Sets the editor inner HTML.
Parameters:
Name Type Description
html string Editor inner HTML.
Source:
Returns:
Sets the editor inner HTML.

setText(text)

Sets the editor's text.
Parameters:
Name Type Description
text string Text to be set in the editor.
Source:
Returns:
The text in the editor is set.

uncommentSelection(element)

Uncomments the selected text.
Parameters:
Name Type Description
element object Element where the selection is.
Source:
Returns:
The selected text uncommented.

undoRestoreEditorContent(element)

Undo previous restores command.
Parameters:
Name Type Description
element object Element where to restore content.
Source:
Returns:
The editor's previous content is restored.

unindentSelection(element)

Unindents the selected text.
Parameters:
Name Type Description
element object Element where the selection is.
Source:
Returns:
The selected text unindented.

(inner) init()

Creates the attributes of the class.
Source:

(inner) visitElement(editor, visitor) → {number}

Visits each of the text nodes in an object.
Parameters:
Name Type Description
editor object Editor object.
visitor object Visiting object.
Source:
Returns:
The current position of the cursor.
Type
number