"use strict";
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.CurrentDocument = void 0;
const errors_1 = require("../../../util/vs/base/common/errors");
/**
 * Represents the current document state along with the cursor position within it.
 *
 * Provides convenience methods for inspecting text around the cursor, such as
 * retrieving the cursor's line, the text after the cursor, and whether the
 * cursor sits at the end of a line.
 */
class CurrentDocument {
    constructor(content, 
    /** Note that `cursorPosition`'s line and column numbers are 1-based. */
    cursorPosition) {
        this.content = content;
        this.cursorPosition = cursorPosition;
        this.lines = content.getLines();
        this.transformer = content.getTransformer();
        this.cursorOffset = this.transformer.getOffset(cursorPosition);
        this.cursorLineOffset = this.cursorPosition.lineNumber - 1;
    }
    /** Returns the full text of the line containing the cursor. */
    lineWithCursor() {
        const line = this.lines.at(this.cursorLineOffset);
        if (line === undefined) {
            throw new errors_1.BugIndicatingError(`CurrentDocument#lineWithCursor: cursor is out of bounds: cursor: ${this.cursorLineOffset}, doc line count: ${this.lines.length}`);
        }
        return line;
    }
    /** Returns the substring of the cursor's line starting from the cursor column (inclusive). */
    textAfterCursor() {
        const line = this.lineWithCursor();
        return line.substring(this.cursorPosition.column - 1);
    }
    /**
     * Determines if the cursor is at the end of the line.
     */
    isCursorAtEndOfLine() {
        // checks if there's any non-whitespace character after the cursor in the line
        const afterCursor = this.textAfterCursor();
        const isAtEndOfLine = afterCursor.match(/^\s*$/) !== null;
        return isAtEndOfLine;
    }
}
exports.CurrentDocument = CurrentDocument;
//# sourceMappingURL=xtabCurrentDocument.js.map