Files
ThreadNet-Web/src/editor/offset.ts
T

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

26 lines
714 B
TypeScript
Raw Normal View History

/*
2024-09-09 14:57:16 +01:00
Copyright 2024 New Vector Ltd.
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.
*/
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
export default class DocumentOffset {
2024-01-02 18:56:39 +00:00
public constructor(
public offset: number,
public readonly atNodeEnd: boolean,
) {}
2021-07-12 13:26:34 +01:00
public asPosition(model: EditorModel): DocumentPosition {
return model.positionForOffset(this.offset, this.atNodeEnd);
}
2021-07-12 13:26:34 +01:00
public add(delta: number, atNodeEnd = false): DocumentOffset {
return new DocumentOffset(this.offset + delta, atNodeEnd);
}
}