Files
ThreadNet-Web/src/utils/EditorStateTransfer.ts
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

46 lines
1.3 KiB
TypeScript
Raw Normal View History

/*
2024-09-09 14:57:16 +01:00
Copyright 2024 New Vector Ltd.
Copyright 2019-2021 The Matrix.org Foundation C.I.C.
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
2024-09-09 14:57:16 +01:00
Please see LICENSE files in the repository root for full details.
*/
import { MatrixEvent } from "matrix-js-sdk/src/matrix";
2021-06-22 17:22:38 +01:00
import { SerializedPart } from "../editor/parts";
import DocumentOffset from "../editor/offset";
2021-06-22 17:22:38 +01:00
/**
* Used while editing, to pass the event, and to preserve editor state
2019-06-13 13:28:21 +02:00
* from one editor instance to another when remounting the editor
* upon receiving the remote echo for an unsent event.
*/
export default class EditorStateTransfer {
private serializedParts: SerializedPart[] | null = null;
private caret: DocumentOffset | null = null;
public constructor(private readonly event: MatrixEvent) {}
2021-06-22 17:22:38 +01:00
public setEditorState(caret: DocumentOffset | null, serializedParts: SerializedPart[]): void {
2021-06-22 17:22:38 +01:00
this.caret = caret;
this.serializedParts = serializedParts;
}
public hasEditorState(): boolean {
2021-06-22 17:22:38 +01:00
return !!this.serializedParts;
}
public getSerializedParts(): SerializedPart[] | null {
2021-06-22 17:22:38 +01:00
return this.serializedParts;
}
public getCaret(): DocumentOffset | null {
2021-06-22 17:22:38 +01:00
return this.caret;
}
public getEvent(): MatrixEvent {
2021-06-22 17:22:38 +01:00
return this.event;
}
}