This class represents all essential editing state for a single TextBuffer, including cursor and selection positions, folds, and soft wraps. If you’re manipulating the state of an editor, use this class.
A single TextBuffer can belong to multiple editors. For example, if the same file is open in two different panes, Atom creates a separate editor for each pane. If the buffer is manipulated the changes are reflected in both editors, but each maintains its own cursor position, folded lines, etc.
The easiest way to get hold of TextEditor
objects is by registering a callback
with ::observeTextEditors
on the atom.workspace
global. Your callback will
then be called with all current editor instances and also when any editor is
created in the future.
atom.workspace.observeTextEditors(editor => {
editor.insertText('Hello World')
})
Because editors support folds and soft-wrapping, the lines on screen don’t always match the lines in the buffer. For example, a long line that soft wraps twice renders as three lines on screen, but only represents one line in the buffer. Similarly, if rows 5-10 are folded, then row 6 on screen corresponds to row 11 in the buffer.
Your choice of coordinates systems will depend on what you’re trying to achieve. For example, if you’re writing a command that jumps the cursor up or down by 10 lines, you’ll want to use screen coordinates because the user probably wants to skip lines on screen. However, if you’re writing a package that jumps between method definitions, you’ll want to work in buffer coordinates.
When in doubt, just default to buffer coordinates, then experiment with soft wraps and folds to ensure your code interacts with them correctly.
Calls your callback
when the buffer’s title has changed.
Argument | Description |
---|---|
|
Return values |
---|
Returns a Disposable on which |
Calls your callback
when the buffer’s path, and therefore title, has changed.
Argument | Description |
---|---|
|
Return values |
---|
Returns a Disposable on which |
Invoke the given callback synchronously when the content of the buffer changes.
Because observers are invoked synchronously, it’s important not to perform any expensive operations via this method. Consider ::onDidStopChanging to delay expensive operations until after changes stop occurring.
Argument | Description |
---|---|
|
Return values |
---|
Returns a Disposable on which |
Invoke callback
when the buffer’s contents change. It is
emit asynchronously 300ms after the last buffer change. This is a good place
to handle changes to the buffer without compromising typing performance.
Argument | Description |
---|---|
|
Return values |
---|
Returns a Disposable on which |
Calls your callback
when a Cursor is moved. If there are
multiple cursors, your callback will be called for each cursor.
Argument | Description |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Cursor that triggered the event |
Return values |
---|
Returns a Disposable on which |
Calls your callback
when a selection’s screen range changes.
Argument | Description |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
Selection that triggered the event |
Return values |
---|
Returns a Disposable on which |
Invoke the given callback after the buffer is saved to disk.
Argument | Description |
---|---|
|
Function to be called after the buffer is saved. |
|
Object with the following keys: |
|
The path to which the buffer was saved. |
Return values |
---|
Returns a Disposable on which |
Invoke the given callback when the editor is destroyed.
Argument | Description |
---|---|
|
Function to be called when the editor is destroyed. |
Return values |
---|
Returns a Disposable on which |
Calls your callback
when a Gutter is added to the editor.
Immediately calls your callback for each existing gutter.
Argument | Description |
---|---|
|
|
|
Gutter that currently exists/was added. |
Return values |
---|
Returns a Disposable on which |
Calls your callback
when a Gutter is added to the editor.
Argument | Description |
---|---|
|
|
|
Gutter that was added. |
Return values |
---|
Returns a Disposable on which |
Calls your callback
when a Gutter is removed from the editor.
Argument | Description |
---|---|
|
|
|
The name of the Gutter that was removed. |
Return values |
---|
Returns a Disposable on which |
Calls your callback
when soft wrap was enabled or disabled.
Argument | Description |
---|---|
|
Return values |
---|
Returns a Disposable on which |
Calls your callback
when the buffer’s encoding has changed.
Argument | Description |
---|---|
|
Return values |
---|
Returns a Disposable on which |
Calls your callback
when the grammar that interprets and
colorizes the text has been changed. Immediately calls your callback with
the current grammar.
Argument | Description |
---|---|
|
|
|
Return values |
---|
Returns a Disposable on which |
Calls your callback
when the grammar that interprets and
colorizes the text has been changed.
Argument | Description |
---|---|
|
|
|
Return values |
---|
Returns a Disposable on which |
Calls your callback
when the result of ::isModified changes.
Argument | Description |
---|---|
|
Return values |
---|
Returns a Disposable on which |
Calls your callback
when the buffer’s underlying file changes on
disk at a moment when the result of ::isModified is true.
Argument | Description |
---|---|
|
Return values |
---|
Returns a Disposable on which |
Calls your callback
before text has been inserted.
Argument | Description |
---|---|
|
|
|
event Object |
|
String text to be inserted |
|
Function Call to prevent the text from being inserted |
Return values |
---|
Returns a Disposable on which |
Calls your callback
after text has been inserted.
Argument | Description |
---|---|
|
|
|
event Object |
|
String text to be inserted |
Return values |
---|
Returns a Disposable on which |
Calls your callback
when a Cursor is added to the editor.
Immediately calls your callback for each existing cursor.
Argument | Description |
---|---|
|
|
|
Cursor that was added |
Return values |
---|
Returns a Disposable on which |
Calls your callback
when a Cursor is added to the editor.
Argument | Description |
---|---|
|
|
|
Cursor that was added |
Return values |
---|
Returns a Disposable on which |
Calls your callback
when a Cursor is removed from the editor.
Argument | Description |
---|---|
|
|
|
Cursor that was removed |
Return values |
---|
Returns a Disposable on which |
Calls your callback
when a Selection is added to the editor.
Immediately calls your callback for each existing selection.
Argument | Description |
---|---|
|
|
|
Selection that was added |
Return values |
---|
Returns a Disposable on which |
Calls your callback
when a Selection is added to the editor.
Argument | Description |
---|---|
|
|
|
Selection that was added |
Return values |
---|
Returns a Disposable on which |
Calls your callback
when a Selection is removed from the editor.
Argument | Description |
---|---|
|
|
|
Selection that was removed |
Return values |
---|
Returns a Disposable on which |
Calls your callback
with each Decoration added to the editor.
Calls your callback
immediately for any existing decorations.
Argument | Description |
---|---|
|
|
|
Return values |
---|
Returns a Disposable on which |
Calls your callback
when a Decoration is added to the editor.
Argument | Description |
---|---|
|
|
|
Decoration that was added |
Return values |
---|
Returns a Disposable on which |
Calls your callback
when a Decoration is removed from the editor.
Argument | Description |
---|---|
|
|
|
Decoration that was removed |
Return values |
---|
Returns a Disposable on which |
Calls your callback
when the placeholder text is changed.
Argument | Description |
---|---|
|
|
|
String new text |
Return values |
---|
Returns a Disposable on which |
Retrieves the current TextBuffer.
Get the editor’s title for display in other parts of the UI such as the tabs.
If the editor’s buffer is saved, its title is the file name. If it is unsaved, its title is “untitled”.
Return values |
---|
Returns a String. |
Get unique title for display in other parts of the UI, such as the window title.
If the editor’s buffer is unsaved, its title is “untitled” If the editor’s buffer is saved, its unique title is formatted as one of the following,
Return values |
---|
Returns a String |
Set the character set encoding to use in this editor’s text buffer.
Argument | Description |
---|---|
|
The String character set encoding name such as ‘utf8’ |
Saves the editor’s text buffer.
See TextBuffer::save for more details.
Saves the editor’s text buffer as the given path.
See TextBuffer::saveAs for more details.
Argument | Description |
---|---|
|
A String path. |
Return values |
---|
Returns a Number representing the number of screen lines in the editor. This accounts for folds. |
Set the text in the given Range in buffer coordinates.
Argument | Description |
---|---|
|
|
|
A String |
|
optional |
|
optional
Boolean (default: true) |
|
optional
Deprecated String ‘skip’ will skip the undo system. This property is deprecated. Call groupLastChanges() on the TextBuffer afterward instead. |
|
optional
Boolean Must be |
Return values |
---|
Returns the Range of the newly-inserted text. |
For each selection, transpose the selected text.
If the selection is empty, the characters preceding and following the cursor are swapped. Otherwise, the selected characters are reversed.
Argument | Description |
---|---|
|
optional |
|
optional
Boolean Must be |
Convert the selected text to upper case.
For each selection, if the selection is empty, converts the containing word to upper case. Otherwise convert the selected text to upper case.
Argument | Description |
---|---|
|
optional |
|
optional
Boolean Must be |
Convert the selected text to lower case.
For each selection, if the selection is empty, converts the containing word to upper case. Otherwise convert the selected text to upper case.
Argument | Description |
---|---|
|
optional |
|
optional
Boolean Must be |
Similar to ::deleteToBeginningOfWord, but deletes only back to the previous word boundary.
Argument | Description |
---|---|
|
optional |
|
optional
Boolean Must be |
Similar to ::deleteToEndOfWord, but deletes only up to the next word boundary.
Argument | Description |
---|---|
|
optional |
|
optional
Boolean Must be |
For each selection, if the selection is not empty, deletes the selection; otherwise, deletes all characters of the containing line following the cursor. If the cursor is already at the end of the line, deletes the following newline.
Argument | Description |
---|---|
|
optional |
|
optional
Boolean Must be |
Batch multiple operations as a single undo/redo step.
Any group of operations that are logically grouped from the perspective of undoing and redoing should be performed in a transaction. If you want to abort the transaction, call ::abortTransaction to terminate the function’s execution and revert any changes performed up to the abortion.
Argument | Description |
---|---|
|
optional
The Number of milliseconds for which this transaction should be considered ‘groupable’ after it begins. If a transaction with a positive |
|
A Function to call inside the transaction. |
Abort an open transaction, undoing any operations performed so far within the transaction.
Create a pointer to the current state of the buffer for use with ::revertToCheckpoint and ::groupChangesSinceCheckpoint.
Return values |
---|
Returns a checkpoint value. |
Revert the buffer to the state it was in when the given checkpoint was created.
The redo stack will be empty following this operation, so changes since the
checkpoint will be lost. If the given checkpoint is no longer present in the
undo history, no changes will be made to the buffer and this method will
return false
.
Argument | Description |
---|---|
|
The checkpoint to revert to. |
Return values |
---|
Returns a Boolean indicating whether the operation succeeded. |
Group all changes since the given checkpoint into a single transaction for purposes of undo/redo.
If the given checkpoint is no longer present in the undo history, no
grouping will be performed and this method will return false
.
Argument | Description |
---|---|
|
The checkpoint from which to group changes. |
Return values |
---|
Returns a Boolean indicating whether the operation succeeded. |
Convert a position in buffer-coordinates to screen-coordinates.
The position is clipped via ::clipBufferPosition prior to the conversion.
The position is also clipped via ::clipScreenPosition following the
conversion, which only makes a difference when options
are supplied.
Argument | Description |
---|---|
|
|
|
optional
An options hash for ::clipScreenPosition. |
Return values |
---|
Returns a Point. |
Convert a position in screen-coordinates to buffer-coordinates.
The position is clipped via ::clipScreenPosition prior to the conversion.
Argument | Description |
---|---|
|
|
|
optional
An options hash for ::clipScreenPosition. |
Return values |
---|
Returns a Point. |
Clip the start and end of the given range to valid positions in the buffer. See ::clipBufferPosition for more information.
Argument | Description |
---|---|
|
The Range to clip. |
Return values |
---|
Returns a Range. |
Clip the given Point to a valid position on screen.
Argument | Description |
---|---|
|
The Point representing the position to clip. |
|
optional |
|
String If |
Return values |
---|
Returns a Point. |
Clip the start and end of the given range to valid positions on screen. See ::clipScreenPosition for more information.
Argument | Description |
---|---|
|
The Range to clip. |
|
optional
See ::clipScreenPosition |
Return values |
---|
Returns a Range. |
Add a decoration that tracks a DisplayMarker. When the marker moves, is invalidated, or is destroyed, the decoration will be updated to reflect the marker’s state.
The following are the supported decorations types:
class
to the lines overlapping the rows
spanned by the marker.class
to the line numbers overlapping
the rows spanned by the markerclass
or style
to these spans. Use this to manipulate the foreground
color or styling of text in a range..highlight
div to the editor
containing nested divs that cover the marked region. For example, when the user
selects text, the selection is implemented with a highlight decoration. The structure
of this highlight will be:
<div class="highlight <your-class>">
<!-- Will be one region for each row in the range. Spans 2 lines? There will be 2 regions. -->
<div class="region"></div>
</div>
DisplayMarker
, depending on the position
property.Gutter
instance.position
property.
Block decorations at the same screen row are ordered by their order
property.Argument | Description |
---|---|
|
A DisplayMarker you want this decoration to follow. |
|
An Object representing the decoration e.g. |
|
Determines the behavior and appearance of this Decoration. Supported decoration types and their uses are listed above. |
|
This CSS class will be applied to the decorated line number, line, text spans, highlight regions, cursors, or overlay. |
|
An Object containing CSS style properties to apply to the relevant DOM node. Currently this only works with a |
|
optional
An HTMLElement or a model Object with a corresponding view registered. Only applicable to the |
|
optional
If |
|
optional
If |
|
optional
If |
|
optional
If |
|
optional
Only applicable to decorations of type |
|
optional
Only applicable to decorations of type |
|
optional
Only applicable to decorations of type |
Return values |
---|
Returns the created Decoration object. |
Add a decoration to every marker in the given marker layer. Can be used to decorate a large number of markers without having to create and manage many individual decorations.
Argument | Description |
---|---|
|
A DisplayMarkerLayer or MarkerLayer to decorate. |
|
The same parameters that are passed to TextEditor::decorateMarker, except the |
Return values |
---|
Returns a LayerDecoration. |
Get all decorations.
Argument | Description |
---|---|
|
optional
An Object containing key value pairs that the returned decorations’ properties must match. |
Return values |
---|
Returns an Array of Decorations. |
Get all decorations of type ‘line’.
Argument | Description |
---|---|
|
optional
An Object containing key value pairs that the returned decorations’ properties must match. |
Return values |
---|
Returns an Array of Decorations. |
Get all decorations of type ‘line-number’.
Argument | Description |
---|---|
|
optional
An Object containing key value pairs that the returned decorations’ properties must match. |
Return values |
---|
Returns an Array of Decorations. |
Get all decorations of type ‘highlight’.
Argument | Description |
---|---|
|
optional
An Object containing key value pairs that the returned decorations’ properties must match. |
Return values |
---|
Returns an Array of Decorations. |
Get all decorations of type ‘overlay’.
Argument | Description |
---|---|
|
optional
An Object containing key value pairs that the returned decorations’ properties must match. |
Return values |
---|
Returns an Array of Decorations. |
Create a marker on the default marker layer with the given range in buffer coordinates. This marker will maintain its logical location as the buffer is changed, so if you mark a particular word, the marker will remain over that word even if the word’s location in the buffer changes.
Argument | Description |
---|---|
|
|
|
A hash of key-value pairs to associate with the marker. There are also reserved property names that have marker-specific meaning. |
|
optional
Boolean Whether to store this marker’s range before and after each change in the undo history. This allows the marker’s position to be restored more accurately for certain undo/redo operations, but uses more time and memory. (default: false) |
|
optional
Boolean Creates the marker in a reversed orientation. (default: false) |
|
optional
String Determines the rules by which changes to the buffer invalidate the marker. (default: ‘overlap’) It can be any of the following strategies, in order of fragility:
|
Return values |
---|
Returns a DisplayMarker. |
Create a marker on the default marker layer with the given range in screen coordinates. This marker will maintain its logical location as the buffer is changed, so if you mark a particular word, the marker will remain over that word even if the word’s location in the buffer changes.
Argument | Description |
---|---|
|
|
|
A hash of key-value pairs to associate with the marker. There are also reserved property names that have marker-specific meaning. |
|
optional
Boolean Whether to store this marker’s range before and after each change in the undo history. This allows the marker’s position to be restored more accurately for certain undo/redo operations, but uses more time and memory. (default: false) |
|
optional
Boolean Creates the marker in a reversed orientation. (default: false) |
|
optional
String Determines the rules by which changes to the buffer invalidate the marker. (default: ‘overlap’) It can be any of the following strategies, in order of fragility:
|
Return values |
---|
Returns a DisplayMarker. |
Create a marker on the default marker layer with the given buffer position and no tail. To group multiple markers together in their own private layer, see ::addMarkerLayer.
Argument | Description |
---|---|
|
|
|
optional
An Object with the following keys: |
|
optional
String Determines the rules by which changes to the buffer invalidate the marker. (default: ‘overlap’) It can be any of the following strategies, in order of fragility:
|
Return values |
---|
Returns a DisplayMarker. |
Create a marker on the default marker layer with the given screen position and no tail. To group multiple markers together in their own private layer, see ::addMarkerLayer.
Argument | Description |
---|---|
|
|
|
optional
An Object with the following keys: |
|
optional
String Determines the rules by which changes to the buffer invalidate the marker. (default: ‘overlap’) It can be any of the following strategies, in order of fragility:
|
|
String If |
Return values |
---|
Returns a DisplayMarker. |
Find all DisplayMarkers on the default marker layer that match the given properties.
This method finds markers based on the given properties. Markers can be associated with custom properties that will be compared with basic equality. In addition, there are several special properties that will be compared with the range of the markers rather than their properties.
Argument | Description |
---|---|
|
An Object containing properties that each returned marker must satisfy. Markers can be associated with custom properties, which are compared with basic equality. In addition, several reserved properties can be used to filter markers based on their current range: |
|
Only include markers starting at this row in buffer coordinates. |
|
Only include markers ending at this row in buffer coordinates. |
|
Only include markers containing this Range or in range-compatible Array in buffer coordinates. |
|
Only include markers containing this Point or Array of |
Return values |
---|
Returns an Array of DisplayMarkers |
Create a marker layer to group related markers.
Argument | Description |
---|---|
|
An Object containing the following keys: |
|
A Boolean indicating whether marker state should be restored on undo/redo. Defaults to |
|
A Boolean indicating whether or not this marker layer should be serialized and deserialized along with the rest of the buffer. Defaults to |
Return values |
---|
Returns a DisplayMarkerLayer. |
Get a DisplayMarkerLayer by id.
Argument | Description |
---|---|
|
The id of the marker layer to retrieve. |
Return values |
---|
Returns a DisplayMarkerLayer or |
Get the default DisplayMarkerLayer.
All marker APIs not tied to an explicit layer interact with this default layer.
Return values |
---|
Returns a DisplayMarkerLayer. |
Get the DisplayMarker on the default layer for the given marker id.
Argument | Description |
---|---|
|
Number id of the marker |
Get all DisplayMarkers on the default marker layer. Consider using ::findMarkers
Get the position of the most recently added cursor in buffer coordinates.
Return values |
---|
Returns a Point |
Move the cursor to the given position in buffer coordinates.
If there are multiple cursors, they will be consolidated to a single cursor.
Argument | Description |
---|---|
|
|
|
optional
An Object containing the following keys: |
|
Determines whether the editor scrolls to the new cursor’s position. Defaults to true. |
Get the position of the most recently added cursor in screen coordinates.
Return values |
---|
Returns a Point. |
Move the cursor to the given position in screen coordinates.
If there are multiple cursors, they will be consolidated to a single cursor.
Argument | Description |
---|---|
|
|
|
optional
An Object combining options for ::clipScreenPosition with: |
|
Determines whether the editor scrolls to the new cursor’s position. Defaults to true. |
Move every cursor up one row in screen coordinates.
Argument | Description |
---|---|
|
optional
Number number of lines to move |
Move every cursor down one row in screen coordinates.
Argument | Description |
---|---|
|
optional
Number number of lines to move |
Move every cursor left one column.
Argument | Description |
---|---|
|
optional
Number number of columns to move (default: 1) |
Move every cursor right one column.
Argument | Description |
---|---|
|
optional
Number number of columns to move (default: 1) |
Move every cursor to the beginning of its line in buffer coordinates.
Move every cursor to the beginning of its line in screen coordinates.
Move every cursor to the first non-whitespace character of its line.
Move every cursor to the end of its line in buffer coordinates.
Move every cursor to the end of its line in screen coordinates.
Move every cursor to the beginning of its surrounding word.
Move every cursor to the end of its surrounding word.
Move every cursor to the top of the buffer.
If there are multiple cursors, they will be merged into a single cursor.
Move every cursor to the bottom of the buffer.
If there are multiple cursors, they will be merged into a single cursor.
Move every cursor to the beginning of the next word.
Move every cursor to the previous word boundary.
Move every cursor to the next word boundary.
Move every cursor to the previous subword boundary.
Move every cursor to the next subword boundary.
Move every cursor to the beginning of the next paragraph.
Move every cursor to the beginning of the previous paragraph.
Argument | Description |
---|---|
|
optional |
Return values |
---|
Returns the word surrounding the most recently added cursor. |
Get an Array of all Cursors.
Set the selected range in buffer coordinates. If there are multiple selections, they are reduced to a single selection with the given range.
Argument | Description |
---|---|
|
|
|
optional
An options Object: |
|
A Boolean indicating whether to create the selection in a reversed orientation. |
|
A Boolean, which if |
Set the selected ranges in buffer coordinates. If there are multiple selections, they are replaced by new selections with the given ranges.
Argument | Description |
---|---|
|
|
|
optional
An options Object: |
|
A Boolean indicating whether to create the selection in a reversed orientation. |
|
A Boolean, which if |
Add a selection for the given range in buffer coordinates.
Argument | Description |
---|---|
|
A Range |
|
optional
An options Object: |
|
A Boolean indicating whether to create the selection in a reversed orientation. |
|
A Boolean, which if |
Return values |
---|
Returns the added Selection. |
Add a selection for the given range in screen coordinates.
Argument | Description |
---|---|
|
A Range |
|
optional
An options Object: |
|
A Boolean indicating whether to create the selection in a reversed orientation. |
|
A Boolean, which if |
Select from the current cursor position to the given position in buffer coordinates.
This method may merge selections that end up intersecting.
Argument | Description |
---|---|
|
An instance of Point, with a given |
Select from the current cursor position to the given position in screen coordinates.
This method may merge selections that end up intersecting.
Argument | Description |
---|---|
|
An instance of Point, with a given |
Move the cursor of each selection one character upward while preserving the selection’s tail position.
This method may merge selections that end up intersecting.
Argument | Description |
---|---|
|
optional
Number number of rows to select (default: 1) |
Move the cursor of each selection one character downward while preserving the selection’s tail position.
This method may merge selections that end up intersecting.
Argument | Description |
---|---|
|
optional
Number number of rows to select (default: 1) |
Move the cursor of each selection one character leftward while preserving the selection’s tail position.
This method may merge selections that end up intersecting.
Argument | Description |
---|---|
|
optional
Number number of columns to select (default: 1) |
Move the cursor of each selection one character rightward while preserving the selection’s tail position.
This method may merge selections that end up intersecting.
Argument | Description |
---|---|
|
optional
Number number of columns to select (default: 1) |
Select from the top of the buffer to the end of the last selection in the buffer.
This method merges multiple selections into a single selection.
Selects from the top of the first selection in the buffer to the end of the buffer.
This method merges multiple selections into a single selection.
Select all text in the buffer.
This method merges multiple selections into a single selection.
Move the cursor of each selection to the beginning of its line while preserving the selection’s tail position.
This method may merge selections that end up intersecting.
Move the cursor of each selection to the first non-whitespace character of its line while preserving the selection’s tail position. If the cursor is already on the first character of the line, move it to the beginning of the line.
This method may merge selections that end up intersecting.
Move the cursor of each selection to the end of its line while preserving the selection’s tail position.
This method may merge selections that end up intersecting.
Expand selections to the beginning of their containing word.
Operates on all selections. Moves the cursor to the beginning of the containing word while preserving the selection’s tail position.
Expand selections to the end of their containing word.
Operates on all selections. Moves the cursor to the end of the containing word while preserving the selection’s tail position.
For each cursor, select the containing line.
This method merges selections on successive lines.
Select the word surrounding each cursor.
For each selection, move its cursor to the preceding subword boundary while maintaining the selection’s tail position.
This method may merge selections that end up intersecting.
For each selection, move its cursor to the next subword boundary while maintaining the selection’s tail position.
This method may merge selections that end up intersecting.
For each selection, move its cursor to the preceding word boundary while maintaining the selection’s tail position.
This method may merge selections that end up intersecting.
For each selection, move its cursor to the next word boundary while maintaining the selection’s tail position.
This method may merge selections that end up intersecting.
Expand selections to the beginning of the next word.
Operates on all selections. Moves the cursor to the beginning of the next word while preserving the selection’s tail position.
Expand selections to the beginning of the next paragraph.
Operates on all selections. Moves the cursor to the beginning of the next paragraph while preserving the selection’s tail position.
Expand selections to the beginning of the next paragraph.
Operates on all selections. Moves the cursor to the beginning of the next paragraph while preserving the selection’s tail position.
For each selection, select the syntax node that contains that selection.
Undo the effect a preceding call to ::selectLargerSyntaxNode.
Select the range of the given marker if it is valid.
Argument | Description |
---|---|
|
Return values |
---|
Returns the selected Range or |
Scan regular expression matches in the entire buffer, calling the given iterator function on each match.
::scan
functions as the replace method as well via the replace
If you’re programmatically modifying the results, you may want to try ::backwardsScanInBufferRange to avoid tripping over your own changes.
Argument | Description |
---|---|
|
A RegExp to search for. |
|
optional |
|
Number default |
|
Number default |
|
A Function that’s called on each match |
|
|
|
The current regular expression match. |
|
A String with the text of the match. |
|
The Range of the match. |
|
Call this Function to terminate the scan. |
|
Scan regular expression matches in a given range, calling the given iterator function on each match.
Argument | Description |
---|---|
|
A RegExp to search for. |
|
A Range in which to search. |
|
A Function that’s called on each match with an Object containing the following keys: |
|
The current regular expression match. |
|
A String with the text of the match. |
|
The Range of the match. |
|
Call this Function to terminate the scan. |
|
Scan regular expression matches in a given range in reverse order, calling the given iterator function on each match.
Argument | Description |
---|---|
|
A RegExp to search for. |
|
A Range in which to search. |
|
A Function that’s called on each match with an Object containing the following keys: |
|
The current regular expression match. |
|
A String with the text of the match. |
|
The Range of the match. |
|
Call this Function to terminate the scan. |
|
Toggle soft tabs for this editor
Determine if the buffer uses hard or soft tabs.
Return values |
---|
Returns |
Returns |
Returns a Boolean or undefined if no non-comment lines had leading whitespace. |
Get the text representing a single level of indent.
If soft tabs are enabled, the text is composed of N spaces, where N is the
tab length. Otherwise the text is a tab character (\t
).
Return values |
---|
Returns a String. |
Gets the column at which column will soft wrap
Get the indentation level of the given buffer row.
Determines how deeply the given row is indented based on the soft tabs and tab length settings of this editor. Note that if soft tabs are enabled and the tab length is 2, a row with 4 leading spaces would have an indentation level of 2.
Argument | Description |
---|---|
|
A Number indicating the buffer row. |
Return values |
---|
Returns a Number. |
Set the indentation level for the given buffer row.
Inserts or removes hard tabs or spaces based on the soft tabs and tab length settings of this editor in order to bring it to the given indentation level. Note that if soft tabs are enabled and the tab length is 2, a row with 4 leading spaces would have an indentation level of 2.
Argument | Description |
---|---|
|
A Number indicating the buffer row. |
|
A Number indicating the new indentation level. |
|
optional
An Object with the following keys: |
|
|
Get the indentation level of the given line of text.
Determines how deeply the given line is indented based on the soft tabs and tab length settings of this editor. Note that if soft tabs are enabled and the tab length is 2, a row with 4 leading spaces would have an indentation level of 2.
Argument | Description |
---|---|
|
A String representing a line of text. |
Return values |
---|
Returns a Number. |
Get the current Grammar of this editor.
Return values |
---|
Returns a ScopeDescriptor that includes this editor’s language.
e.g. |
Get the syntactic ScopeDescriptor for the given position in buffer coordinates. Useful with Config::get.
For example, if called with a position inside the parameter list of an
anonymous CoffeeScript function, this method returns a ScopeDescriptor with
the following scopes array:
["source.coffee", "meta.function.inline.coffee", "meta.parameters.coffee", "variable.parameter.function.coffee"]
Argument | Description |
---|---|
|
Return values |
---|
Returns a ScopeDescriptor. |
Get the syntactic tree ScopeDescriptor for the given position in buffer coordinates or the syntactic ScopeDescriptor for TextMate language mode
For example, if called with a position inside the parameter list of a
JavaScript class function, this method returns a ScopeDescriptor with
the following syntax nodes array:
["source.js", "program", "expression_statement", "assignment_expression", "class", "class_body", "method_definition", "formal_parameters", "identifier"]
if tree-sitter is used
and the following scopes array:
["source.js"]
if textmate is used
Argument | Description |
---|---|
|
Return values |
---|
Returns a ScopeDescriptor. |
Get the range in buffer coordinates of all tokens surrounding the cursor that match the given scope selector.
For example, if you wanted to find the string surrounding the cursor, you
could call editor.bufferRangeForScopeAtCursor(".string.quoted")
.
Argument | Description |
---|---|
|
String selector. e.g. |
Return values |
---|
Returns a Range. |
Get the range in buffer coordinates of all tokens surrounding the given position in buffer coordinates that match the given scope selector.
For example, if you wanted to find the string surrounding the cursor, you
could call editor.bufferRangeForScopeAtPosition(".string.quoted", this.getCursorBufferPosition())
.
Argument | Description |
---|---|
|
String selector. e.g. |
|
Return values |
---|
Returns a Range. |
Determine if the given row is entirely a comment
For each selection, copy the selected text.
For each selection, replace the selected text with the contents of the clipboard.
If the clipboard contains the same number of selections as the current editor, each selection will be replaced with the content of the corresponding clipboard selection text.
Argument | Description |
---|---|
|
optional |
Fold the most recent cursor’s row based on its indentation level.
The fold will extend from the nearest preceding line with a lower indentation level up to the nearest following row with a lower indentation level.
Unfold the most recent cursor’s row by one level.
Fold the given row in buffer coordinates based on its indentation level.
If the given row is foldable, the fold will begin there. Otherwise, it will begin at the first foldable row preceding the given row.
Argument | Description |
---|---|
|
A Number. |
Unfold all folds containing the given row in buffer coordinates.
Argument | Description |
---|---|
|
A Number |
For each selection, fold the rows it intersects.
Fold all foldable lines.
Unfold all existing folds.
Fold all foldable lines at the given indent level.
Argument | Description |
---|---|
|
A Number starting at 0. |
Fold the given buffer row if it isn’t currently folded, and unfold it otherwise.
Add a custom Gutter.
Argument | Description |
---|---|
|
An Object with the following fields: |
|
(required) A unique String to identify this gutter. |
|
optional
A Number that determines stacking order between gutters. Lower priority items are forced closer to the edges of the window. (default: -100) |
|
optional
Boolean specifying whether the gutter is visible initially after being created. (default: true) |
|
optional
String specifying the type of gutter to create. |
|
optional
String added to the CSS classnames of the gutter’s root DOM element. |
|
optional
Function called by a |
|
an Object containing information about each line to label. |
|
Number indicating the zero-indexed buffer index of this line. |
|
Number indicating the zero-indexed screen index. |
|
Boolean that is |
|
Boolean if this screen row is the soft-wrapped continuation of the same buffer row. |
|
Number the maximum number of digits necessary to represent any known screen row. |
|
optional
Function to be called when a mousedown event is received by a line-number element within this |
|
an Object containing information about the line that’s being clicked. |
|
Number of the originating line element |
|
|
|
optional
Function to be called when a mousemove event occurs on a line-number element within within this |
|
an Object containing information about the line that’s being clicked. |
|
Number of the originating line element |
|
Return values |
---|
Returns the newly-created Gutter. |
Get the gutter with the given name.
Return values |
---|
Returns a Gutter, or |
Scroll the editor to reveal the most recently added cursor if it is off-screen.
Argument | Description |
---|---|
|
optional |
|
Center the editor around the cursor if possible. (default: true) |
Set the greyed out placeholder of a mini editor. Placeholder text will be displayed when the editor has no content.
Argument | Description |
---|---|
|
String text that is displayed when the editor has no content. |