2019-08-28 15:52:39 +02:00
|
|
|
/*
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2019-08-28 15:52:39 +02:00
|
|
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
2024-09-09 14:57:16 +01:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
2019-08-28 15:52:39 +02:00
|
|
|
*/
|
|
|
|
|
|
2020-07-15 09:45:45 +01:00
|
|
|
import EditorModel from "./model";
|
2021-07-12 13:26:34 +01:00
|
|
|
import DocumentPosition from "./position";
|
2020-07-15 09:45:45 +01:00
|
|
|
|
2019-08-28 15:52:39 +02:00
|
|
|
export default class DocumentOffset {
|
2024-01-02 18:56:39 +00:00
|
|
|
public constructor(
|
|
|
|
|
public offset: number,
|
|
|
|
|
public readonly atNodeEnd: boolean,
|
|
|
|
|
) {}
|
2019-08-28 15:52:39 +02:00
|
|
|
|
2021-07-12 13:26:34 +01:00
|
|
|
public asPosition(model: EditorModel): DocumentPosition {
|
2019-09-03 15:58:05 +02:00
|
|
|
return model.positionForOffset(this.offset, this.atNodeEnd);
|
2019-08-28 15:52:39 +02:00
|
|
|
}
|
2019-09-04 12:40:03 +02:00
|
|
|
|
2021-07-12 13:26:34 +01:00
|
|
|
public add(delta: number, atNodeEnd = false): DocumentOffset {
|
2019-09-04 12:40:03 +02:00
|
|
|
return new DocumentOffset(this.offset + delta, atNodeEnd);
|
|
|
|
|
}
|
2019-08-28 15:52:39 +02:00
|
|
|
}
|