Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

Selection

abstract

Superclass for editor selections. Every selection type should extend this. Should not be instantiated directly.

abstract class Selection {
constructor(
$anchor: ResolvedPos,
$head: ResolvedPos,
ranges?: readonly SelectionRange[],
);
readonly $anchor: ResolvedPos;
readonly $head: ResolvedPos;
get anchor(): number;
get head(): number;
get from(): number;
get empty(): boolean;
ranges: readonly SelectionRange[];
get to(): number;
get $from(): ResolvedPos;
get $to(): ResolvedPos;
visible: boolean;
 
content(): Slice;
abstract eq(selection: Selection): boolean;
getBookmark(): SelectionBookmark;
abstract map(doc: Node, mapping: Mappable): Selection;
replace(tr: Transaction, content?: Slice): void;
replaceWith(tr: Transaction, node: Node): void;
abstract toJSON(): any;
 
static atEnd(doc: Node): Selection;
static atStart(doc: Node): Selection;
static findFrom(
dir: number,
textOnly?: boolean,
): Selection | null;
static fromJSON(doc: Node, json: any): Selection;
static jsonID(id: string, selectionClass: {
fromJSON: (doc: Node, json: any) => Selection;
}
): {
fromJSON: (doc: Node, json: any) => Selection;
}
;
static near($pos: ResolvedPos, bias?: number): Selection;
}

§Constructors

§
new Selection($anchor: ResolvedPos, $head: ResolvedPos, ranges?: readonly SelectionRange[])
[src]

Initialize a selection with the head and anchor and ranges. If no ranges are given, constructs a single range across $anchor and $head.

§Properties

§

The resolved anchor of the selection (the side that stays in place when the selection is modified).

§

The resolved head of the selection (the side that moves when the selection is modified).

§
anchor: number readonly
[src]

The selection's anchor, as an unresolved position.

§
from: number readonly
[src]

The lower bound of the selection's main range.

§
empty: boolean readonly
[src]

Indicates whether the selection contains any content.

§
ranges: readonly SelectionRange[]
[src]

The ranges covered by the selection.

§
to: number readonly
[src]

The upper bound of the selection's main range.

§
$from: ResolvedPos readonly
[src]

The resolved lower bound of the selection's main range.

§
$to: ResolvedPos readonly
[src]

The resolved upper bound of the selection's main range.

§
visible: boolean
[src]

Controls whether, when a selection of this type is active in the browser, the selected range should be visible to the user. Defaults to true.

§Methods

§
content(): Slice
[src]

Get the content of this selection as a slice.

§
eq(selection: Selection): boolean abstract
[src]

Test whether the selection is the same as another selection.

§
getBookmark(): SelectionBookmark
[src]

Get a bookmark for this selection, which is a value that can be mapped without having access to a current document, and later resolved to a real selection for a given document again. (This is used mostly by the history to track and restore old selections.) The default implementation of this method just converts the selection to a text selection and returns the bookmark for that.

§
map(doc: Node, mapping: Mappable): Selection abstract
[src]

Map this selection through a mappable thing. doc should be the new document to which we are mapping.

§
replace(tr: Transaction, content?: Slice): void
[src]

Replace the selection with a slice or, if no slice is given, delete the selection. Will append to the given transaction.

§
replaceWith(tr: Transaction, node: Node): void
[src]

Replace the selection with the given node, appending the changes to the given transaction.

§
toJSON(): any abstract
[src]

Convert the selection to a JSON representation. When implementing this for a custom selection class, make sure to give the object a type property whose value matches the ID under which you registered your class.

§Static Methods

§
atEnd(doc: Node): Selection
[src]

Find the cursor or leaf node selection closest to the end of the given document.

§
atStart(doc: Node): Selection
[src]

Find the cursor or leaf node selection closest to the start of the given document. Will return an AllSelection if no valid position exists.

§
findFrom($pos: ResolvedPos, dir: number, textOnly?: boolean): Selection | null
[src]

Find a valid cursor or leaf node selection starting at the given position and searching back if dir is negative, and forward if positive. When textOnly is true, only consider cursor selections. Will return null when no valid selection position is found.

§
fromJSON(doc: Node, json: any): Selection
[src]

Deserialize the JSON representation of a selection. Must be implemented for custom classes (as a static class method).

§
jsonID(id: string, selectionClass: {
fromJSON: (doc: Node, json: any) => Selection;
}
): {
fromJSON: (doc: Node, json: any) => Selection;
}
[src]

To be able to deserialize selections from JSON, custom selection classes must register themselves with an ID string, so that they can be disambiguated. Try to pick something that's unlikely to clash with classes from other modules.

§
near($pos: ResolvedPos, bias?: number): Selection
[src]

Find a valid cursor or leaf node selection near the given position. Searches forward first by default, but if bias is negative, it will search backwards first.