edit

package
v1.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package edit holds visual columns, text boundaries, cursors, cursor movement and the editing commands (SPEC §6.2, §7.2).

Index

Constants

View Source
const DefaultPageRows = 20

DefaultPageRows is the page size of a ModelLineLayout that has none.

View Source
const DefaultWordSeparators = "`~!@#$%^&*()-=+[{]}\\|;:'\",.<>/?"

DefaultWordSeparators is VS Code's default for editor.wordSeparators.

Variables

This section is empty.

Functions

func ColumnFromVisible

func ColumnFromVisible(line string, visible, tabSize int) int

ColumnFromVisible is the byte column in line nearest to a visual column (VS Code's CursorColumns.columnFromVisibleColumn): a visual column inside a tab or a wide character goes to the nearer end of it, and to the one before when both are as near. A visual column at or before 0 gives 0; one past the end of the line gives len(line).

func GraphemeBoundaries

func GraphemeBoundaries(s string) []int

GraphemeBoundaries returns the byte offsets where the grapheme clusters of s start, then len(s). An empty string gives [0].

func JumpToBracket

func JumpToBracket(bm BracketModel, sels []buffer.Selection) []buffer.Selection

JumpToBracket is Go to Bracket (Ctrl+Shift+\): each cursor goes to the bracket that matches the one at the start of its selection, or else to the closing bracket of the pair around it, or else to the next bracket. A selection that finds none becomes a cursor where it started.

Ported from VS Code: src/vs/editor/contrib/bracketMatching/browser/bracketMatching.ts (jumpToBracket)

func NextGrapheme

func NextGrapheme(line string, col int) int

NextGrapheme returns the byte column of the first grapheme boundary after col, or len(line) when there is none. A column before the start counts as the start. In a line longer than 4 KiB only the 1 KiB around col is looked at, so a cluster of more than that is cut.

func NextIndentTabStop

func NextIndentTabStop(visible, indentSize int) int

NextIndentTabStop is the first indent stop after a visual column; it is NextRenderTabStop with the indent size.

func NextRenderTabStop

func NextRenderTabStop(visible, tabSize int) int

NextRenderTabStop is the first tab stop after a visual column.

func NextWordPart

func NextWordPart(line string, col int) int

NextWordPart returns the byte column of the end of the word part after col in line (_moveWordPartRight inside a line), or len(line) when there is no boundary after col, and then the caller moves to the next line.

func NormalizeIndentation

func NormalizeIndentation(str string, indentSize int, insertSpaces bool) string

NormalizeIndentation rewrites the leading white space of str so that it uses tabs (up to the indent size) or only spaces, keeping its visual width. It is VS Code's normalizeIndentation.

Ported from VS Code: src/vs/editor/common/core/misc/indentation.ts

func PrevGrapheme

func PrevGrapheme(line string, col int) int

PrevGrapheme returns the byte column of the last grapheme boundary before col, or 0 when there is none. A column after the end counts as the end. Long lines are treated as NextGrapheme does.

func PrevIndentTabStop

func PrevIndentTabStop(visible, indentSize int) int

PrevIndentTabStop is the last indent stop before a visual column; it is PrevRenderTabStop with the indent size.

func PrevRenderTabStop

func PrevRenderTabStop(visible, tabSize int) int

PrevRenderTabStop is the last tab stop before a visual column, or 0.

func PrevWordPart

func PrevWordPart(line string, col int) int

PrevWordPart returns the byte column of the start of the word part before col in line: parts of snake_case, kebab-case, camelCase and runs of capitals are split as VS Code's word-part navigation does (_moveWordPartLeft, the part that works inside a line). It returns 0 when there is no boundary before col, and then the caller moves to the previous line.

func ProvideSelectionRanges

func ProvideSelectionRanges(m Model, opts Options, positions []buffer.Position, ropts SelectionRangesOptions, providers ...SelectionRangeProvider) [][]buffer.Range

ProvideSelectionRanges collects the ranges of the providers around each position, and the ones of the word provider, which is always used. For each position it returns the ranges from the smallest to the largest, each containing the one before and different from it; with SelectLeadingAndTrailingWhitespace, the lines of a range that wraps onto other lines are added without and with their white space.

Ported from VS Code: src/vs/editor/contrib/smartSelect/browser/smartSelect.ts (provideSelectionRanges).

func RangeSelection

func RangeSelection(initial buffer.Range, p buffer.Position) buffer.Selection

RangeSelection is the selection from an initial range to a position, as VS Code's SingleCursorState computes it: the anchor is the start of the range, or its end when the position is before its start.

Ported from VS Code: src/vs/editor/common/cursorCommon.ts (SingleCursorState._computeSelection)

func SelectToBracket

func SelectToBracket(bm BracketModel, sels []buffer.Selection, selectBrackets bool) ([]buffer.Selection, bool)

SelectToBracket is Select to Bracket: each selection becomes the text between the brackets of the pair at its start, around it, or the next one, with the brackets when selectBrackets is true and backwards when the cursor was on the closing bracket. A selection that finds no pair is dropped; it reports false when none found one.

Ported from VS Code: bracketMatching.ts (selectToBracket)

func SnippetPairs added in v1.0.0

func SnippetPairs(l *autoclose.Language, texts []string) ([][2]int, bool)

SnippetPairs finds, in the text of each edit of an inserted snippet, the pair that its end closes: the last closing character of the text (nothing but other characters after it) and the nearest opening character of its pair before it. It gives, for each text, the byte index of the opening and of the closing character. It reports false when any text has no such pair, has more than one line, or is empty, or when the closing character is that of none or of several pairs of single characters: the snippet then has no pair for the editor to type over (VS Code's `_findAutoClosingPairs`, for the edits of the source "snippet").

Ported from VS Code: src/vs/editor/common/cursor/cursor.ts (_findAutoClosingPairs). One difference: for a closing character at the very start of the text VS Code's lastIndexOf with a negative index finds the opening there when it is the same character (a quote); here there is no pair.

func StatusbarColumn

func StatusbarColumn(line string, col, tabSize int) int

StatusbarColumn is the number the status bar shows as "Col" for the byte column col in line (VS Code's CursorColumns.toStatusbarColumn): every code point counts 1 and a tab goes to the next tab stop, then one is added. Unlike VisibleColumn it does not make wide characters and emoji count 2.

func VisibleColumn

func VisibleColumn(line string, col, tabSize int) int

VisibleColumn is the visual column of the byte column col in line (SPEC §6.2, VS Code's CursorColumns.visibleColumnFromColumn): walk the grapheme clusters before col; for each take its first code point: a tab goes to the next tab stop, a full-width character or an emoji counts 2, anything else 1. A col outside the line is moved into it.

Types

type AutoClosed

type AutoClosed struct {
	// Character is where the closing text is.
	Character buffer.Range
	// Enclosing is the typed opening character and the closing text; the cursor must stay inside
	// it for the closing text to count as auto-closed.
	Enclosing buffer.Range
}

AutoClosed is a closing character that the editor typed for the user, such as the ")" after a typed "(": typing the closing character over it, or Backspace after the opening one, takes it away again (SPEC §8.6.4).

func SnippetAutoClosed added in v1.0.0

func SnippetAutoClosed(snap buffer.Snapshot, l *autoclose.Language, texts []string, starts []int) []AutoClosed

SnippetAutoClosed makes the AutoClosed values of the pairs that SnippetPairs found: starts are the offsets in the document where the texts are now, and snap is the document after the insertion. The tracker then lets the user type over the closing characters of the snippet as over those the editor typed.

type AutoClosedTracker

type AutoClosedTracker struct {
	// contains filtered or unexported fields
}

AutoClosedTracker keeps the closing characters that the editor typed (Result.AutoClosed) as decorations of a document, so that they move with the text, and drops them once the cursors leave the pair (SPEC §8.6.4). Overtyping and deleting them read Characters.

Ported from VS Code: src/vs/editor/common/cursor/cursor.ts (AutoClosedAction)

func NewAutoClosedTracker

func NewAutoClosedTracker(doc *document.Document, owner int) *AutoClosedTracker

NewAutoClosedTracker makes a tracker whose decorations belong to owner (1 or more).

func (*AutoClosedTracker) Add

func (t *AutoClosedTracker) Add(closed []AutoClosed)

Add starts tracking what a result typed. The cursors must have been set to the selections of the result before: they are not tested until they change.

func (*AutoClosedTracker) Characters

func (t *AutoClosedTracker) Characters() []buffer.Range

Characters are the ranges of the tracked closing characters now.

func (*AutoClosedTracker) Clear

func (t *AutoClosedTracker) Clear()

Clear stops tracking everything.

func (*AutoClosedTracker) Validate

func (t *AutoClosedTracker) Validate(sels []buffer.Selection)

Validate stops tracking the pairs that the selections are not inside of any more: every selection must be strictly inside a pair of the action, and no pair may have become several lines long.

type BracketModel

type BracketModel interface {
	BracketNavigator
	// Match gives the two brackets of the pair the position is at.
	Match(pos buffer.Position) (open, closing buffer.Range, ok bool)
	// Enclosing gives the brackets of the innermost closed pair around the position.
	Enclosing(pos buffer.Position) (open, closing buffer.Range, ok bool)
}

BracketModel is what the bracket commands ask of the bracket structure of a document (a *brackets.Index is one).

type BracketNavigator

type BracketNavigator interface {
	// Next is the first bracket that ends after the position.
	Next(pos buffer.Position) (brackets.Found, bool)
	// Prev is the last bracket that starts before the position.
	Prev(pos buffer.Position) (brackets.Found, bool)
}

BracketNavigator finds the brackets next to a position (a *brackets.Index is one).

type Case

type Case int

Case is a change of case.

const (
	// CaseUpper turns text into upper case.
	CaseUpper Case = iota
	// CaseLower turns text into lower case.
	CaseLower
	// CaseTitle makes the first letter of each word upper case and the others lower case.
	CaseTitle
)

type CharClass

type CharClass int

CharClass is what a character is to word navigation (VS Code's WordCharacterClass).

const (
	// ClassRegular is any character that is not a separator or white space.
	ClassRegular CharClass = iota
	// ClassWhitespace is a space or a tab.
	ClassWhitespace
	// ClassSeparator is a character of editor.wordSeparators.
	ClassSeparator
)

type ColumnSelectData

type ColumnSelectData struct {
	// FromLine and FromVisual are where the selection started: a line (from 0) and a
	// visual column (from 0).
	FromLine, FromVisual int
	// ToLine and ToVisual are the other corner.
	ToLine, ToVisual int
}

ColumnSelectData is where a column selection started and where it ends. Columns are visual columns (a tab goes to the next tab stop), so the rectangle they make is the one the eyes see, also over lines shorter than it.

type ColumnSelection

type ColumnSelection struct {
	// Cursors have the selected part of each line, from the starting line on; the first
	// is the primary cursor.
	Cursors []Cursor
	// Data is the rectangle, to give back to extend the selection.
	Data ColumnSelectData
	// Reversed is true when the selection goes from a line up to a lower one.
	Reversed bool
}

ColumnSelection is the cursors of a column selection, one per line that reaches the rectangle, and the data to go on with it.

type Commands

type Commands struct {
	// Model is the text the commands read.
	Model Model
	// Options are the settings they read.
	Options Options
	// contains filtered or unexported fields
}

Commands are the editing commands: each reads a text and the selections of the cursors and returns a Result, without changing anything (SPEC §7.2).

func NewCommands

func NewCommands(m Model, o Options) Commands

NewCommands makes the commands of a text.

func (Commands) AddLineComment

func (c Commands) AddLineComment(sels []buffer.Selection) Result

AddLineComment is Add Line Comment: every line the selections touch gets a line comment.

func (Commands) AddNextOccurrence

func (c Commands) AddNextOccurrence(sess *OccurrenceSession, sels []buffer.Selection, find SearchOptions) (*OccurrenceSession, []buffer.Selection, bool)

AddNextOccurrence is Ctrl+D. Without a session it starts one, except when there are several selections that do not hold the same text: then it only selects the word at each empty cursor. It returns the session to keep (nil if none), the new selections, and false when nothing changes.

Ported from VS Code: multicursor.ts (MultiCursorSelectionController.addSelectionToNextFindMatch).

func (Commands) AddPreviousOccurrence

func (c Commands) AddPreviousOccurrence(sess *OccurrenceSession, sels []buffer.Selection, find SearchOptions) (*OccurrenceSession, []buffer.Selection, bool)

AddPreviousOccurrence adds the previous occurrence, starting a session if needed.

func (Commands) AutoIndentPaste

func (c Commands) AutoIndentPaste(sel buffer.Selection, r buffer.Range) Result

AutoIndentPaste fits the text just pasted into range r to the indentation around it (editor.autoIndentOnPaste). sel is the selection after the paste. It works for one selection only, and not at all below the level "full".

Ported from VS Code: contrib/indentation/browser/indentation.ts (AutoIndentOnPaste)

func (Commands) CompositionType

func (c Commands) CompositionType(sels []buffer.Selection, text string, replacePrev, replaceNext, positionDelta int) Result

CompositionType is what an input method does while it composes: at each cursor with an empty selection it replaces the replacePrev characters before the cursor and the replaceNext after it by text, and puts the cursor positionDelta characters after the end of the text (negative to put it before). Characters are code points; a cursor with a selection is left alone.

Ported from VS Code: cursorTypeEditOperations.ts (CompositionOperation)

func (Commands) ConvertIndentation

func (c Commands) ConvertIndentation(sel buffer.Selection, toSpaces bool) Result

ConvertIndentation is Convert Indentation to Spaces (toSpaces) and to Tabs: in the indentation of every line, which is all of a line that has only white space, each tab becomes as many spaces as the tab size, or each run of as many spaces as the tab size becomes a tab. The selection is moved along with the text; the other cursors are not part of the command, as in VS Code, which works on the primary selection only.

Ported from VS Code: src/vs/editor/contrib/indentation/browser/indentation.ts (IndentationToSpacesCommand, IndentationToTabsCommand, getIndentationEditOperations)

func (Commands) Copy

func (c Commands) Copy(sels []buffer.Selection, emptySelectionClipboard bool) CopyData

Copy gets the text to copy for the selections. With emptySelectionClipboard a cursor with no selection copies its line (with the line break), once for the cursors on the same line, and a copy of nothing but empty selections without it copies nothing: Text is empty and Pieces nil.

Ported from VS Code: src/vs/editor/common/viewModel/viewModelImpl.ts (getPlainTextToCopy) and src/vs/editor/browser/controller/editContext/clipboardUtils.ts (getDataToCopy)

func (Commands) CopyLines

func (c Commands) CopyLines(sels []buffer.Selection, down bool) Result

CopyLines copies the lines the selections touch above or below themselves (Shift+Alt+Up, Shift+Alt+Down); the selection ends on the copy below, or stays on the upper block when copying up. Selections that would copy the same line copy it once. The selections of the result are in the order of the text.

Ported from VS Code: copyLinesCommand.ts and AbstractCopyLinesAction.

func (Commands) CursorsAtLineEnds

func (c Commands) CursorsAtLineEnds(sels []buffer.Selection) []buffer.Selection

CursorsAtLineEnds puts a cursor at the end of each line of each selection that is not empty (Shift+Alt+I): at the end of every line but the last, and at the end of the selection when that is not at the start of a line. It returns nil when no selection has lines to end.

Ported from VS Code: multicursor.ts (InsertCursorAtEndOfEachLineSelected).

func (Commands) CursorsToBottom

func (c Commands) CursorsToBottom(sels []buffer.Selection) []buffer.Selection

CursorsToBottom adds a cursor with the first selection's columns on every line from its first line to the last one (multicursor.ts, addCursorsToBottom).

func (Commands) CursorsToTop

func (c Commands) CursorsToTop(sels []buffer.Selection) []buffer.Selection

CursorsToTop adds a cursor with the first selection's columns on every line from its first line to the first one (multicursor.ts, addCursorsToTop).

func (Commands) Cut

func (c Commands) Cut(sels []buffer.Selection, emptySelectionClipboard bool) Result

Cut deletes what Copy copies: the selections, and the line of a cursor with no selection when emptySelectionClipboard is set (with its line break; the last line takes the break before it). Cursors with no selection do nothing without it.

Ported from VS Code: src/vs/editor/common/cursor/cursorDeleteOperations.ts (DeleteOperations.cut)

func (Commands) DeleteInsideWord

func (c Commands) DeleteInsideWord(sels []buffer.Selection, onlyWord bool) Result

DeleteInsideWord deletes the word at the cursor with the blanks on one side of it (the blanks around the cursor when it is in white space), and the line break of an empty line. With onlyWord it leaves the blanks.

Ported from VS Code: cursorWordOperations.ts (WordOperations.deleteInsideWord)

func (Commands) DeleteLeft

func (c Commands) DeleteLeft(sels []buffer.Selection) Result

DeleteLeft is Backspace at every cursor.

A cursor between an opening character and the closing one the editor typed for it, such as "(|)", deletes both (editor.autoClosingDelete).

func (Commands) DeleteLines

func (c Commands) DeleteLines(sels []buffer.Selection) Result

DeleteLines deletes the lines the selections touch (Ctrl+Shift+K), the lines of cursors that touch or overlap once. The cursor of a deleted line goes to the line that takes its place, in the same column when it can. The selections of the result are in the order of the text. An empty text has nothing to delete.

Ported from VS Code: linesOperations.ts (DeleteLinesAction).

func (Commands) DeleteRight

func (c Commands) DeleteRight(sels []buffer.Selection) Result

DeleteRight is the Delete key at every cursor.

func (Commands) DeleteWordEndLeft

func (c Commands) DeleteWordEndLeft(sels []buffer.Selection) Result

DeleteWordEndLeft deletes back to the end of the previous word (deleteWordEndLeft).

func (Commands) DeleteWordEndRight

func (c Commands) DeleteWordEndRight(sels []buffer.Selection) Result

DeleteWordEndRight deletes to the end of the word (deleteWordEndRight).

func (Commands) DeleteWordLeft

func (c Commands) DeleteWordLeft(sels []buffer.Selection) Result

DeleteWordLeft is Ctrl+Backspace: it deletes back to the start of the word, or back over white space when there are two or more blanks before the cursor.

func (Commands) DeleteWordPartLeft

func (c Commands) DeleteWordPartLeft(sels []buffer.Selection) Result

DeleteWordPartLeft deletes back to the nearest of the word start, the word end and the start of the part (camelCase, snake_case, kebab-case).

Ported from VS Code: cursorWordOperations.ts (WordPartOperations.deleteWordPartLeft)

func (Commands) DeleteWordPartRight

func (c Commands) DeleteWordPartRight(sels []buffer.Selection) Result

DeleteWordPartRight deletes to the nearest of the word start, the word end and the end of the part.

func (Commands) DeleteWordRight

func (c Commands) DeleteWordRight(sels []buffer.Selection) Result

DeleteWordRight is Ctrl+Delete: it deletes to the end of the word, or the white space after the cursor.

func (Commands) DeleteWordStartLeft

func (c Commands) DeleteWordStartLeft(sels []buffer.Selection) Result

DeleteWordStartLeft deletes back to the start of the word, without the white space rule (deleteWordStartLeft).

func (Commands) DeleteWordStartRight

func (c Commands) DeleteWordStartRight(sels []buffer.Selection) Result

DeleteWordStartRight deletes to the start of the next word (deleteWordStartRight).

func (Commands) DragAndDrop

func (c Commands) DragAndDrop(sel buffer.Selection, target buffer.Position, copy bool) Result

DragAndDrop moves the text of a selection to a position, or copies it there, and selects the text at its new place (dragging selected text with the mouse). Dropping inside the selection changes nothing, except that with copy a drop at one of its ends puts a copy next to it. The result has the selection to put the cursor on.

Ported from VS Code: src/vs/editor/contrib/dnd/browser/dragAndDropCommand.ts

func (Commands) Indent

func (c Commands) Indent(sels []buffer.Selection) Result

Indent indents the lines the selections touch by one level (Ctrl+]).

func (Commands) InsertLineAfter

func (c Commands) InsertLineAfter(sels []buffer.Selection) Result

InsertLineAfter inserts a line below the line of each cursor, with the indentation of that line, and moves the cursor to it (Ctrl+Enter).

func (Commands) InsertLineBefore

func (c Commands) InsertLineBefore(sels []buffer.Selection) Result

InsertLineBefore inserts a line above the line of each cursor, with the indentation of the line above, and moves the cursor to it (Ctrl+Shift+Enter).

Ported from VS Code: cursorTypeEditOperations.ts (EnterOperation.lineInsertBefore).

func (Commands) JoinLines

func (c Commands) JoinLines(sels []buffer.Selection) Result

JoinLines joins each selected line with the next one (the lines of a selection into one), replacing the white space that separates them by one space. The selections of the result have the primary one first, then the others in the order of the text; a cursor on a line with nothing to join to is left out.

Ported from VS Code: linesOperations.ts (JoinLinesAction).

func (Commands) LineBreakInsert

func (c Commands) LineBreakInsert(sels []buffer.Selection) Result

LineBreakInsert is Insert Line Break (Ctrl+O): it breaks the line at every cursor as NewLine does, but the cursor stays before the line break.

func (Commands) MoveLines

func (c Commands) MoveLines(sels []buffer.Selection, down bool) Result

MoveLines moves the lines the selections touch one line up or down (Alt+Up, Alt+Down). The selections move with the text. Moving the first line up or the last line down does nothing. An empty line swaps its place with the line next to it and the cursor goes to that line.

Ported from VS Code: src/vs/editor/contrib/linesOperations/browser/moveLinesCommand.ts, without the re-indentation by language rules (the language steps add it).

func (Commands) MoveToNextOccurrence

func (c Commands) MoveToNextOccurrence(sess *OccurrenceSession, sels []buffer.Selection, find SearchOptions) (*OccurrenceSession, []buffer.Selection, bool)

MoveToNextOccurrence moves the last selection to the next occurrence, starting a session if needed.

func (Commands) MoveToPreviousOccurrence

func (c Commands) MoveToPreviousOccurrence(sess *OccurrenceSession, sels []buffer.Selection, find SearchOptions) (*OccurrenceSession, []buffer.Selection, bool)

MoveToPreviousOccurrence moves the last selection to the previous occurrence.

func (Commands) NewExpansion

func (c Commands) NewExpansion(sels []buffer.Selection, ropts SelectionRangesOptions, providers ...SelectionRangeProvider) *Expansion

NewExpansion finds the ranges around the active end of each selection. It returns nil when there are none.

func (Commands) NewLine

func (c Commands) NewLine(sels []buffer.Selection) Result

NewLine breaks the line at every cursor, replacing its selection, and starts the new line with the indentation that editor.autoIndent gives (Options.AutoIndent): none, that of the line before the cursor, or what the brackets, the on-enter rules and the indentation rules of the language say (SPEC §8.6.2).

Ported from VS Code: cursorTypeEditOperations.ts (EnterOperation)

func (Commands) Occurrences

func (c Commands) Occurrences(q OccurrenceQuery) []buffer.Range

Occurrences are the matches of a query in the document, in order and without overlapping.

func (Commands) OccurrencesApartFrom

func (c Commands) OccurrencesApartFrom(q OccurrenceQuery, sels []buffer.Selection) []buffer.Range

OccurrencesApartFrom are the matches of a query that are not the selections and do not overlap a selection that has text: the highlight of the text that equals the selection leaves the selection itself alone.

Ported from VS Code: multicursor.ts (SelectionHighlighter._setState)

func (Commands) Outdent

func (c Commands) Outdent(sels []buffer.Selection) Result

Outdent takes one level of indentation off the lines the selections touch (Shift+Tab, Ctrl+[).

func (Commands) Paste

func (c Commands) Paste(sels []buffer.Selection, text string, opts PasteOptions) Result

Paste puts a text at the selections, replacing them. With several cursors, the pieces of a copy by as many cursors go to the cursors from the top; so does, with Spread, a text that has as many lines as there are cursors. A block copied from a column selection into one cursor goes down the lines. Otherwise every cursor gets the whole text. The edit is an undo step of its own.

Ported from VS Code: src/vs/editor/common/cursor/cursorTypeEditOperations.ts (PasteOperation)

func (Commands) Reindent

func (c Commands) Reindent(sels []buffer.Selection, first, last int) Result

Reindent is Reindent Lines: the lines first to last (zero-based, both included) get the indentation the rules of the language want, taking the first line as it is. The cursors follow the text.

Ported from VS Code: src/vs/editor/contrib/indentation/browser/indentation.ts (ReindentLinesAction, ReindentSelectedLinesAction)

func (Commands) ReindentSelected

func (c Commands) ReindentSelected(sels []buffer.Selection) Result

ReindentSelected is Reindent Selected Lines: the lines of each selection are reindented with the line above the first one as the base, and the last line of a selection that ends at the start of a line is left out.

func (Commands) RemoveBrackets

func (c Commands) RemoveBrackets(bm BracketModel, sels []buffer.Selection) Result

RemoveBrackets is Remove Brackets: the two brackets of the pair at each cursor (or around it) are deleted.

Ported from VS Code: bracketMatching.ts (removeBrackets)

func (Commands) RemoveLineComment

func (c Commands) RemoveLineComment(sels []buffer.Selection) Result

RemoveLineComment is Remove Line Comment: the line comments of the lines the selections touch are taken off.

func (Commands) SaveParticipants

func (c Commands) SaveParticipants(sels []buffer.Selection, p SaveParticipants, autoSave bool) Result

SaveParticipants is what a save does to the text before it is written, as VS Code's TrimWhitespaceParticipant, FinalNewLineParticipant and TrimFinalNewLinesParticipant do one after the other: trailing white space is trimmed from every line (strings and regular expressions included), a final line break is added when the last line has text (the buffer holds "\n"; the file's line ending is written when it is saved), and the empty lines after the final line break are removed. VS Code applies them as three edits; this makes the result of the three as one batch, which is one step of the undo history.

With autoSave (files.autoSave, SaveReason.AUTO) the white space in front of a cursor stays, so that the cursor does not jump while the user types, and no line up to the one of the cursor furthest down is removed. The selections of the result are the selections given, kept inside the text that is left.

Not built: files.trimTrailingWhitespaceInRegexAndStrings (it is always on, which is its default) and the lines of a snippet session.

Ported from VS Code: src/vs/workbench/contrib/codeEditor/browser/saveParticipants.ts

func (Commands) SelectAllOccurrences

func (c Commands) SelectAllOccurrences(sess *OccurrenceSession, sels []buffer.Selection, find SearchOptions, scope []buffer.Range) (*OccurrenceSession, []buffer.Selection)

SelectAllOccurrences is Ctrl+Shift+L: it starts a session if needed and selects every occurrence of what the primary selection (or the word at it) holds.

func (Commands) SelectionQuery

SelectionQuery is what the selection highlight looks for: the text of the selection, with the switches of the find widget. It says no (false) when the selections have no text, when a selection spans lines and Multiline is off, when several selections hold different texts (compared without case unless the find options match case), when the text is only spaces and tabs, and when it is longer than MaxLength. A cursor with no selection highlights nothing: the word at it is the business of WordOccurrences.

Ported from VS Code: multicursor.ts (SelectionHighlighter._createState)

func (Commands) SortLines

func (c Commands) SortLines(sels []buffer.Selection, descending bool) Result

SortLines sorts the lines the selections touch, in the order of the locale (Intl.Collator in VS Code), ascending or descending. A single selection inside one line sorts the whole text. When any selection has nothing to sort (fewer than two lines, or already in order), nothing changes. Selections keep the offsets they had in the sorted text.

Ported from VS Code: sortLinesCommand.ts and AbstractSortLinesAction.

func (Commands) StartOccurrences

func (c Commands) StartOccurrences(sels []buffer.Selection, find SearchOptions) *OccurrenceSession

StartOccurrences begins a session for the primary selection, which is the first one. It returns nil when there is nothing to search for (an empty selection that is not in a word).

func (Commands) Tab

func (c Commands) Tab(sels []buffer.Selection) Result

Tab is the Tab key. A cursor on a line of white space only goes to the indentation of a new level (replacing the white space when the line does not start with it); any other cursor, and a selection inside a line, is replaced by spaces up to the next indent stop (or one tab); a selection of whole lines, or of several, indents those lines.

Ported from VS Code: cursorTypeEditOperations.ts (TabOperation). On a line of white space only, the indentation is the one the rules of the language suggest, or one level.

func (Commands) ToggleBlockComment

func (c Commands) ToggleBlockComment(sels []buffer.Selection) Result

ToggleBlockComment is Toggle Block Comment (Ctrl+Shift+A): each selection is wrapped in a block comment, or, when it is in one, the comment is taken off.

Ported from VS Code: comment.ts (BlockCommentAction)

func (Commands) ToggleLineComment

func (c Commands) ToggleLineComment(sels []buffer.Selection) Result

ToggleLineComment is Toggle Line Comment (Ctrl+/): the lines the selections touch get a line comment, or lose theirs when they all have one. A language with no line comment uses its block comment (SPEC §8.6.5).

Ported from VS Code: src/vs/editor/contrib/comment/browser/comment.ts (CommentLineAction)

func (Commands) TransformCase

func (c Commands) TransformCase(sels []buffer.Selection, kind Case) Result

TransformCase changes the case of the selected text, or of the word at an empty cursor (Transform to Uppercase, Lowercase, Title Case). The selections keep their start and end around the changed text.

Ported from VS Code: linesOperations.ts (AbstractCaseAction and its subclasses).

func (Commands) Transpose

func (c Commands) Transpose(sels []buffer.Selection) Result

Transpose swaps the characters before and after each empty cursor (Ctrl+T on macOS, unbound on Linux): at the end of a line it swaps the last character and the line break. The cursor goes after the swapped pair. Cursors with a selection, and at the end of the text, are left alone.

Ported from VS Code: linesOperations.ts (TransposeAction).

func (Commands) TrimTrailingWhitespace

func (c Commands) TrimTrailingWhitespace(sels []buffer.Selection, keepCursors bool) Result

TrimTrailingWhitespace deletes the spaces and tabs at the end of every line of the text. With keepCursors, the white space a cursor is in front of, on its line, stays (as when a file is trimmed while it is being typed in). Strings and regular expressions are trimmed too, as with files.trimTrailingWhitespaceInRegexAndStrings on, which is its default.

Ported from VS Code: src/vs/editor/common/commands/trimTrailingWhitespaceCommand.ts

func (Commands) Type

func (c Commands) Type(sels []buffer.Selection, text string) Result

Type types text at every cursor, replacing its selection. A single "\n" is a new line (NewLine). In overtype mode a typed character replaces the one after the cursor, or, with a selection, the selection and the characters after it that the text is longer than the selection by.

Ported from VS Code: src/vs/editor/common/cursor/cursorTypeEditOperations.ts (SimpleCharacterTypeOperation, ReplaceOvertypeCommand)

func (Commands) WordQuery

func (c Commands) WordQuery(sel buffer.Selection) (q OccurrenceQuery, word buffer.Range, ok bool)

WordQuery is what the word highlight looks for: the word the cursor is in or touches, as a case sensitive search for whole words (the textual document highlight of VS Code). It says no when the selection spans lines, when there is no word at its start, or when the selection reaches out of that word.

Ported from VS Code: wordHighlighter.ts (WordHighlighter._run), textualHighlightProvider.ts

type CommentKind

type CommentKind int

CommentKind is what a line comment command does with the lines it is given.

const (
	// CommentToggle removes the comments when every line has one, and adds them otherwise.
	CommentToggle CommentKind = iota
	// CommentAdd adds a comment to every line, whatever it has.
	CommentAdd
	// CommentRemove removes the comments the lines have.
	CommentRemove
)

The kinds of line comment command.

type CopyData

type CopyData struct {
	// Text is the text for the clipboard: the pieces of the cursors, one after the other
	// with a line break between them.
	Text string
	// Pieces is the text of each cursor, in the order of the text, when there is more than one
	// piece; a paste of exactly as many cursors gives each its own piece. It is nil for one
	// piece.
	Pieces []string
	// FromEmptySelection says the text is a whole line copied from a cursor with no selection;
	// pasting it puts the line above the line of the cursor.
	FromEmptySelection bool
}

CopyData is what a copy puts on the clipboard.

type Cursor

type Cursor struct {
	Selection buffer.Selection
	// DesiredVisualCol is that column, or -1 when there is none and the column of
	// the cursor is used. Any move other than a vertical one clears it.
	DesiredVisualCol int
}

Cursor is one selection and the visual column vertical moves aim for (SPEC §7.2): when the cursor goes up or down over a short line and then on to a long one, it returns to the column it started from.

func CursorOf

func CursorOf(s buffer.Selection) Cursor

CursorOf makes a cursor of a selection.

func NewCursor

func NewCursor(p buffer.Position) Cursor

NewCursor is an empty selection at p.

func (Cursor) Position

func (c Cursor) Position() buffer.Position

Position is the active end: where the cursor is drawn.

type CursorHistory

type CursorHistory struct {
	// contains filtered or unexported fields
}

CursorHistory remembers where the cursors were so that Ctrl+U (cursor undo) and Ctrl+Shift+U (cursor redo) can go back: states are recorded before an explicit move, and edits to the text forget them, since they refer to the old text.

func (*CursorHistory) Clear

func (h *CursorHistory) Clear()

Clear forgets everything, as when the text is edited.

func (*CursorHistory) Record

func (h *CursorHistory) Record(sels []buffer.Selection)

Record remembers the selections before a move. Recording the same selections twice in a row is ignored; a new record forgets what could be redone.

func (*CursorHistory) Redo

func (h *CursorHistory) Redo(current []buffer.Selection) ([]buffer.Selection, bool)

Redo undoes an Undo.

func (*CursorHistory) Undo

func (h *CursorHistory) Undo(current []buffer.Selection) ([]buffer.Selection, bool)

Undo returns the selections to go back to, given the current ones, which become what Redo returns. The second result is false when there is nothing to go back to.

type Cursors

type Cursors struct {
	// contains filtered or unexported fields
}

Cursors are the cursors of an editor: the primary one first, then the others in the order they were added (SPEC §7.2, VS Code's CursorCollection).

func NewCursors

func NewCursors(opts Options) *Cursors

NewCursors makes the cursors of an editor: one at the start of the text.

func (*Cursors) Add

func (cs *Cursors) Add(c Cursor)

Add adds a cursor, which becomes the last added one: when it ends up merged with another, its direction counts (as in Ctrl-dragging into another cursor).

func (*Cursors) All

func (cs *Cursors) All() []Cursor

All returns a copy of the cursors, the primary first.

func (*Cursors) CancelSecondary

func (cs *Cursors) CancelSecondary()

CancelSecondary removes every cursor but the primary (Escape).

func (*Cursors) LastAdded

func (cs *Cursors) LastAdded() int

LastAdded is the index of the cursor added last, which the mouse keeps moving while a cursor is dragged out with the multi-cursor modifier; 0 when none was added.

func (*Cursors) Len

func (cs *Cursors) Len() int

Len is the number of cursors, at least 1.

func (*Cursors) Map

func (cs *Cursors) Map(fn func(Cursor) Cursor)

Map moves every cursor with fn and merges the ones that meet.

func (*Cursors) Normalize

func (cs *Cursors) Normalize()

Normalize merges cursors that overlap, or touch when one of them is empty; it is VS Code's CursorCollection.normalize. Of two merged cursors the one added first wins and keeps its place, with the union of both selections.

func (*Cursors) Primary

func (cs *Cursors) Primary() Cursor

Primary is the primary cursor.

func (*Cursors) Replace

func (cs *Cursors) Replace(i int, c Cursor)

Replace sets the cursor at index i, keeping which one was added last, and merges the cursors that meet. An index out of range changes nothing.

func (*Cursors) Selections

func (cs *Cursors) Selections() []buffer.Selection

Selections returns the selections of the cursors, the primary first.

func (*Cursors) Set

func (cs *Cursors) Set(list []Cursor)

Set replaces the cursors; the first is the primary. An empty list leaves them as they are.

func (*Cursors) SetOnChange

func (cs *Cursors) SetOnChange(fn func())

SetOnChange sets the function that is called after the cursors were changed by Set, SetSelections, Add, Replace, Map or CancelSecondary; nil removes it.

func (*Cursors) SetSelections

func (cs *Cursors) SetSelections(sels []buffer.Selection)

SetSelections replaces the cursors by selections.

type Expansion

type Expansion struct {
	// contains filtered or unexported fields
}

Expansion is a series of Expand Selection and Shrink Selection (Shift+Alt+Right and Left): it remembers the ranges around each cursor, found when it began, so that Shrink goes back through the same steps. The editor keeps it until the cursors move in any other way.

Ported from VS Code: smartSelect.ts (SmartSelectController).

func (*Expansion) Expand

func (e *Expansion) Expand() []buffer.Selection

Expand goes to the next larger range around each cursor and returns the selections.

func (*Expansion) Shrink

func (e *Expansion) Shrink() []buffer.Selection

Shrink goes back to the previous smaller range around each cursor.

type HiddenSpanner

type HiddenSpanner interface {
	// HiddenSpan is the span of hidden lines, first to last, that has a line; ok is false for a
	// line that is shown.
	HiddenSpan(line int) (first, last int, ok bool)
}

HiddenSpanner is implemented by a LineLayout that has lines hidden by folding: they have no row, and a cursor moves over them (SPEC §8.7).

type InsertionTypes

type InsertionTypes interface {
	TypeIfInserting(line, col int, ch string) (textmate.TokenType, bool)
}

InsertionTypes is what a TokenSource can also do: tell the standard type the text ch would have if it were inserted at a byte column of a line (tokens.Tokenizer.TypeIfInserting). The auto-closing of quotes asks it, to see whether a quote would end a string or begin one.

type LineLayout

type LineLayout interface {
	// PageRows is the number of rows a page up or page down moves.
	PageRows() int
	// MoveVertically moves a position by a number of rows, up when negative, and
	// returns the new position and the desired visual column to keep for the next
	// vertical move (-1 when there is none). desiredVisualCol is the one from the
	// previous move, or -1. Moving past the first or last row goes to the start or
	// end of it.
	MoveVertically(pos buffer.Position, rows, desiredVisualCol int) (buffer.Position, int)
	// RowStart is the position where the row that holds pos starts.
	RowStart(pos buffer.Position) buffer.Position
	// RowEnd is the position where the row that holds pos ends.
	RowEnd(pos buffer.Position) buffer.Position
}

LineLayout is what cursor movement asks of the view: how model lines are laid out in rows on the screen. The editor's view model implements it to account for word wrap and folding; ModelLineLayout is the one with a row per line.

type LineTokens

type LineTokens interface {
	Line(line int) []tokens.Token
}

LineTokens gives the tokens of a line, or nil when it has none (a *tokens.Tokenizer is one).

type Model

type Model interface {
	// LineCount is the number of lines, at least 1.
	LineCount() int
	// LineContent is the text of a line, which must be a valid line number.
	LineContent(line int) string
	// ValidatePosition moves a position into the text.
	ValidatePosition(p buffer.Position) buffer.Position
}

Model is the text the cursor functions read: lines by zero-based number, without their line feed (SPEC §7.2).

type ModelLineLayout

type ModelLineLayout struct {
	Model   Model
	TabSize int
	// Page is the number of rows of a page; zero means DefaultPageRows.
	Page int
	// Hidden tells the span of hidden lines that has a line (see HiddenSpanner); nil hides none.
	Hidden func(line int) (first, last int, ok bool)
	// Rows tells how the lines are split into rows; nil makes every line one row.
	Rows RowMap
}

ModelLineLayout lays out every model line as one row, or as the rows of Rows when word wrap splits lines. A position where a row starts is on that row; a cursor that moves by rows or goes to the end of a row that is not the last stops after its last visible character (before the white space that ends it, or before its last character when it has none), since a position has no side to say that it is shown at the end of the row before.

func (ModelLineLayout) HiddenSpan

func (l ModelLineLayout) HiddenSpan(line int) (first, last int, ok bool)

HiddenSpan implements HiddenSpanner.

func (ModelLineLayout) MoveVertically

func (l ModelLineLayout) MoveVertically(pos buffer.Position, rows, desired int) (buffer.Position, int)

MoveVertically ports VS Code's MoveOperations.vertical. The desired visual column is the one of the position in its row, or the one kept from the last move when a short row took the cursor to its end.

func (ModelLineLayout) PageRows

func (l ModelLineLayout) PageRows() int

PageRows is the page size.

func (ModelLineLayout) RowEnd

RowEnd is the end of the row that holds the position: the end of the line, or where a cursor stops at the end of a row that is not the last (see ModelLineLayout).

func (ModelLineLayout) RowStart

func (l ModelLineLayout) RowStart(pos buffer.Position) buffer.Position

RowStart is the start of the row that holds the position.

type Mover

type Mover struct {
	Model   Model
	Options Options
	// Layout says how lines are laid out in rows; nil means one row per line.
	Layout LineLayout
}

Mover moves cursors over a text: character, vertical, line, word, page and document moves of SPEC §3.1, each as a pure function from a cursor to a cursor (SPEC §7.2). With selecting, only the active end moves and the anchor stays; without, a selection collapses first as VS Code's does.

func NewMover

func NewMover(m Model, o Options, layout LineLayout) Mover

NewMover makes a Mover; layout may be nil.

func (Mover) AddCursorAbove

func (mv Mover) AddCursorAbove(cursors []Cursor) []Cursor

AddCursorAbove adds a cursor on the line above each cursor (Shift+Alt+Up on Linux), keeping the shape of its selection. The cursors, the new ones included, are the result; those that end up in the same place merge when set into Cursors.

Ported from VS Code: src/vs/editor/common/cursor/cursorMoveCommands.ts (addCursorUp).

func (Mover) AddCursorBelow

func (mv Mover) AddCursorBelow(cursors []Cursor) []Cursor

AddCursorBelow adds a cursor on the line below each cursor (Shift+Alt+Down).

func (Mover) ColumnSelect

func (mv Mover) ColumnSelect(fromLine, fromVisual, toLine, toVisual int) ColumnSelection

ColumnSelect selects the rectangle between two corners given as a line and a visual column: for each line between them, the part of the line inside the columns. Lines that end before the rectangle starts are left out; when all of them do, the cursors are at the end of each line. This is what dragging the mouse with Shift+Alt does, with the corner under the mouse as the second one.

Ported from VS Code: src/vs/editor/common/cursor/cursorColumnSelection.ts

func (Mover) ColumnSelectDataOf

func (mv Mover) ColumnSelectDataOf(c Cursor) ColumnSelectData

ColumnSelectDataOf is the rectangle of a cursor that has no column selection yet: from the anchor to the active end.

func (Mover) ColumnSelectDown

func (mv Mover) ColumnSelectDown(d ColumnSelectData, paged bool) ColumnSelection

ColumnSelectDown moves the second corner down one line, or one page.

func (Mover) ColumnSelectLeft

func (mv Mover) ColumnSelectLeft(d ColumnSelectData) ColumnSelection

ColumnSelectLeft makes the rectangle one visual column narrower on its moving side (or wider to the left), stopping at the first column.

func (Mover) ColumnSelectRight

func (mv Mover) ColumnSelectRight(d ColumnSelectData) ColumnSelection

ColumnSelectRight makes the rectangle one column wider to the right, up to the end of the longest line it covers.

func (Mover) ColumnSelectUp

func (mv Mover) ColumnSelectUp(d ColumnSelectData, paged bool) ColumnSelection

ColumnSelectUp moves the second corner up one line, or one page.

func (Mover) DocEnd

func (mv Mover) DocEnd(c Cursor, selecting bool) Cursor

DocEnd is Ctrl+End.

func (Mover) DocStart

func (mv Mover) DocStart(c Cursor, selecting bool) Cursor

DocStart is Ctrl+Home.

func (Mover) Down

func (mv Mover) Down(c Cursor, selecting bool) Cursor

Down moves one row down, keeping the desired visual column.

func (Mover) End

func (mv Mover) End(c Cursor, selecting bool) Cursor

End is the End key: the end of the row.

func (Mover) ExpandLine

func (mv Mover) ExpandLine(c Cursor) Cursor

ExpandLine selects the lines the cursor's selection touches, whole, up to the start of the line after (Ctrl+L); on the last line it ends at the end of the text.

func (Mover) Home

func (mv Mover) Home(c Cursor, selecting bool) Cursor

Home is the Home key: on a row that continues a wrapped line it goes to the start of the row; otherwise it goes to the first character that is not white space, and when already there, to the start of the line (smart home).

func (Mover) Left

func (mv Mover) Left(c Cursor, selecting bool) Cursor

Left moves one character left. A selection that is not being extended collapses to its start instead.

func (Mover) LineSelect

func (mv Mover) LineSelect(line int) buffer.Range

LineSelect is the range a triple click on a line enters: the whole line with its line break, or up to the end of the text on the last line.

Ported from VS Code: src/vs/editor/common/cursor/cursorMoveCommands.ts (CursorMoveCommands.line)

func (Mover) LineSelectDrag

func (mv Mover) LineSelectDrag(initial buffer.Range, p buffer.Position) buffer.Selection

LineSelectDrag is the selection while a triple click (or a press on a line number) is dragged to a position: whole lines from the line that was entered to the line of the position.

Ported from VS Code: src/vs/editor/common/cursor/cursorMoveCommands.ts (CursorMoveCommands.line)

func (Mover) MoveTo

func (mv Mover) MoveTo(c Cursor, p buffer.Position, selecting bool) Cursor

MoveTo moves to a position, which is moved into the text first (a click).

func (Mover) PageDown

func (mv Mover) PageDown(c Cursor, selecting bool) Cursor

PageDown moves a page down.

func (Mover) PageUp

func (mv Mover) PageUp(c Cursor, selecting bool) Cursor

PageUp moves a page up.

func (Mover) Right

func (mv Mover) Right(c Cursor, selecting bool) Cursor

Right moves one character right. A selection that is not being extended collapses to its end instead.

func (Mover) SelectAll

func (mv Mover) SelectAll() Cursor

SelectAll selects the whole text.

func (Mover) Up

func (mv Mover) Up(c Cursor, selecting bool) Cursor

Up moves one row up, keeping the desired visual column.

func (Mover) WordLeft

func (mv Mover) WordLeft(c Cursor, selecting bool, nav WordNavigation, multi bool) Cursor

WordLeft moves to the previous word stop; multi says there is more than one cursor, which changes where WordStartFast stops so that they stay together.

func (Mover) WordPartLeft

func (mv Mover) WordPartLeft(c Cursor, selecting bool, multi bool) Cursor

WordPartLeft moves to the previous stop of snake_case, camelCase and kebab-case parts, which is also never past the previous word start or word end (VS Code's WordPartOperations.moveWordPartLeft takes the nearest of the three).

func (Mover) WordPartRight

func (mv Mover) WordPartRight(c Cursor, selecting bool) Cursor

WordPartRight moves to the next stop of word parts, never past the next word start or word end (WordPartOperations.moveWordPartRight).

func (Mover) WordRight

func (mv Mover) WordRight(c Cursor, selecting bool, nav WordNavigation) Cursor

WordRight moves to the next word stop.

func (Mover) WordSelect

func (mv Mover) WordSelect(p buffer.Position) buffer.Range

WordSelect is the range a double click at a position enters: the word the position touches, or the gap between two words when it touches none. The selection it makes has the position at the end of the range.

Ported from VS Code: src/vs/editor/common/cursor/cursorWordOperations.ts (WordOperations.word)

func (Mover) WordSelectDrag

func (mv Mover) WordSelectDrag(initial buffer.Range, p buffer.Position) buffer.Selection

WordSelectDrag is the selection while a double click is dragged to a position: it extends from the word that was entered by whole words. A position inside a word reaches the word's far end; one on a boundary reaches the boundary.

Ported from VS Code: src/vs/editor/common/cursor/cursorWordOperations.ts (WordOperations.word)

type OccurrenceQuery

type OccurrenceQuery struct {
	// Text is the text to find.
	Text string
	// MatchCase makes the search case sensitive.
	MatchCase bool
	// WholeWord only accepts matches that are whole words.
	WholeWord bool
}

OccurrenceQuery is a piece of text that a highlight looks for in the whole document.

type OccurrenceSession

type OccurrenceSession struct {
	// contains filtered or unexported fields
}

OccurrenceSession is a series of Add Selection to Next Occurrence (Ctrl+D) and its relatives: it remembers what is searched for. The editor keeps it while the selections change only through these commands and drops it as soon as they change in any other way, or the editor loses focus.

Ported from VS Code: src/vs/editor/contrib/multicursor/browser/multicursor.ts (MultiCursorSession), without the link to the find widget.

func (*OccurrenceSession) AddNext

func (sess *OccurrenceSession) AddNext(c Commands, sels []buffer.Selection) ([]buffer.Selection, bool)

AddNext adds the next occurrence of the searched text after the last selection (Ctrl+D); ok is false when there is none.

func (*OccurrenceSession) AddPrevious

func (sess *OccurrenceSession) AddPrevious(c Commands, sels []buffer.Selection) ([]buffer.Selection, bool)

AddPrevious adds the previous occurrence before the last selection.

func (*OccurrenceSession) MoveToNext

func (sess *OccurrenceSession) MoveToNext(c Commands, sels []buffer.Selection) ([]buffer.Selection, bool)

MoveToNext replaces the last selection by the next occurrence (Ctrl+K Ctrl+D, "skip" an occurrence).

func (*OccurrenceSession) MoveToPrevious

func (sess *OccurrenceSession) MoveToPrevious(c Commands, sels []buffer.Selection) ([]buffer.Selection, bool)

MoveToPrevious replaces the last selection by the previous occurrence.

func (*OccurrenceSession) SelectAll

func (sess *OccurrenceSession) SelectAll(c Commands, primary buffer.Selection, scope []buffer.Range) []buffer.Selection

SelectAll selects every occurrence of the searched text (Ctrl+Shift+L), in the ranges of scope when there are any. The primary selection becomes the occurrence that touches the selection the command started from.

type Options

type Options struct {
	// TabSize is editor.tabSize.
	TabSize int
	// InsertSpaces is editor.insertSpaces.
	InsertSpaces bool
	// WordSeparators is the classifier of editor.wordSeparators.
	WordSeparators *WordClassifier
	// MultiCursorMergeOverlapping is editor.multiCursorMergeOverlapping: cursors
	// that overlap or touch become one.
	MultiCursorMergeOverlapping bool
	// UseTabStops is editor.useTabStops: Backspace in the indentation of a line
	// deletes back to the previous tab stop.
	UseTabStops bool
	// WordAtPosition finds the word the language defines at a byte column of a
	// line, as the language's wordPattern does (VS Code's model.getWordAtPosition).
	// It returns the start and end columns of the word touching col, and false when
	// there is none. Nil means VS Code's default word pattern.
	WordAtPosition func(line string, col int) (start, end int, ok bool)
	// Overtype is the overtype input mode: a typed character replaces the one after
	// the cursor.
	Overtype bool
	// OvertypeOnPaste is editor.overtypeOnPaste: in overtype mode a paste replaces the
	// characters after the cursor as typing does; off, a paste inserts.
	OvertypeOnPaste bool
	// AutoIndent is editor.autoIndent: what a new line, typing and pasting do with the
	// indentation (SPEC §8.6.2).
	AutoIndent indent.AutoIndent
	// AutoIndentOnPaste is editor.autoIndentOnPaste.
	AutoIndentOnPaste bool
	// AutoIndentOnPasteWithinString is editor.autoIndentOnPasteWithinString.
	AutoIndentOnPasteWithinString bool
	// Indenter applies the indentation rules and the on-enter rules of the languages, with
	// Tokens. Without them a language has no rules and a new line keeps the indentation of the
	// line it starts on.
	Indenter *indent.Indenter
	// Tokens gives the Indenter the tokens of the document.
	Tokens TokenSource
	// AutoClosingBrackets is editor.autoClosingBrackets.
	AutoClosingBrackets autoclose.Strategy
	// AutoClosingQuotes is editor.autoClosingQuotes.
	AutoClosingQuotes autoclose.Strategy
	// AutoClosingComments is editor.autoClosingComments.
	AutoClosingComments autoclose.Strategy
	// AutoClosingDelete is editor.autoClosingDelete.
	AutoClosingDelete autoclose.Behavior
	// AutoClosingOvertype is editor.autoClosingOvertype.
	AutoClosingOvertype autoclose.Behavior
	// AutoSurround is editor.autoSurround.
	AutoSurround autoclose.Surround
	// AutoClosing is the auto-closing and surrounding configuration of the language of the
	// document. Without it nothing is closed and nothing is surrounded.
	AutoClosing *autoclose.Language
	// AutoClosed are the closing characters the editor typed and that are still there (the
	// Character of each AutoClosed that earlier results reported and that the text and the cursors
	// have not made stale).
	AutoClosed []buffer.Range
	// Comments gives the comment tokens of the languages (SPEC §8.6.5); without it nothing can be
	// commented.
	Comments comment.Languages
	// CommentInsertSpace is editor.comments.insertSpace: a space goes between a comment token and
	// the text.
	CommentInsertSpace bool
	// CommentIgnoreEmptyLines is editor.comments.ignoreEmptyLines: lines with nothing on them get
	// no line comment.
	CommentIgnoreEmptyLines bool
	// UnmatchedClosing tells whether a closing bracket that closes nothing and that would close the
	// opening bracket text starts at or after a position; without it there is none.
	UnmatchedClosing func(pos buffer.Position, opening string) bool
}

Options is everything the cursor and editing functions read besides the text (SPEC §7.2). Later steps add fields; none of the functions take the settings one by one.

func DefaultOptions

func DefaultOptions() Options

DefaultOptions are VS Code's defaults.

type PasteOptions

type PasteOptions struct {
	// OnNewLine says the text is a whole line that was copied from a cursor with no selection:
	// it goes above the line of the cursor and the cursor stays where it was in its text.
	OnNewLine bool
	// Pieces is the text of each cursor of the copy the text comes from, when it came from
	// several cursors.
	Pieces []string
	// Block says the text was copied from a column selection.
	Block bool
	// Spread is editor.multiCursorPaste being "spread": a text with as many lines as there are
	// cursors goes line by line to the cursors, and a block goes down the lines under a single
	// cursor.
	Spread bool
}

PasteOptions say how a paste goes.

type Result

type Result struct {
	// Edits is one batch: sorted, not overlapping, every range in the text before.
	// It is empty when the command changes nothing.
	Edits []document.Edit
	// Selections are the selections in the text after the edits, in the order of the
	// selections the command was given. A cursor whose edits overlapped the edits
	// of an earlier cursor is dropped, as in VS Code, so there can be fewer.
	Selections []buffer.Selection
	// Kind is the undo kind of the edits.
	Kind document.EditKind
	// AutoClosed are the closing characters the command inserted, in the text after the edits:
	// the editor tracks them (SPEC §8.6.4).
	AutoClosed []AutoClosed
	// FollowUp, when it is not nil, is a second command to run once this one is applied, as its own
	// undo step: it is given the commands over the text after this result and the selections now.
	// It reports false when it has nothing to do, for instance when the text is not what it
	// expected.
	FollowUp func(c Commands, sels []buffer.Selection) (Result, bool)
}

Result is what an editing command does: the edits to apply, the selections that follow and the kind that decides how the edits join the undo history (document.EditOptions.Kind). The caller applies Edits with Document.Edit, using Selections as the selections after, and sets them as the new cursors.

type RowMap

type RowMap interface {
	// RowStarts are the byte columns where the rows of a line start: the first is 0. A line of one
	// row may give nil.
	RowStarts(line int) []int
	// Indent is the number of columns the rows after the first of a line are indented by.
	Indent(line int) int
}

RowMap tells how word wrap splits the model lines into rows (SPEC §9.2). A line that is not split is one row.

type SaveParticipants

type SaveParticipants struct {
	TrimTrailingWhitespace bool
	InsertFinalNewline     bool
	TrimFinalNewlines      bool
}

SaveParticipants say which of the edits that a save makes to the text are on (SPEC §6.3): the settings files.trimTrailingWhitespace, files.insertFinalNewline and files.trimFinalNewlines of the language of the document.

func (SaveParticipants) Any

func (p SaveParticipants) Any() bool

Any tells whether a participant is on.

type SearchOptions

type SearchOptions struct {
	// MatchCase makes the search case sensitive.
	MatchCase bool
	// WholeWord only accepts matches that are whole words.
	WholeWord bool
}

SearchOptions are the find options that the occurrence commands use when the selection is not empty: the match case and whole word switches of the find widget (editor.selectedTextMatchMode "findOptions", the default). An empty selection always starts a case sensitive search for whole words.

type SelectionHighlightOptions

type SelectionHighlightOptions struct {
	// MaxLength is the longest selection, in characters, that is searched for; 0 is no limit
	// (editor.selectionHighlightMaxLength).
	MaxLength int
	// Multiline lets a selection that spans lines be searched for (editor.selectionHighlightMultiline).
	Multiline bool
}

SelectionHighlightOptions are the settings of the selection highlight.

type SelectionRangeProvider

type SelectionRangeProvider interface {
	// SelectionRanges returns, for each position, ranges that contain it.
	SelectionRanges(m Model, positions []buffer.Position) [][]buffer.Range
}

SelectionRangeProvider says, for each position, the ranges around it that Expand Selection steps through, from the smallest to the largest (the bracket and string providers of the language steps implement it).

func NewBracketSelectionRanges

func NewBracketSelectionRanges(nav BracketNavigator) SelectionRangeProvider

NewBracketSelectionRanges makes the provider of the bracket steps of Expand Selection: for each bracket pair around a position, the text inside and the pair, and, when the pair spans lines, what is before it on its line or above it.

Ported from VS Code: src/vs/editor/contrib/smartSelect/browser/bracketSelections.ts

func NewStringSelectionRanges

func NewStringSelectionRanges(src LineTokens) SelectionRangeProvider

NewStringSelectionRanges makes the provider of the string steps of Expand Selection: for a position in a string (the tokens of the standard type "string" that touch it, which may be several: the quotes, the text, the escapes), the text inside the quotes and the string with them. A string that has no quotes at its ends, or that continues on another line, has only the second step.

func NewWordSelectionRanges

func NewWordSelectionRanges(opts Options, selectSubwords bool) SelectionRangeProvider

NewWordSelectionRanges makes the word based provider.

Ported from VS Code: src/vs/editor/contrib/smartSelect/browser/wordSelections.ts

type SelectionRangesOptions

type SelectionRangesOptions struct {
	// SelectLeadingAndTrailingWhitespace adds the line without its indentation and
	// trailing white space as a step before the whole line.
	SelectLeadingAndTrailingWhitespace bool
	// SelectSubwords adds the part of a camelCase, snake_case or kebab-case word
	// around the position as a step before the word.
	SelectSubwords bool
}

SelectionRangesOptions are editor.smartSelect.

func DefaultSelectionRangesOptions

func DefaultSelectionRangesOptions() SelectionRangesOptions

DefaultSelectionRangesOptions are VS Code's defaults: both on.

type SnapshotModel

type SnapshotModel struct {
	buffer.Snapshot
}

SnapshotModel is a Model over a buffer snapshot.

func NewModel

func NewModel(s buffer.Snapshot) SnapshotModel

NewModel makes a Model of a snapshot.

func (SnapshotModel) LineContent

func (m SnapshotModel) LineContent(line int) string

LineContent is the text of a line; a line out of range gives "".

type TokenSource

type TokenSource interface {
	// LineTokens are the tokens of a line (zero-based), or nil when it has none.
	LineTokens(line int) []tokens.Token
	// Language is the code of the language of the document.
	Language() int
	// CheapToTokenize reports whether the tokens of the line are known or can be had at once.
	CheapToTokenize(line int) bool
}

TokenSource gives the indentation rules the tokens of a document and its language (SPEC §8.6.2). A source that tokenizes in the background brings a line up to date in LineTokens.

type Word

type Word struct {
	Start, End int
	Kind       WordKind
	NextClass  CharClass
}

Word is a word found on a line: the byte columns where it starts and ends, what it is made of, and the class of the character that ended the search for it (the one before it when looking backward, the one after it when looking forward; white space when the line ended).

type WordClassifier

type WordClassifier struct {
	// contains filtered or unexported fields
}

WordClassifier tells the class of a character for a set of word separators.

func NewWordClassifier

func NewWordClassifier(separators string) *WordClassifier

NewWordClassifier makes a classifier from the characters of editor.wordSeparators.

func (*WordClassifier) Class

func (c *WordClassifier) Class(r rune) CharClass

Class is the class of r.

func (*WordClassifier) NextWord

func (c *WordClassifier) NextWord(line string, col int) (Word, bool)

NextWord finds the word that starts at or after col, looking forward as VS Code's word navigation does (_doFindNextWordOnLine). The second result is false when the line has no word after col.

func (*WordClassifier) PrevWord

func (c *WordClassifier) PrevWord(line string, col int) (Word, bool)

PrevWord finds the word that ends at or before col, looking backward as VS Code's word navigation does (_doFindPreviousWordOnLine). The second result is false when the line has no word before col. editor.wordSegmenterLocales is not supported, so words are never split by a language-aware segmenter.

func (*WordClassifier) WordAt

func (c *WordClassifier) WordAt(line string, col int) (Word, bool)

WordAt finds the word of regular characters that touches col, as VS Code's getWordAtPosition does for the cursor commands: the word that ends at or after col and starts at or before it. The second result is false when col is not in or next to a word.

type WordKind

type WordKind int

WordKind is what a word is made of: runs of regular characters, or runs of separators, are words for navigation.

const (
	// RegularWord is a run of regular characters.
	RegularWord WordKind = iota + 1
	// SeparatorWord is a run of separators.
	SeparatorWord
)

type WordNavigation

type WordNavigation int

WordNavigation says which stops word movement makes.

const (
	// WordStart stops at the start of words (cursorWordStartLeft and Right).
	WordStart WordNavigation = iota
	// WordStartFast is WordStart, but going left it steps over a single separator
	// followed by a word (cursorWordLeft).
	WordStartFast
	// WordEnd stops at the end of words (cursorWordEndLeft and Right).
	WordEnd
	// WordAccessibility stops at the start of words and skips separators only.
	WordAccessibility
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL