Skip to main content

Editor

Import :

const Editor = brackets.getModule("editor/Editor")

Editor

Kind: global class

new Editor(document, makeMasterEditor, container, [range], options)

Creates a new CodeMirror editor instance bound to the given Document. The Document need not have a "master" Editor realized yet, even if makeMasterEditor is false; in that case, the first time an edit occurs we will automatically ask EditorManager to create a "master" editor to render the Document modifiable.

ALWAYS call destroy() when you are done with an Editor - otherwise it will leak a Document ref.

ParamTypeDescription
documentDocument
makeMasterEditorbooleanIf true, this Editor will set itself as the (secret) "master" Editor for the Document. If false, this Editor will attach to the Document as a "slave"/ secondary editor.
containerjQueryObject | DomNodeContainer to add the editor to.
[range]ObjectIf specified, range of lines within the document to display in this editor. Inclusive.
optionsObjectIf specified, contains editor options that can be passed to CodeMirror

editor.addInlineWidget ⇒ $.Promise

Adds an inline widget below the given line. If any inline widget was already open for that line, it is closed without warning.

Kind: instance property of Editor
Returns: $.Promise - A promise object that is resolved when the widget has been added (but might still be animating open). Never rejected.

ParamTypeDescription
posObjectPosition in text to anchor the inline.
inlineWidgetInlineWidgetThe widget to add.
[scrollLineIntoView]booleanScrolls the associated line into view. Default true.

editor.removeAllInlineWidgets

Removes all inline widgets

Kind: instance property of Editor

editor.removeInlineWidget ⇒ $.Promise

Removes the given inline widget.

Kind: instance property of Editor
Returns: $.Promise - A promise that is resolved when the inline widget is fully closed and removed from the DOM.

ParamTypeDescription
inlineWidgetnumberThe widget to remove.

editor.removeAllInlineWidgetsForLine

Removes all inline widgets for a given line

Kind: instance property of Editor

ParamTypeDescription
lineNumnumberThe line number to modify

editor.getAllInlineWidgetsForLine

****** Update actual public API doc in Editor.js ***** Gets all inline widgets for a given line

Kind: instance property of Editor

ParamTypeDescription
lineNumnumberThe line number to modify

editor.getInlineWidgets ⇒ Object

Returns a list of all inline widgets currently open in this editor. Each entry contains the inline's id, and the data parameter that was passed to addInlineWidget().

Kind: instance property of Editor

editor.getFocusedInlineWidget ⇒ InlineWidget

Returns the currently focused inline widget, if any.

Kind: instance property of Editor

editor.setInlineWidgetHeight

Sets the height of an inline widget in this editor.

Kind: instance property of Editor

ParamTypeDescription
inlineWidgetInlineWidgetThe widget whose height should be set.
heightnumberThe height of the widget.
[ensureVisible]booleanWhether to scroll the entire widget into view. Default false.

editor.document : Document

The Document we're bound to

Kind: instance property of Editor

editor.getInlineWidgetsBelowCursor() ⇒ boolean

Gets the inline widgets below the current cursor position or null.

Kind: instance method of Editor

editor.canConsumeEscapeKeyEvent()

returns true if the editor can do something an escape key event. Eg. Disable multi cursor escape

Kind: instance method of Editor

editor.destroy()

Removes this editor from the DOM and detaches from the Document. If this is the "master" Editor that is secretly providing the Document's backing state, then the Document reverts to a read-only string-backed mode.

Kind: instance method of Editor

editor.selectAllNoScroll()

Selects all text and maintains the current scroll position.

Kind: instance method of Editor

editor.isTextSubset() ⇒ boolean

Kind: instance method of Editor
Returns: boolean - True if editor is not showing the entire text of the document (i.e. an inline editor)

editor.getFile() ⇒ File

Gets the file associated with this editor This is a required Pane-View interface method

Kind: instance method of Editor
Returns: File - the file associated with this editor

editor.getCursorPos([expandTabs], [which]) ⇒ Object

Gets the current cursor position within the editor.

Cursor positions can be converted to index(0 based character offsets in editor text string) using editor.indexFromPos API.

Kind: instance method of Editor

ParamTypeDescription
[expandTabs]booleanIf true, return the actual visual column number instead of the character offset in the "ch" property.
[which]stringOptional string indicating which end of the selection to return. It may be "start", "end", "head" (the side of the selection that moves when you press shift+arrow), or "anchor" (the fixed side of the selection). Omitting the argument is the same as passing "head". A ch object will be returned.)

editor.getEndingCursorPos([expandTabs]) ⇒ Object

Gets the cursor position of the last charected in the editor.

Kind: instance method of Editor

ParamTypeDescription
[expandTabs]booleanIf true, return the actual visual column number instead of the character offset in the "ch" property.

editor.getColOffset(pos) ⇒ number

Returns the display column (zero-based) for a given string-based pos. Differs from pos.ch only when the line contains preceding \t chars. Result depends on the current tab size setting.

Kind: instance method of Editor

ParamType
posObject

editor.getCharIndexForColumn(lineNum, column) ⇒ number

Returns the string-based pos for a given display column (zero-based) in given line. Differs from column only when the line contains preceding \t chars. Result depends on the current tab size setting.

Kind: instance method of Editor

ParamTypeDescription
lineNumnumberLine number
columnnumberDisplay column number

editor.setCursorPos(line, ch, [center], [expandTabs])

Sets the cursor position within the editor. Removes any selection.

Kind: instance method of Editor

ParamTypeDescription
linenumberThe 0 based line number.
chnumberThe 0 based character position; treated as 0 if unspecified.
[center]booleanTrue if the view should be centered on the new cursor position.
[expandTabs]booleanIf true, use the actual visual column number instead of the character offset as the "ch" parameter.

editor.setSize(width, height)

Set the editor size in pixels or percentage

Kind: instance method of Editor

ParamType
widthnumber | string
heightnumber | string

editor.getViewport() ⇒ Object

Returns a to object indicating the start (inclusive) and end (exclusive) of the currently rendered part of the document. In big documents, when most content is scrolled out of view, Editor will only render the visible part, and a margin around it. See also the viewportChange event fired on the editor.

This is combination with viewportChange event can be used to selectively redraw visual elements in code like syntax analyze only parts of code instead of the full code everytime.

Kind: instance method of Editor

editor.centerOnCursor(centerOptions)

Scrolls the editor viewport to vertically center the line with the cursor, but only if the cursor is currently near the edges of the viewport or entirely outside the viewport.

This does not alter the horizontal scroll position.

Kind: instance method of Editor

ParamTypeDescription
centerOptionsnumberOption value, or 0 for no options; one of the BOUNDARY_* constants above.

editor.indexFromPos(cursorPos) ⇒ number

Given a position, returns its index within the text (assuming \n newlines)

Kind: instance method of Editor

ParamType
cursorPosObject

editor.posFromIndex(index) ⇒ Object

Given a position, returns its index within the text (assuming \n newlines)

Kind: instance method of Editor

ParamType
indexnumber

editor.posWithinRange(pos, start, end, endInclusive)

Returns true if pos is between start and end (INclusive at start; EXclusive at end by default, but overridable via the endInclusive flag).

Kind: instance method of Editor

ParamType
posObject
startObject
endObject
endInclusiveboolean

editor.hasSelection() ⇒ boolean

Kind: instance method of Editor
Returns: boolean - True if there's a text selection; false if there's just an insertion point

editor.getSelection() ⇒ Object

Gets the current selection; if there is more than one selection, returns the primary selection (generally the last one made). Start is inclusive, end is exclusive. If there is no selection, returns the current cursor position as both the start and end of the range (i.e. a selection of length zero). If reversed is set, then the head of the selection (the end of the selection that would be changed if the user extended the selection) is before the anchor.

Kind: instance method of Editor

editor.getSelections() ⇒ Object

Returns an array of current selections, nonoverlapping and sorted in document order. Each selection is a start/end pair, with the start guaranteed to come before the end. Cursors are represented as a range whose start is equal to the end. If reversed is set, then the head of the selection (the end of the selection that would be changed if the user extended the selection) is before the anchor. If primary is set, then that selection is the primary selection.

Kind: instance method of Editor

editor.hasMultipleCursors() ⇒ boolean

Check if the editor has multiple cursors or selections

Kind: instance method of Editor

editor.convertToLineSelections(selections, options) ⇒ Object

Takes the given selections, and expands each selection so it encompasses whole lines. Merges adjacent line selections together. Keeps track of each original selection associated with a given line selection (there might be multiple if individual selections were merged into a single line selection). Useful for doing multiple-selection-aware line edits.

Kind: instance method of Editor
Returns: Object - The combined line selections. For each selection, selectionForEdit is the line selection, and selectionsToTrack is the set of original selections that combined to make up the given line selection. Note that the selectionsToTrack will include the original objects passed in selections, so if it is later mutated the original passed-in selections will be mutated as well.

ParamTypeDescription
selectionsObjectThe selections to expand.
optionsObjectexpandEndAtStartOfLine: true if a range selection that ends at the beginning of a line should be expanded to encompass the line. Default false. mergeAdjacent: true if adjacent line ranges should be merged. Default true.

editor.getSelectedText([allSelections]) ⇒ string

Returns the currently selected text, or "" if no selection. Includes \n if the selection spans multiple lines (does NOT reflect the Document's line-endings style). By default, returns only the contents of the primary selection, unless allSelections is true.

Kind: instance method of Editor
Returns: string - The selected text.

ParamTypeDescription
[allSelections]booleanWhether to return the contents of all selections (separated by newlines) instead of just the primary selection. Default false.

editor.coordsChar(coordinates, [mode]) ⇒ Object

Given an top object (e.g. coordinates of a mouse event) returns the ch position that corresponds to it. The optional mode parameter determines relative to what the coordinates are interpreted.

Kind: instance method of Editor
Returns: Object - for the given coordinates

ParamTypeDescription
coordinatesObjectcan be obtained from Eg. coordinates of a mouse event
[mode]stringIt may be "window", "page" (the default), or "local".

editor.charCoords(pos, [mode]) ⇒ Object

Returns the position and dimensions of an arbitrary character given a cursor (Eg. from getCursorPos()). It'll give the size of the whole character, rather than just the position that the cursor would have when it would sit at that position.

Kind: instance method of Editor
Returns: Object - coordinates for the given character position

ParamTypeDescription
posObjectA cursor, can be obtained from Eg. getCursorPos()
[mode]stringIt may be "window", "page" (the default), or "local".

editor.getToken([cursor], [precise]) ⇒ Object

Get the token at the given cursor position, or at the current cursor if none is given.

Kind: instance method of Editor
Returns: Object - - the CodeMirror token at the given cursor position

ParamTypeDescription
[cursor]ObjectOptional cursor position at which to retrieve a token. If not provided, the current position will be used.
[precise]booleanIf given, results in more current results. Suppresses caching.

editor.getCharacterAtPosition(pos) ⇒ string | null

Retrieves a single character from the specified position in the editor. x|y where | is the cursor, will return y

Kind: instance method of Editor
Returns: string | null - The character at the given position if within bounds, otherwise null if the position is out of range.

ParamTypeDescription
posCodeMirror.PositionThe position from which to retrieve the character. This should be an object with line and ch properties.

editor.getPrevCharacterAtPosition(pos) ⇒ string | null

Retrieves a single character previous to the specified position in the editor in the same line if possible. x|y where | is the cursor, will return x

Kind: instance method of Editor
Returns: string | null - The character previous to the given position if within bounds, otherwise null if the position is out of range.

ParamTypeDescription
posCodeMirror.PositionThe position from which to retrieve the character. This should be an object with line and ch properties.

editor.getNextToken([cursor], [skipWhitespace], [precise]) ⇒ Object

Get the token after the one at the given cursor position

Kind: instance method of Editor
Returns: Object - - the CodeMirror token after the one at the given cursor position

ParamTypeDescription
[cursor]ObjectOptional cursor position after which a token should be retrieved
[skipWhitespace]booleantrue if this should skip over whitespace tokens. Default is true.
[precise]booleanIf given, results in more current results. Suppresses caching.

editor.getPreviousToken([cursor], [skipWhitespace], [precise]) ⇒ Object

Get the token before the one at the given cursor position

Kind: instance method of Editor
Returns: Object - - the CodeMirror token before the one at the given cursor position

ParamTypeDescription
[cursor]ObjectOptional cursor position before which a token should be retrieved
[skipWhitespace]booleantrue if this should skip over whitespace tokens. Default is true.
[precise]booleanIf given, results in more current results. Suppresses caching.

editor.operation(execFn) ⇒ *

Use This if you are making large number of editor changes in a single workflow to improve performance. The editor internally buffers changes and only updates its DOM structure after it has finished performing some operation. If you need to perform a lot of operations on a CodeMirror instance, you can call this method with a function argument. It will call the function, buffering up all changes, and only doing the expensive update after the function returns. This can be a lot faster. The return value from this method will be the return value of your function.

Kind: instance method of Editor

ParamDescription
execFnThe function that will be called to make all editor changes.

editor.markToken(markType, cursor, [options]) ⇒ Object

Same as markText, but will apply to the token at the given position or current position

Kind: instance method of Editor
Returns: Object - TextMarker

ParamTypeDescription
markTypestringA String that can be used to label the mark type.
cursorObjectThe position of the token
[options]same as markText

editor.setBookmark(markType, [cursorPos], [options]) ⇒ Object

Inserts a bookmark, a handle that follows the text around it as it is being edited, at the given position. Similar to mark text, but for just a point instead of range.

Kind: instance method of Editor
Returns: Object - TextMarker- A bookmark has two methods find() and clear(). find returns the current position of the bookmark, if it is still in the document, and clear explicitly removes the bookmark.

ParamTypeDescription
markTypestringA String that can be used to label the mark type.
[cursorPos]ObjectWhere to place the mark. Optional, if not specified, will use current pos
[options]ObjectWhen given, it should be an object that may contain the following configuration options:
[options.widget]ElementCan be used to display a DOM node at the current location of the bookmark (analogous to the replacedWith option to markText).
[options.insertLeft]booleanBy default, text typed when the cursor is on top of the bookmark will end up to the right of the bookmark. Set this option to true to make it go to the left instead.
[options.handleMouseEvents]booleanAs with markText, this determines whether mouse events on the widget inserted for this bookmark are handled by CodeMirror. The default is false.

editor.findMarks(cursorFrom, cursorTo, [markType]) ⇒ Array.<TextMarker>

Returns an array of all the bookmarks and marked ranges found between the given positions (non-inclusive).

Kind: instance method of Editor
Returns: Array.<TextMarker> - TextMarker - A text marker array

ParamTypeDescription
cursorFromObjectMark start position
cursorToObjectMark end position
[markType]stringOptional, if given will only return marks of that type. Else returns everything.

editor.findMarksAt(cursorPos, [markType]) ⇒ Array.<TextMarker>

Returns an array of all the bookmarks and marked ranges present at the given position.

Kind: instance method of Editor
Returns: Array.<TextMarker> - TextMarker - A text marker array

ParamTypeDescription
cursorPosObjectcursor position
[markType]stringOptional, if given will only return marks of that type. Else returns everything.

editor.getMarksAfter(position, markType) ⇒ Array.<TextMarker>

Returns the first mark of a specific type found after the given position.

Kind: instance method of Editor
Returns: Array.<TextMarker> - The array of text markers found, or an empty array if none are found.

ParamTypeDescription
positionObjectThe starting position to search from.
markTypestringThe type of mark to look for.

editor.getMarksBefore(position, markType) ⇒ Array.<TextMarker>

Returns the first mark of a specific type found before the given position.

Kind: instance method of Editor
Returns: Array.<TextMarker> - The array of text markers found, or an empty array if none are found.

ParamTypeDescription
positionObjectThe ending position to search up to.
markTypestringThe type of mark to look for.

editor.getAllMarks([markType]) ⇒ Array.<TextMarker>

Returns an array containing all marked ranges in the document.

Kind: instance method of Editor
Returns: Array.<TextMarker> - TextMarker - A text marker array

ParamTypeDescription
[markType]stringOptional, if given will only return marks of that type. Else returns everything.

editor.clearAllMarks([markType])

Clears all mark of the given type. If nothing is given, clears all marks(Don't use this API without types!).

Kind: instance method of Editor

ParamTypeDescription
[markType]stringOptional, if given will only delete marks of that type. Else delete everything.

editor.isSamePosition(position1, position2) ⇒ boolean

Checks if two positions in the editor are the same.

Kind: instance method of Editor
Returns: boolean - True if both positions are the same, false otherwise.

ParamTypeDescription
position1Objectcursor position
position2Objectcursor position

editor.getHistory() ⇒ Array

Get a (JSON-serializable) representation of the undo history.

Kind: instance method of Editor
Returns: Array - The history of the editor.

editor.setHistory()

Replace the editor's undo history with the one provided, which must be a value as returned by getHistory. Note that this will have entirely undefined results if the editor content isn't also the same as it was when getHistory was called.

Kind: instance method of Editor

editor.createHistoryRestorePoint(restorePointName)

Creates a named restore point in undo history. this can be later be restored to undo all changed till the named restore point in one go.

Kind: instance method of Editor

ParamTypeDescription
restorePointNamestringThe name of the restore point to revert to.

editor.restoreHistoryPoint(restorePointName)

To restore the editor to a named restore point if the restore point is found, it reverts all changes made after that point.

Kind: instance method of Editor

ParamTypeDescription
restorePointNamestringThe name of the restore point to revert to.

editor.setSelection(start, [end], [center], [centerOptions], [origin])

Sets the current selection. Start is inclusive, end is exclusive. Places the cursor at the end of the selection range. Optionally centers around the cursor after making the selection

Kind: instance method of Editor

ParamTypeDescription
startObject
[end]ObjectIf not specified, defaults to start.
[center]booleantrue to center the viewport
[centerOptions]numberOption value, or 0 for no options; one of the BOUNDARY_* constants above.
[origin]stringAn optional string that describes what other selection or edit operations this should be merged with for the purposes of undo. See Document::Document#replaceRange for more details.

editor.replaceSelection(replacement, [select])

Replace the selection with the given string.

Kind: instance method of Editor

ParamTypeDescription
replacementstringthe text to replace the current selection
[select]stringThe optional select argument can be used to change selection. Passing "around" will cause the new text to be selected, passing "start" will collapse the selection to the start of the inserted text.

editor.replaceSelections(replacement, [select])

Replaces the content of multiple selections with the strings in the array. The length of the given array should be the same as the number of active selections.

Kind: instance method of Editor

ParamTypeDescription
replacementArray.<string>the text array to replace the current selections with
[select]stringThe optional select argument can be used to change selection. Passing "around" will cause the new text to be selected, passing "start" will collapse the selection to the start of the inserted text.

editor.replaceRange(replacement, from, [to], origin)

Replace the part of the document between from and to with the given string.

Kind: instance method of Editor

ParamTypeDescription
replacementstringthe text to replace the current selection
fromObjectthe strat position to replace
[to]Objectthe end position to replace. to can be left off to simply insert the string at position from.
originstringWhen origin is given, it will be passed on to "change" events, and its first letter will be used to determine whether this change can be merged with previous history events of the inserted text.

editor.replaceMultipleRanges(ranges, [origin])

Replaces multiple ranges in the editor with the specified texts.

Kind: instance method of Editor

ParamTypeDescription
rangesArrayAn array of range objects, each containing from, to, and text properties.
ranges[].fromObjectThe start position of the range to be replaced. It should have line and ch properties.
ranges[].toObjectThe end position of the range to be replaced. It should have line and ch properties.
ranges[].textstringThe text to replace the specified range.
[origin]stringAn optional origin identifier to be associated with the changes.

Example

editor.replaceMultipleRanges([
{ from: { line: 0, ch: 0 }, to: { line: 0, ch: 5 }, text: 'Hello' },
{ from: { line: 1, ch: 0 }, to: { line: 1, ch: 4 }, text: 'World' }
], 'exampleOrigin');

editor.clearSelection()

Clears any active selection if present.

Kind: instance method of Editor

editor.setSelections(selections, center, centerOptions, origin)

Sets a multiple selection, with the "primary" selection (the one returned by getSelection() and getCursorPos()) defaulting to the last if not specified. Overlapping ranges will be automatically merged, and the selection will be sorted. Optionally centers around the primary selection after making the selection.

Kind: instance method of Editor

ParamTypeDescription
selectionsObjectThe selection ranges to set. If the start and end of a range are the same, treated as a cursor. If reversed is true, set the anchor of the range to the end instead of the start. If primary is true, this is the primary selection. Behavior is undefined if more than one selection has primary set to true. If none has primary set to true, the last one is primary.
centerbooleantrue to center the viewport around the primary selection.
centerOptionsnumberOption value, or 0 for no options; one of the BOUNDARY_* constants above.
originstringAn optional string that describes what other selection or edit operations this should be merged with for the purposes of undo. See Document::Document#replaceRange for more details.

editor.toggleOverwrite(start)

Sets the editors overwrite mode state. If null is passed, the state is toggled.

Kind: instance method of Editor

ParamType
startboolean

editor.selectWordAt(pos)

Selects word that the given pos lies within or adjacent to. If pos isn't touching a word (e.g. within a token like "//"), moves the cursor to pos without selecting a range.

Kind: instance method of Editor

ParamType
posObject

editor.getTextBetween(startPos, endPos) ⇒ string

To get the text between the starting position and the ending position

Kind: instance method of Editor
Returns: string - The text between the starting position and the ending position

ParamTypeDescription
startPosObject
endPosObject

editor.getWordAt(pos) ⇒ Object

Gets word at the given pos lies within or adjacent to. If pos isn't touching a word (e.g. within a token like "//"), returns null

Kind: instance method of Editor

Param
pos

editor.getNumberAt(pos, maxDigits) ⇒ Object

Gets number string of (upto 10 digits default) at the given pos lies within or adjacent to. If pos isn't touching a number, returns null. If the number in string is greater than max digits returns null.

Kind: instance method of Editor

ParamTypeDescription
pos
maxDigitsnumbernumber of digits allowed. This is to prevent massive digit strings.

editor.lineCount() ⇒ number

Gets the total number of lines in the document (includes lines not visible in the viewport)

Kind: instance method of Editor

editor.isLineVisible(zero-based) ⇒ boolean

Deterines if line is fully visible.

Kind: instance method of Editor
Returns: boolean - true if the line is fully visible, false otherwise

ParamTypeDescription
zero-basednumberindex of the line to test

editor.getFirstVisibleLine() ⇒ number

Gets the number of the first visible line in the editor.

Kind: instance method of Editor
Returns: number - The 0-based index of the first visible line.

editor.getLastVisibleLine() ⇒ number

Gets the number of the last visible line in the editor.

Kind: instance method of Editor
Returns: number - The 0-based index of the last visible line.

editor.totalHeight() ⇒ number

Gets the total height of the document in pixels (not the viewport)

Kind: instance method of Editor
Returns: number - height in pixels

editor.getScrollerElement() ⇒ HTMLDivElement

Gets the scroller element from the editor.

Kind: instance method of Editor
Returns: HTMLDivElement - scroller

editor.getRootElement() ⇒ HTMLDivElement

Gets the root DOM node of the editor.

Kind: instance method of Editor
Returns: HTMLDivElement - The editor's root DOM node.

editor.getScrollPos() ⇒ Object

Returns the current scroll position of the editor.

Kind: instance method of Editor
Returns: Object - The x,y scroll position in pixels

editor.adjustScrollPos(scrollPos, heightDelta)

Restores and adjusts the current scroll position of the editor.

Kind: instance method of Editor

ParamTypeDescription
scrollPosObjectThe x,y scroll position in pixels
heightDeltanumberThe amount of delta H to apply to the scroll position

editor.setScrollPos(x, y)

Sets the current scroll position of the editor.

Kind: instance method of Editor

ParamTypeDescription
xnumberscrollLeft position in pixels
ynumberscrollTop position in pixels

editor.getTextHeight() ⇒ number

Returns the current text height of the editor.

Kind: instance method of Editor
Returns: number - Height of the text in pixels

editor.displayErrorMessageAtCursor(errorMsg)

Display temporary popover message at current cursor position. Display message above cursor if space allows, otherwise below.

Kind: instance method of Editor

ParamTypeDescription
errorMsgstringError message to display

editor.getVirtualScrollAreaTop() ⇒ number

Returns the offset of the top of the virtual scroll area relative to the browser window (not the editor itself). Mainly useful for calculations related to scrollIntoView(), where you're starting with the offset() of a child widget (relative to the browser window) and need to figure out how far down it is from the top of the virtual scroll area (excluding the top padding).

Kind: instance method of Editor

editor.focus()

Gives focus to the editor control

Kind: instance method of Editor

editor.hasFocus()

Returns true if the editor has focus

Kind: instance method of Editor

editor.getViewState() ⇒ EditorViewState

returns the view state for the editor

Kind: instance method of Editor

editor.restoreViewState(viewState)

Restores the view state

Kind: instance method of Editor

ParamTypeDescription
viewStateEditorViewStatethe view state object to restore

editor.refresh([handleResize])

Re-renders the editor UI

Kind: instance method of Editor

ParamTypeDescription
[handleResize]booleantrue if this is in response to resizing the editor. Default false.

editor.refreshAll([handleResize])

Re-renders the editor, and all children inline editors.

Kind: instance method of Editor

ParamTypeDescription
[handleResize]booleantrue if this is in response to resizing the editor. Default false.

editor.undo()

Undo the last edit.

Kind: instance method of Editor

editor.redo()

Redo the last un-done edit.

Kind: instance method of Editor

editor.notifyVisibilityChange(show, refresh)

View API Visibility Change Notification handler. This is also called by the native "setVisible" API which refresh can be optimized

Kind: instance method of Editor

ParamTypeDescription
showbooleantrue to show the editor, false to hide it
refreshbooleantrue (default) to refresh the editor, false to skip refreshing it

editor.setVisible(show, refresh)

Shows or hides the editor within its parent. Does not force its ancestors to become visible.

Kind: instance method of Editor

ParamTypeDescription
showbooleantrue to show the editor, false to hide it
refreshbooleantrue (default) to refresh the editor, false to skip refreshing it

editor.isFullyVisible()

Returns true if the editor is fully visible--i.e., is in the DOM, all ancestors are visible, and has a non-zero width/height.

Kind: instance method of Editor

editor.getModeForRange(start, end, [knownMixed]) ⇒ Object | string

Gets the syntax-highlighting mode for the given range. Returns null if the mode at the start of the selection differs from the mode at the end - an approximation of whether the mode is consistent across the whole range (a pattern like A-B-A would return A as the mode, not null).

Kind: instance method of Editor
Returns: Object | string - Name of syntax-highlighting mode, or object containing a "name" property naming the mode along with configuration options required by the mode.
See: LanguageManager::#getLanguageForPath and LanguageManager::Language#getMode.

ParamTypeDescription
startObjectThe start of the range to check.
endObjectThe end of the range to check.
[knownMixed]booleanWhether we already know we're in a mixed mode and need to check both the start and end.

editor.getModeForSelection(selection) ⇒ Object | string

Gets the syntax-highlighting mode for the current selection or cursor position. (The mode may vary within one file due to embedded languages, e.g. JS embedded in an HTML script block). See getModeForRange() for how this is determined for a single selection.

If there are multiple selections, this will return a mode only if all the selections are individually consistent and resolve to the same mode.

Kind: instance method of Editor
Returns: Object | string - Name of syntax-highlighting mode, or object containing a "name" property naming the mode along with configuration options required by the mode.
See: LanguageManager::#getLanguageForPath and LanguageManager::Language#getMode.

ParamType
selectionObject

editor.getLanguageForSelection() ⇒ Language

gets the language for the selection. (Javascript selected from an HTML document or CSS selected from an HTML document, etc...)

Kind: instance method of Editor

editor.getLanguageForPosition() ⇒ Language

gets the language for the selection. (Javascript selected from an HTML document or CSS selected from an HTML document, etc...)

Kind: instance method of Editor

editor.getModeForDocument() ⇒ Object | String

Gets the syntax-highlighting mode for the document.

Kind: instance method of Editor
Returns: Object | String - Object or Name of syntax-highlighting mode
See: LanguageManager.getLanguageForPath and Language.getMode.

editor.updateLayout([forceRefresh])

resizes the editor to fill its parent container should not be used on inline editors

Kind: instance method of Editor

ParamTypeDescription
[forceRefresh]booleanforces the editor to update its layout even if it already matches the container's height / width

editor.setGutterMarker(lineNumber, gutterName, marker)

Sets the marker for the specified gutter on the specified line number

Kind: instance method of Editor

ParamTypeDescription
lineNumbernumberThe line number for the inserted gutter marker
gutterNamestringThe name of the gutter
markerobjectThe dom element representing the marker to the inserted in the gutter

editor.getGutterMarker(lineNumber, gutterName)

Gets the gutter marker of the given name if found on the current line, else returns undefined.

Kind: instance method of Editor

ParamTypeDescription
lineNumbernumberThe line number for the inserted gutter marker
gutterNamestringThe name of the gutter

editor.clearGutterMarker(lineNumber, gutterName)

Clears the marker for the specified gutter on the specified line number. Does nothing if there was no marker on the line.

Kind: instance method of Editor

ParamTypeDescription
lineNumbernumberThe line number for the inserted gutter marker
gutterNamestringThe name of the gutter

editor.clearGutter(gutterName)

Clears all marks from the gutter with the specified name.

Kind: instance method of Editor

ParamTypeDescription
gutterNamestringThe name of the gutter to clear.

Editor.getMarkOptionUnderlineError

Mark option to underline errors.

Kind: static property of Editor

Editor.getMarkOptionUnderlineWarn

Mark option to underline warnings.

Kind: static property of Editor

Editor.getMarkOptionUnderlineInfo

Mark option to underline informational text.

Kind: static property of Editor

Editor.getMarkOptionUnderlineSpellcheck

Mark option to underline spelling errors.

Kind: static property of Editor

Editor.getMarkOptionHyperlinkText

Mark option to highlight hyperlinks.

Kind: static property of Editor

Editor.getMarkOptionMatchingRefs

Mark option for matching references.

Kind: static property of Editor

Editor.getMarkOptionRenameOutline

Mark option for renaming outlines.

Kind: static property of Editor

Editor.getRegisteredGutters() ⇒ Object

Returns the list of gutters current registered on all editors.

Kind: static method of Editor

Editor.isGutterRegistered(gutterName) ⇒ boolean

Return true if gutter of the given name is registered

Kind: static method of Editor

ParamTypeDescription
gutterNamestringThe name of the gutter

Editor.registerGutter(name, priority, [languageIds])

Registers the gutter with the specified name at the given priority.

Kind: static method of Editor

ParamTypeDescription
namestringThe name of the gutter.
prioritynumberA number denoting the priority of the gutter. Priorities higher than LINE_NUMBER_GUTTER_PRIORITY appear after the line numbers. Priority less than LINE_NUMBER_GUTTER_PRIORITY appear before.
[languageIds]Array.<string>A list of language ids that this gutter is valid for. If no language ids are passed, then the gutter is valid in all languages.

Editor.unregisterGutter(name)

Unregisters the gutter with the specified name and removes it from the UI.

Kind: static method of Editor

ParamTypeDescription
namestringThe name of the gutter to be unregistered.

Editor.setUseTabChar(value, [fullPath]) ⇒ boolean

Sets whether to use tab characters (vs. spaces) when inserting new text. Affects any editors that share the same preference location.

Kind: static method of Editor
Returns: boolean - true if value was valid

ParamTypeDescription
valueboolean
[fullPath]stringPath to file to get preference for

Editor.getUseTabChar([fullPath]) ⇒ boolean

Gets whether the specified or current file uses tab characters (vs. spaces) when inserting new text

Kind: static method of Editor

ParamTypeDescription
[fullPath]stringPath to file to get preference for

Editor.setTabSize(value, [fullPath]) ⇒ boolean

Sets tab character width. Affects any editors that share the same preference location.

Kind: static method of Editor
Returns: boolean - true if value was valid

ParamTypeDescription
valuenumber
[fullPath]stringPath to file to get preference for

Editor.getTabSize([fullPath]) ⇒ number

Get indent unit

Kind: static method of Editor

ParamTypeDescription
[fullPath]stringPath to file to get preference for

Editor.getAutoTabUnits(fullPath) ⇒ number | *

Gets the number of tabs for the file. Will

Kind: static method of Editor

Param
fullPath

Editor.setAutoTabSpaces(value, [fullPath]) ⇒ boolean

When set, the tabs and spaces to be used will be auto detected from the current file or fall back to defaults. Affects any editors that share the same preference location.

Kind: static method of Editor
Returns: boolean - true if value was valid

ParamTypeDescription
valueboolean
[fullPath]stringPath to file to get preference for

Editor.getAutoTabSpaces([fullPath]) ⇒ number

Get auto tabbing/spacing option

Kind: static method of Editor

ParamTypeDescription
[fullPath]stringPath to file to get preference for

Editor.setSpaceUnits(value, [fullPath]) ⇒ boolean

Sets indentation width. Affects any editors that share the same preference location.

Kind: static method of Editor
Returns: boolean - true if value was valid

ParamTypeDescription
valuenumber
[fullPath]stringPath to file to get preference for

Editor.getSpaceUnits([fullPath]) ⇒ number

Get indentation width

Kind: static method of Editor

ParamTypeDescription
[fullPath]stringPath to file to get preference for

Editor.setCloseBrackets(value, [fullPath]) ⇒ boolean

Sets the auto close brackets. Affects any editors that share the same preference location.

Kind: static method of Editor
Returns: boolean - true if value was valid

ParamTypeDescription
valueboolean
[fullPath]stringPath to file to get preference for

Editor.getCloseBrackets([fullPath]) ⇒ boolean

Gets whether the specified or current file uses auto close brackets

Kind: static method of Editor

ParamTypeDescription
[fullPath]stringPath to file to get preference for

Editor.setShowLineNumbers(value, [fullPath]) ⇒ boolean

Sets show line numbers option. Affects any editors that share the same preference location.

Kind: static method of Editor
Returns: boolean - true if value was valid

ParamTypeDescription
valueboolean
[fullPath]stringPath to file to get preference for

Editor.getShowLineNumbers([fullPath]) ⇒ boolean

Returns true if show line numbers is enabled for the specified or current file

Kind: static method of Editor

ParamTypeDescription
[fullPath]stringPath to file to get preference for

Editor.setShowActiveLine(value, [fullPath]) ⇒ boolean

Sets show active line option. Affects any editors that share the same preference location.

Kind: static method of Editor
Returns: boolean - true if value was valid

ParamTypeDescription
valueboolean
[fullPath]stringPath to file to get preference for

Editor.getShowActiveLine([fullPath]) ⇒ boolean

Returns true if show active line is enabled for the specified or current file

Kind: static method of Editor

ParamTypeDescription
[fullPath]stringPath to file to get preference for

Editor.setWordWrap(value, [fullPath]) ⇒ boolean

Sets word wrap option. Affects any editors that share the same preference location.

Kind: static method of Editor
Returns: boolean - true if value was valid

ParamTypeDescription
valueboolean
[fullPath]stringPath to file to get preference for

Editor.getWordWrap([fullPath]) ⇒ boolean

Returns true if word wrap is enabled for the specified or current file

Kind: static method of Editor

ParamTypeDescription
[fullPath]stringPath to file to get preference for

Editor.setIndentLineComment(value, [fullPath]) ⇒ boolean

Sets indentLineComment option. Affects any editors that share the same preference location.

Kind: static method of Editor
Returns: boolean - true if value was valid

ParamTypeDescription
valueboolean
[fullPath]stringPath to file to get preference for

Editor.getIndentLineComment([fullPath]) ⇒ boolean

Returns true if indentLineComment is enabled for the specified or current file

Kind: static method of Editor

ParamTypeDescription
[fullPath]stringPath to file to get preference for

Editor.forEveryEditor(callback, [fullPath])

Runs callback for every Editor instance that currently exists or only the editors matching the given fullPath.

Kind: static method of Editor

ParamTypeDescription
callbackfunction
[fullPath]stringan optional second argument, if given will only callback for all editors that is editing the file for the given fullPath

CommandManager

Editor is a 1-to-1 wrapper for a CodeMirror editor instance. It layers on Brackets-specific functionality and provides APIs that cleanly pass through the bits of CodeMirror that the rest of our codebase may want to interact with. An Editor is always backed by a Document, and stays in sync with its content; because Editor keeps the Document alive, it's important to always destroy() an Editor that's going away so it can release its Document ref.

For now, there's a distinction between the "master" Editor for a Document - which secretly acts as the Document's internal model of the text state - and the multitude of secondary Editors which, via Document, sync their changes to and from that master.

For now, direct access to the underlying CodeMirror object is still possible via _codeMirror -- but this is considered deprecated and may go away.

The Editor object dispatches the following events: (available as Editor.EVENT_* constants. see below)

  • keydown, keypress, keyup -- When any key event happens in the editor (whether it changes the text or not). Handlers are passed (BracketsEvent, Editor, KeyboardEvent). The 3nd arg is the raw DOM event. Note: most listeners will only want to listen for "keypress".
  • change - Triggered with an array of change objects. Parameters: (editor, changeList)
  • beforeChange - (self, changeObj)
  • beforeSelectionChange - (selectionObj)
  • focus - Fired when an editor is focused
  • blur - Fired when an editor loses focused
  • update - Will be fired whenever Editor updates its DOM display.
  • cursorActivity -- When the user moves the cursor or changes the selection, or an edit occurs. Note: do not listen to this in order to be generally informed of edits--listen to the "change" event on Document instead.
  • scroll -- When the editor is scrolled, either by user action or programmatically.
  • viewportChange - (from: number, to: number) Fires whenever the view port of the editor changes (due to scrolling, editing, or any other factor). The from and to arguments give the new start and end of the viewport. This is combination with editorInstance.getViewPort() can be used to selectively redraw visual elements in code like syntax analyze only parts of code instead of the full code everytime.
  • lostContent -- When the backing Document changes in such a way that this Editor is no longer able to display accurate text. This occurs if the Document's file is deleted, or in certain Document->editor syncing edge cases that we do not yet support (the latter cause will eventually go away).
  • optionChange -- Triggered when an option for the editor is changed. The 2nd arg to the listener is a string containing the editor option that is changing. The 3rd arg, which can be any data type, is the new value for the editor option.
  • beforeDestroy - Triggered before the object is about to dispose of all its internal state data so that listeners can cache things like scroll pos, etc...

The Editor also dispatches "change" events internally, but you should listen for those on Documents, not Editors.

To listen for events, do something like this: (see EventDispatcher for details on this pattern) editorInstance.on("eventname", handler);

Kind: global variable

BOUNDARY_CHECK_NORMAL : number

Constant: Normal boundary check when centering text.

Kind: global constant

BOUNDARY_IGNORE_TOP : number

Constant: Ignore the upper boundary when centering text.

Kind: global constant

BOUNDARY_BULLSEYE : number

Constant: Bulls-eye mode, strictly center the text always.

Kind: global constant

CENTERING_MARGIN

Kind: global constant