UNPKG

@pierre/diffs

Version:

56 lines (55 loc) 3.19 kB
import { FileContents } from "../types.js"; import { EditState, EditorType, EditorViewState, RetainedDiffSessionSnapshot } from "./types.js"; import { TextDocument } from "./textDocument.js"; import { Editor } from "./editor.js"; //#region src/editor/EditStateManager.d.ts interface ManagedEditSessionBase<EType extends EditorType, LAnnotation = unknown> { document?: TextDocument<EType, LAnnotation>; fileInfo?: Pick<FileContents, 'lang' | 'name'>; editor?: EditorViewState; } interface ManagedFileEditSession<LAnnotation = unknown> extends ManagedEditSessionBase<'file', LAnnotation> { type: 'file'; diffSession?: never; } interface ManagedFileDiffEditSession<LAnnotation = unknown> extends ManagedEditSessionBase<'file-diff', LAnnotation> { type: 'file-diff'; diffSession?: RetainedDiffSessionSnapshot; } type ManagedEditSession<EType extends EditorType = EditorType, LAnnotation = unknown> = ManagedEditSessionBase<EType, LAnnotation> & (EType extends 'file' ? Pick<ManagedFileEditSession, 'type' | 'diffSession'> : Pick<ManagedFileDiffEditSession, 'type' | 'diffSession'>); /** Keeps file and diff edit state in independent persistence domains. */ declare class EditStateManagerClass { #private; /** Mark a keyed session as active and return its initial or stored state. */ activate<EType extends EditorType, LAnnotation, Caret>(type: EType, editStateKey: string, owner: Editor<EType, LAnnotation, Caret>, initialState?: ManagedEditSession<EType, LAnnotation>): ManagedEditSession<EType, LAnnotation>; /** * Stop tracking this file session as active and store its current state, * unless `discard` is true. */ releaseFile<LAnnotation, Caret>(editStateKey: string, owner: Editor<'file', LAnnotation, Caret>, discard?: boolean): void; /** * Stop tracking this diff session as active and store its current state, * unless `discard` is true. */ releaseFileDiff<LAnnotation, Caret>(editStateKey: string, owner: Editor<'file-diff', LAnnotation, Caret>, discard?: boolean): void; /** Return current state for an active or dormant editing session. */ get<EType extends EditorType, LAnnotation>(type: EType, editStateKey: string): EditState<EType, LAnnotation> | undefined; /** Clear a dormant session, returning false when it is active or missing. */ clear(type: EditorType, editStateKey: string, parts?: ClearEditStateOptions): boolean; /** Clear all dormant sessions without affecting active editors. */ clearAll(): void; setCapacity(capacity: number): void; } interface ClearEditStateOptions { document?: boolean; history?: boolean; editor?: boolean; selections?: boolean; view?: boolean; } declare function cloneEditorViewState(state: EditorViewState): EditorViewState; declare function toManagedEditState<EType extends EditorType, LAnnotation>(session: ManagedEditSession<EType, LAnnotation>): EditState<EType, LAnnotation> | undefined; declare const EditStateManager: EditStateManagerClass; //#endregion export { ClearEditStateOptions, EditStateManager, ManagedEditSession, ManagedFileDiffEditSession, ManagedFileEditSession, cloneEditorViewState, toManagedEditState }; //# sourceMappingURL=EditStateManager.d.ts.map