Skip to content

Commit

Permalink
Fixes #41968: Keep the top line stable, and not the centered one
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdima committed Mar 26, 2018
1 parent ecce88d commit 7a3204c
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/vs/editor/contrib/codelens/codelensController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,14 @@ export class CodeLensContribution implements editorCommon.IEditorContribution {
}
}

const centeredRange = this._editor.getCenteredRangeInViewport();
const shouldRestoreCenteredRange = centeredRange && (groups.length !== this._lenses.length && this._editor.getScrollTop() !== 0);
const visibleRanges = this._editor.getVisibleRanges();
const visiblePosition = (visibleRanges.length > 0 ? visibleRanges[0].getStartPosition() : null);
let visiblePositionScrollDelta = 0;
if (visiblePosition) {
const visiblePositionScrollTop = this._editor.getTopForPosition(visiblePosition.lineNumber, visiblePosition.column);
visiblePositionScrollDelta = this._editor.getScrollTop() - visiblePositionScrollTop;
}

this._editor.changeDecorations((changeAccessor) => {
this._editor.changeViewZones((accessor) => {

Expand Down Expand Up @@ -259,8 +265,10 @@ export class CodeLensContribution implements editorCommon.IEditorContribution {
helper.commit(changeAccessor);
});
});
if (shouldRestoreCenteredRange) {
this._editor.revealRangeInCenter(centeredRange, editorCommon.ScrollType.Immediate);

if (visiblePosition) {
const visiblePositionScrollTop = this._editor.getTopForPosition(visiblePosition.lineNumber, visiblePosition.column);
this._editor.setScrollTop(visiblePositionScrollTop + visiblePositionScrollDelta);
}
}

Expand Down

0 comments on commit 7a3204c

Please sign in to comment.