don't use ICodeEditor#getOffsetForColumn for lines that aren't rendered (#208896)

fixes https://github.com/microsoft/vscode-copilot/issues/4828
This commit is contained in:
Johannes Rieken 2024-03-27 12:33:56 +01:00 committed by GitHub
parent 2fbd5e0656
commit 631514ae58
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -132,14 +132,14 @@ export class InlineChatZoneWidget extends ZoneWidget {
const marginWithoutIndentation = info.glyphMarginWidth + info.decorationsWidth + info.lineNumbersWidth;
this.container.style.marginLeft = `${marginWithoutIndentation}px`;
this._setWidgetMargins(position);
super.show(position, this._computeHeightInLines());
this._setWidgetMargins(position);
this.widget.focus();
}
override updatePositionAndHeight(position: Position): void {
this._setWidgetMargins(position);
super.updatePositionAndHeight(position, this._computeHeightInLines());
this._setWidgetMargins(position);
}
protected override _getWidth(info: EditorLayoutInfo): number {
@ -157,12 +157,17 @@ export class InlineChatZoneWidget extends ZoneWidget {
if (!viewModel) {
return 0;
}
const visibleRange = viewModel.getCompletelyVisibleViewRange();
const startLineVisibleRange = visibleRange.startLineNumber;
const positionLine = position.lineNumber;
let indentationLineNumber: number | undefined;
let indentationLevel: number | undefined;
for (let lineNumber = positionLine; lineNumber >= startLineVisibleRange; lineNumber--) {
if (!visibleRange.containsPosition(position)) {
// this is needed because `getOffsetForColumn` won't work when the position
// isn't visible/rendered
return 0;
}
let indentationLevel = viewModel.getLineFirstNonWhitespaceColumn(position.lineNumber);
let indentationLineNumber = position.lineNumber;
for (let lineNumber = position.lineNumber; lineNumber >= visibleRange.startLineNumber; lineNumber--) {
const currentIndentationLevel = viewModel.getLineFirstNonWhitespaceColumn(lineNumber);
if (currentIndentationLevel !== 0) {
indentationLineNumber = lineNumber;
@ -170,7 +175,8 @@ export class InlineChatZoneWidget extends ZoneWidget {
break;
}
}
return this.editor.getOffsetForColumn(indentationLineNumber ?? positionLine, indentationLevel ?? viewModel.getLineFirstNonWhitespaceColumn(positionLine));
return Math.max(0, this.editor.getOffsetForColumn(indentationLineNumber, indentationLevel)); // double-guard against invalie getOffsetForColumn-calls
}
private _setWidgetMargins(position: Position): void {