json-joy
Version:
Collection of libraries for building collaborative editing apps.
45 lines (44 loc) • 1.91 kB
TypeScript
import { CursorAnchor } from '../slice/constants';
import { PersistedSlice } from '../slice/PersistedSlice';
import type { Point } from '../rga/Point';
/**
* Cursor is a slice that represents an explicitly highlighted place in the
* text to the user. The {@link Cursor} is a {@link Range}, it has a `start`
* {@link Point} and an `end` {@link Point}.
*
* The {@link Cursor} can be a caret (collapsed cursor) or a selection (range
* expanded cursor). The caret is said to be "collapsed", its `start` and `end`
* {@link Point}s are the same. When the selection is said to be "expanded", its
* `start` and `end` {@link Point}s are different.
*
* The `start` {@link Point} is always the one that comes first in the text, it
* is less then or equal to the `end` {@link Point} in the spatial (text) order.
*
* An expanded selection cursor has a *focus* and an *anchor* side. The *focus*
* side is the one that moves when the user presses the arrow keys. The *anchor*
* side is the one that stays in place when the user presses the arrow keys. The
* side of the anchor is determined by the {@link Cursor#anchorSide} property.
*/
export declare class Cursor<T = string> extends PersistedSlice<T> {
/**
* @todo Remove getter `get` here.
*/
get anchorSide(): CursorAnchor;
isStartFocused(): boolean;
isEndFocused(): boolean;
set anchorSide(value: CursorAnchor);
anchor(): Point<T>;
focus(): Point<T>;
set(start: Point<T>, end?: Point<T>, anchorSide?: CursorAnchor): void;
/**
* Move one of the edges of the cursor to a new point.
*
* @param point Point to set the edge to.
* @param endpoint 0 for "focus", 1 for "anchor".
*/
setEndpoint(point: Point<T>, endpoint?: 0 | 1): void;
move(move: number): void;
collapseToStart(anchorSide?: CursorAnchor): void;
toStringName(): string;
toStringHeaderName(): string;
}