Skip to content

API reference ​

Everything comes from the package root, @adecore/editor-core.

DocumentModel ​

GroupMembers
TextgetText, getLength, getLineCount, getLine, slice, positionAt, offsetAt
SelectionsgetSelections, getSelectionCount, getPrimary, setSelections, expandSelectionTo, occurrencesExhausted
EditsapplyEdits, setText, undo, redo, getRevision
StategetSnapshot, subscribe
CommandstypeText, paste, execute, wordSelectionAt, wordStartBefore, wordEndAfter
Searchfind, findNext, replace, replaceAll
FoldinggetFoldingRanges

See Documents and edits, Typing and commands and Search and folding.

Diffing two texts ​

changedSpan(before, after) returns the one TextSpan (start, end, text) that differs between two texts, found from both ends, or null when they are equal. changedSpans(before, after) runs a line diff and returns one span per changed stretch, in the coordinates of before. Past 4 million steps of work, 1,000 changed lines or 16 MiB between the first and last change it gives up and returns the one span.

Apply the spans as one batch to replace a document's text without moving the carets, folds and marks outside the changes:

ts
const spans = changedSpans(document.getText(), textFromDisk);

document.applyEdits(
    spans.map((span) => ({ from: span.start, to: span.end, text: span.text })),
    { source: 'external' }
);

The view's setText does exactly this.

Brackets ​

scanBrackets(text, language?) pairs brackets lexically, so it works on code that does not parse yet. It skips strings and comments of the language (typescript by default) and returns a BracketIndex: pairs maps each opener to its closer and back, and unmatched holds the offsets of brackets without a partner. Malformed nesting never yields crossing pairs.

ts
scanBrackets('call(items[0]').pairs; // Map { 10 => 12, 12 => 10 }

Words ​

isWordBoundary(text, offset, camel, isStart) says whether a word starts or ends at an offset, where a run of punctuation counts as a word. isHumpBoundary(text, offset, isStart) says whether the offset splits a camel hump, a digit run or an underscore from the word around it. wordBoundary(text, offset, direction, camel?) returns the next stop in a direction, never inside a surrogate pair or between \r and \n. text is a string or any WordText: an object with length and charAt.

Other helpers ​

  • replaceWithCaseRespect(replacement, found) gives replacement the case of found: 'bar' for 'FOO' becomes 'BAR'.
  • indentationColumn(text, tabSize) is the width of the leading whitespace of text, with tabs expanded.

Types ​

TypeWhat it is
Selection, TextEdit, Position, OffsetRange, DocumentLineOffsets, ranges and lines; see Coordinates
EditOptions, DocumentEditOptions, ChangeSourceOptions of applyEdits
EditorSnapshot, DocumentChange, ContentEdit, DisposableWhat subscribe hands out
EditorCommand, CommandOptions, TypeTextOptionsCommands and their options
FindOptions, FindNextOptions, FindMatch, ReplaceOptions, ReplaceAllOptionsSearch
FoldingOptions, FoldingRange, FoldRole, FoldHints, FoldSymbolHint, FoldRangeHintFolding
TextSpan, BracketIndex, WordTextHelper results and inputs

Licenses and third-party notices are listed in each package.