Editor
The main entry point into the Ace functionality.
The Editor
manages the EditSession
(which manages Document
s), as well as the VirtualRenderer
, which draws everything to the screen.
Event sessions dealing with the mouse and keyboard are bubbled up from Document
to the Editor
, which decides what to do with them.
Constructors
- new Editor(VirtualRenderer renderer, EditSession session)
Creates a new Editor
object.
renderer | VirtualRenderer | Required. Associated VirtualRenderer that draws everything |
session | EditSession | Required. The EditSession to refer to |
Events
- Editor.on("blur", function())
Emitted once the editor has been blurred.
- Editor.on("change", function(Object e))
Emitted whenever the document is changed.
e | Object | Required. Contains a single property, data , which has the delta of changes |
- Editor.on("changeSelectionStyle", function(Object data))
Emitted when the selection style changes, via Editor.setSelectionStyle()
.
data | Object | Required. Contains one property, data , which indicates the new selection style |
- Editor.on("changeSession", function(Object e))
Emitted whenever the EditSession
changes.
e | Object | Required. An object with two properties, oldSession and session , that represent the old and new EditSession s. |
- Editor.on("copy", function(String text))
Emitted when text is copied.
text | String | Required. The copied text |
- Editor.on("focus", function())
Emitted once the editor comes into focus.
- Editor.on("paste", function(Object e))
Emitted when text is pasted.
e | Object | Required. An object which contains one property, text , that represents the text to be pasted. Editing this property will alter the text that is pasted. |
Methods
Adds the selection and cursor.
orientedRange | Range | Required. A range containing a cursor |
- Editor.alignCursors()
Aligns the cursors or selected text.
- Editor.blockOutdent()
Outdents the current line.
- Editor.blur()
Blurs the current textInput
.
- Editor.centerSelection()
Attempts to center the current selection on the screen.
- Editor.clearSelection()
Empties the selection (by de-selecting it). This function also emits the 'changeSelection'
event.
- Editor.copyLinesDown()
- 返回值: Number
Copies all the selected lines down one row.
- Editor.copyLinesUp()
- 返回值: Number
Copies all the selected lines up one row.
- Editor.destroy()
Cleans up the entire editor.
- Editor.duplicateSelection()
- Undocumented
- Editor.execCommand()
- Undocumented
- Editor.exitMultiSelectMode()
Removes all the selections except the last added one.
Attempts to find needle
within the document. For more information on options
, see Search
.
needle | String | Required. The text to search for (optional) |
options | Object | Required. An object defining various search properties |
animate | Boolean | Required. If true animate scrolling |
Finds and selects all the occurrences of needle
.
The | String | Required. Text to find |
The | Object | Required. Search options |
keeps | Boolean | Required. |
Performs another search for needle
in the document. For more information on options
, see Search
.
options | Object | Required. Search options |
animate | Boolean | Required. If true animate scrolling |
Performs a search for needle
backwards. For more information on options
, see Search
.
options | Object | Required. Search options |
animate | Boolean | Required. If true animate scrolling |
- Editor.focus()
Brings the current textInput
into focus.
Executes a command for each selection range.
cmd | String | Required. The command to execute |
args | String | Required. Any arguments for the command |
- Editor.getAnimatedScroll()
- Undocumented
- Editor.getBehavioursEnabled()
- 返回值: Boolean
Returns true
if the behaviors are currently enabled. "Behaviors" in this case is the auto-pairing of special characters, like quotation marks, parenthesis, or brackets.
- Editor.getCopyText()
- 返回值: String
Returns the string of text currently highlighted.
- Editor.getCursorPosition()
- 返回值: Object
Gets the current position of the cursor.
- Editor.getCursorPositionScreen()
- 返回值: Number
Returns the screen position of the cursor.
- Editor.getDisplayIndentGuides()
- Undocumented
- Editor.getDragDelay()
- 返回值: Number
Returns the current mouse drag delay.
- Editor.getFadeFoldWidgets()
- Undocumented
- Editor.getFirstVisibleRow()
- 返回值: Number
Returns the index of the first visible row.
- Editor.getHighlightActiveLine()
- 返回值: Boolean
Returns true
if current lines are always highlighted.
- Editor.getHighlightGutterLine()
- Undocumented
- Editor.getHighlightSelectedWord()
- 返回值: Boolean
Returns true
if currently highlighted words are to be highlighted.
- Editor.getKeyboardHandler()
- 返回值: String
Returns the keyboard handler, such as "vim" or "windows".
- Editor.getLastSearchOptions()
- 返回值: Object
Returns an object containing all the search options. For more information on options
, see Search
.
- Editor.getLastVisibleRow()
- 返回值: Number
Returns the index of the last visible row.
Works like EditSession.getTokenAt()
, except it returns a number.
row | Object | Required. |
column | Object | Required. |
- Editor.getOverwrite()
- 返回值: Boolean
Returns true
if overwrites are enabled; false
otherwise.
- Editor.getPrintMarginColumn()
- 返回值: Number
Returns the column number of where the print margin is.
- Editor.getReadOnly()
- 返回值: Boolean
Returns true
if the editor is set to read-only mode.
- Editor.getScrollSpeed()
- 返回值: Number
Returns the value indicating how fast the mouse scroll speed is (in milliseconds).
- Editor.getSelection()
- 返回值: Selection
Returns selection object.
- Editor.getSelectionRange()
- 返回值: Range
Returns the Range
for the selected text.
- Editor.getSelectionStyle()
- 返回值: String
Returns the current selection style.
- Editor.getSession()
- 返回值: EditSession
Returns the current session being used.
- Editor.getShowFoldWidgets()
- 返回值: Boolean
Returns true
if the fold widgets are shown.
- Editor.getShowInvisibles()
- 返回值: Boolean
Returns true
if invisible characters are being shown.
- Editor.getShowPrintMargin()
- 返回值: Boolean
Returns true
if the print margin is being shown.
- Editor.getTheme()
- 返回值: String
Returns the path of the current theme.
- Editor.getValue()
- 返回值: String
Returns the current session's content.
- Editor.getWrapBehavioursEnabled()
Returns true
if the wrapping behaviors are currently enabled.
Moves the cursor to the specified line number, and also into the indicated column.
lineNumber | Number | Required. The line number to go to |
column | Number | Required. A column number to go to |
animate | Boolean | Required. If true animates scrolling |
- Editor.gotoPageDown()
Shifts the document to wherever "page down" is, as well as moving the cursor position.
- Editor.gotoPageUp()
Shifts the document to wherever "page up" is, as well as moving the cursor position.
- Editor.indent()
Indents the current line.
- Editor.insert(String text)
Inserts text
into wherever the cursor is pointing.
text | String | Required. The new text to add |
- Editor.isFocused()
- 返回值: Boolean
Returns true
if the current textInput
is in focus.
Indicates if the entire row is currently visible on the screen.
row | Number | Required. The row to check |
Indicates if the row is currently visible on the screen.
row | Number | Required. The row to check |
- Editor.jumpToMatching(Object select)
Moves the cursor's row and column to the next matching bracket.
select | Object | Required. |
- Editor.modifyNumber(Number amount)
If the character before the cursor is a number, this functions changes its value by amount
.
amount | Number | Required. The value to change the numeral by (can be negative to decrease value) |
Moves the cursor to the specified row and column. Note that this does not de-select the current selection.
row | Number | Required. The new row number |
column | Number | Required. The new column number |
- Editor.moveCursorToPosition(Object pos)
Moves the cursor to the position indicated by pos.row
and pos.column
.
pos | Object | Required. An object with two properties, row and column |
- Editor.moveLinesDown()
- 返回值: Number
Shifts all the selected lines down one row.
- Editor.moveLinesUp()
- 返回值: Number
Shifts all the selected lines up one row.
- Editor.moveText()
- Undocumented
- Editor.navigateDown(Number times)
Moves the cursor down in the document the specified number of times. Note that this does de-select the current selection.
times | Number | Required. The number of times to change navigation |
- Editor.navigateFileEnd()
Moves the cursor to the end of the current file. Note that this does de-select the current selection.
- Editor.navigateFileStart()
Moves the cursor to the start of the current file. Note that this does de-select the current selection.
- Editor.navigateLeft(Number times)
Moves the cursor left in the document the specified number of times. Note that this does de-select the current selection.
times | Number | Required. The number of times to change navigation |
- Editor.navigateLineEnd()
Moves the cursor to the end of the current line. Note that this does de-select the current selection.
- Editor.navigateLineStart()
Moves the cursor to the start of the current line. Note that this does de-select the current selection.
- Editor.navigateRight(Number times)
Moves the cursor right in the document the specified number of times. Note that this does de-select the current selection.
times | Number | Required. The number of times to change navigation |
Moves the cursor to the specified row and column. Note that this does de-select the current selection.
row | Number | Required. The new row number |
column | Number | Required. The new column number |
- Editor.navigateUp(Number times)
Moves the cursor up in the document the specified number of times. Note that this does de-select the current selection.
times | Number | Required. The number of times to change navigation |
- Editor.navigateWordLeft()
Moves the cursor to the word immediately to the left of the current position. Note that this does de-select the current selection.
- Editor.navigateWordRight()
Moves the cursor to the word immediately to the right of the current position. Note that this does de-select the current selection.
- Editor.onBlur()
- Undocumented
- Editor.onChangeAnnotation()
- Undocumented
- Editor.onChangeBackMarker()
- Undocumented
- Editor.onChangeBreakpoint()
- Undocumented
- Editor.onChangeFold()
- Undocumented
- Editor.onChangeFrontMarker()
- Undocumented
- Editor.onChangeMode()
- Undocumented
- Editor.onChangeWrapLimit()
- Undocumented
- Editor.onChangeWrapMode()
- Undocumented
- Editor.onCommandKey()
- Undocumented
- Editor.onCompositionEnd()
- Undocumented
- Editor.onCompositionStart()
- Undocumented
- Editor.onCompositionUpdate()
- Undocumented
- Editor.onCopy()
Called whenever a text "copy" happens.
- Editor.onCursorChange()
Emitted when the selection changes.
- Editor.onCut()
Called whenever a text "cut" happens.
- Editor.onDocumentChange()
- Undocumented
- Editor.onFocus()
- Undocumented
- Editor.onPaste(String text)
Called whenever a text "paste" happens.
text | String | Required. The pasted text |
- Editor.onScrollLeftChange()
- Undocumented
- Editor.onScrollTopChange()
- Undocumented
- Editor.onSelectionChange()
- Undocumented
- Editor.onTextInput()
- Undocumented
- Editor.onTokenizerUpdate()
- Undocumented
- Editor.redo()
Perform a redo operation on the document, reimplementing the last change.
- Editor.remove(String dir)
Removes words of text from the editor. A "word" is defined as a string of characters bookended by whitespace.
dir | String | Required. The direction of the deletion to occur, either "left" or "right" |
- Editor.removeLines()
Removes all the lines in the current selection
- Editor.removeSelectionMarker(Range The)
Removes the selection marker.
The | Range | Required. selection range added with addSelectionMarker() . |
- Editor.removeToLineEnd()
Removes all the words to the right of the current selection, until the end of the line.
- Editor.removeToLineStart()
Removes all the words to the left of the current selection, until the start of the line.
- Editor.removeWordLeft()
Removes the word directly to the left of the current selection.
- Editor.removeWordRight()
Removes the word directly to the right of the current selection.
Replaces the first occurrence of options.needle
with the value in replacement
.
replacement | String | Required. The text to replace with |
options | Object | Required. The Search options to use |
Replaces all occurrences of options.needle
with the value in replacement
.
replacement | String | Required. The text to replace with |
options | Object | Required. The Search options to use |
- Editor.resize(Boolean force)
Triggers a resize of the editor.
force | Boolean | Required. If true , recomputes the size, even if the height and width haven't changed |
- Editor.revealRange()
- Undocumented
- Editor.scrollPageDown()
Scrolls the document to wherever "page down" is, without changing the cursor position.
- Editor.scrollPageUp()
Scrolls the document to wherever "page up" is, without changing the cursor position.
Scrolls to a line. If center
is true
, it puts the line in middle of screen (or attempts to).
line | Number | Required. The line to scroll to |
center | Boolean | Required. If true |
animate | Boolean | Required. If true animates scrolling |
callback | Function | Required. Function to be called when the animation has finished |
- Editor.scrollToRow(Object row)
Moves the editor to the specified row.
row | Object | Required. |
- Editor.selectAll()
Selects all the text in editor.
Finds the next occurrence of text in an active selection and adds it to the selections.
dir | Number | Required. The direction of lines to select: -1 for up, 1 for down |
skip | Boolean | Required. If true , removes the active selection range |
Adds a cursor above or below the active cursor.
dir | Number | Required. The direction of lines to select: -1 for up, 1 for down |
skip | Boolean | Required. If true , removes the active selection range |
- Editor.selectPageDown()
Selects the text from the current position of the document until where a "page down" finishes.
- Editor.selectPageUp()
Selects the text from the current position of the document until where a "page up" finishes.
- Editor.setAnimatedScroll()
- Undocumented
- Editor.setBehavioursEnabled(Boolean enabled)
Specifies whether to use behaviors or not. "Behaviors" in this case is the auto-pairing of special characters, like quotation marks, parenthesis, or brackets.
enabled | Boolean | Required. Enables or disables behaviors |
- Editor.setDisplayIndentGuides()
- Undocumented
- Editor.setDragDelay(Number dragDelay)
Sets the delay (in milliseconds) of the mouse drag.
dragDelay | Number | Required. A value indicating the new delay |
- Editor.setFadeFoldWidgets()
- Undocumented
- Editor.setFontSize(Number size)
Set a new font size (in pixels) for the editor text.
size | Number | Required. A font size |
- Editor.setHighlightActiveLine(Boolean shouldHighlight)
Determines whether or not the current line should be highlighted.
shouldHighlight | Boolean | Required. Set to true to highlight the current line |
- Editor.setHighlightGutterLine()
- Undocumented
- Editor.setHighlightSelectedWord(Boolean shouldHighlight)
Determines if the currently selected word should be highlighted.
shouldHighlight | Boolean | Required. Set to true to highlight the currently selected word |
- Editor.setKeyboardHandler(String keyboardHandler)
Sets a new key handler, such as "vim" or "windows".
keyboardHandler | String | Required. The new key handler |
- Editor.setOverwrite(Boolean overwrite)
Pass in true
to enable overwrites in your session, or false
to disable. If overwrites is enabled, any text you enter will type over any text after it. If the value of overwrite
changes, this function also emits the changeOverwrite
event.
overwrite | Boolean | Required. Defines whether or not to set overwrites |
- Editor.setPrintMarginColumn(Number showPrintMargin)
Sets the column defining where the print margin should be.
showPrintMargin | Number | Required. Specifies the new print margin |
- Editor.setReadOnly(Boolean readOnly)
If readOnly
is true, then the editor is set to read-only mode, and none of the content can change.
readOnly | Boolean | Required. Specifies whether the editor can be modified or not |
- Editor.setScrollSpeed(Number speed)
Sets how fast the mouse scrolling should do.
speed | Number | Required. A value indicating the new speed (in milliseconds) |
- Editor.setSelectionStyle(String style)
Indicates how selections should occur.
By default, selections are set to "line". There are no other styles at the moment, although this code change in the future.
This function also emits the 'changeSelectionStyle'
event.
style | String | Required. The new selection style |
- Editor.setSession(EditSession session)
Sets a new editsession to use. This method also emits the 'changeSession'
event.
session | EditSession | Required. The new session to use |
- Editor.setShowFoldWidgets(Boolean show)
Indicates whether the fold widgets are shown or not.
show | Boolean | Required. Specifies whether the fold widgets are shown |
- Editor.setShowInvisibles(Boolean showInvisibles)
If showInvisibles
is set to true
, invisible characters—like spaces or new lines—are show in the editor.
showInvisibles | Boolean | Required. Specifies whether or not to show invisible characters |
- Editor.setShowPrintMargin(Boolean showPrintMargin)
If showPrintMargin
is set to true
, the print margin is shown in the editor.
showPrintMargin | Boolean | Required. Specifies whether or not to show the print margin |
- Editor.setStyle(String style)
Adds a new class, style
, to the editor.
style | String | Required. A class name |
- Editor.setTheme(String theme)
Sets a new theme for the editor. theme
should exist, and be a directory path, like ace/theme/textmate
.
theme | String | Required. The path to a theme |
Sets the current document to val
.
val | String | Required. The new value to set for the document |
cursorPos | Number | Required. Where to set the new value. undefined or 0 is selectAll, -1 is at the document start, and 1 is at the end |
- Editor.setWrapBehavioursEnabled(Boolean enabled)
Specifies whether to use wrapping behaviors or not, i.e. automatically wrapping the selection with characters such as brackets when such a character is typed in.
enabled | Boolean | Required. Enables or disables wrapping behaviors |
- Editor.sortLines()
- Undocumented
- Editor.splitLine()
Splits the line at the current selection (by inserting an '\n'
).
- Editor.toggleCommentLines()
Given the currently selected range, this function either comments all the lines, or uncomments all of them.
- Editor.toggleOverwrite()
Sets the value of overwrite to the opposite of whatever it currently is.
- Editor.toLowerCase()
Converts the current selection entirely into lowercase.
- Editor.toUpperCase()
Converts the current selection entirely into uppercase.
- Editor.transposeLetters()
Transposes current line.
- Editor.transposeSelections(Number dir)
Transposes the selected ranges.
dir | Number | Required. The direction to rotate selections |
- Editor.undo()
Perform an undo operation on the document, reverting the last change.
- Editor.unsetStyle(Object style)
Removes the class style
from the editor.
style | Object | Required. |
- Editor.updateSelectionMarkers()
Updates the cursor and marker layers.