2019-06-12 18:29:21 +02:00
|
|
|
/*
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2024 New Vector Ltd.
|
|
|
|
|
Copyright 2019-2021 The Matrix.org Foundation C.I.C.
|
2019-06-12 18:29:21 +02:00
|
|
|
|
2025-01-06 11:18:54 +00:00
|
|
|
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.
|
2019-06-12 18:29:21 +02:00
|
|
|
*/
|
|
|
|
|
|
2023-08-07 09:24:58 +01:00
|
|
|
import { MatrixEvent } from "matrix-js-sdk/src/matrix";
|
2021-06-22 17:22:38 +01:00
|
|
|
|
|
|
|
|
import { SerializedPart } from "../editor/parts";
|
2021-06-30 13:01:26 +01:00
|
|
|
import DocumentOffset from "../editor/offset";
|
2021-06-22 17:22:38 +01:00
|
|
|
|
2019-06-12 18:29:21 +02: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
|
2019-06-12 18:29:21 +02:00
|
|
|
* upon receiving the remote echo for an unsent event.
|
|
|
|
|
*/
|
|
|
|
|
export default class EditorStateTransfer {
|
2023-02-13 17:01:43 +00:00
|
|
|
private serializedParts: SerializedPart[] | null = null;
|
|
|
|
|
private caret: DocumentOffset | null = null;
|
2019-06-12 18:29:21 +02:00
|
|
|
|
2022-12-16 12:29:59 +00:00
|
|
|
public constructor(private readonly event: MatrixEvent) {}
|
2021-06-22 17:22:38 +01:00
|
|
|
|
2023-03-13 15:07:20 +00:00
|
|
|
public setEditorState(caret: DocumentOffset | null, serializedParts: SerializedPart[]): void {
|
2021-06-22 17:22:38 +01:00
|
|
|
this.caret = caret;
|
|
|
|
|
this.serializedParts = serializedParts;
|
2019-06-12 18:29:21 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-30 13:01:26 +01:00
|
|
|
public hasEditorState(): boolean {
|
2021-06-22 17:22:38 +01:00
|
|
|
return !!this.serializedParts;
|
2019-06-12 18:29:21 +02:00
|
|
|
}
|
|
|
|
|
|
2023-02-13 17:01:43 +00:00
|
|
|
public getSerializedParts(): SerializedPart[] | null {
|
2021-06-22 17:22:38 +01:00
|
|
|
return this.serializedParts;
|
2019-06-12 18:29:21 +02:00
|
|
|
}
|
|
|
|
|
|
2023-02-13 17:01:43 +00:00
|
|
|
public getCaret(): DocumentOffset | null {
|
2021-06-22 17:22:38 +01:00
|
|
|
return this.caret;
|
2019-06-12 18:29:21 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-30 13:01:26 +01:00
|
|
|
public getEvent(): MatrixEvent {
|
2021-06-22 17:22:38 +01:00
|
|
|
return this.event;
|
2019-06-12 18:29:21 +02:00
|
|
|
}
|
|
|
|
|
}
|