Skip to content

Commit c28d166

Browse files
committed
rename widget: clean up computing cursor-box top
1 parent a6921e0 commit c28d166

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/vs/editor/contrib/rename/browser/renameInputField.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,7 @@ export class RenameInputField implements IContentWidget {
180180
const bodyBox = getClientArea(this.getDomNode().ownerDocument.body);
181181
const editorBox = getDomNodePagePosition(this._editor.getDomNode());
182182

183-
// FIXME@ulugbekna: can getVisibleRanges() be empty? if so what to do about it
184-
const firstLineInViewport = this._editor.getVisibleRanges()[0].startLineNumber;
185-
const cursorBoxTop = this._editor.getTopForLineNumber(this._position!.lineNumber) - this._editor.getTopForLineNumber(firstLineInViewport);
183+
const cursorBoxTop = this._getTopForPosition();
186184

187185
this._nPxAvailableAbove = cursorBoxTop + editorBox.top;
188186
this._nPxAvailableBelow = bodyBox.height - this._nPxAvailableAbove;
@@ -391,6 +389,18 @@ export class RenameInputField implements IContentWidget {
391389
this._editor.layoutContentWidget(this);
392390
}
393391

392+
private _getTopForPosition(): number {
393+
const visibleRanges = this._editor.getVisibleRanges();
394+
let firstLineInViewport: number;
395+
if (visibleRanges.length > 0) {
396+
firstLineInViewport = visibleRanges[0].startLineNumber;
397+
} else {
398+
this._logService.warn('RenameInputField#_getTopForPosition: this should not happen - visibleRanges is empty');
399+
firstLineInViewport = Math.max(1, this._position!.lineNumber - 5); // @ulugbekna: fallback to current line minus 5
400+
}
401+
return this._editor.getTopForLineNumber(this._position!.lineNumber) - this._editor.getTopForLineNumber(firstLineInViewport);
402+
}
403+
394404
private _trace(...args: any[]) {
395405
this._logService.trace('RenameInputField', ...args);
396406
}

0 commit comments

Comments
 (0)