diff --git a/src/vs/editor/browser/stableEditorScroll.ts b/src/vs/editor/browser/stableEditorScroll.ts index 986e18ac6c03d7..4d7539435cd352 100644 --- a/src/vs/editor/browser/stableEditorScroll.ts +++ b/src/vs/editor/browser/stableEditorScroll.ts @@ -20,6 +20,16 @@ export class StableEditorScrollState { const visibleRanges = editor.getVisibleRanges(); if (visibleRanges.length > 0) { visiblePosition = visibleRanges[0].getStartPosition(); + + const cursorPos = editor.getPosition(); + if (cursorPos) { + const isVisible = visibleRanges.some(range => range.containsPosition(cursorPos)); + if (isVisible) { + // Keep cursor pos fixed if it is visible + visiblePosition = cursorPos; + } + } + const visiblePositionScrollTop = editor.getTopForPosition(visiblePosition.lineNumber, visiblePosition.column); visiblePositionScrollDelta = editor.getScrollTop() - visiblePositionScrollTop; }