diff --git a/src/vs/editor/contrib/stickyScroll/browser/stickyScrollController.ts b/src/vs/editor/contrib/stickyScroll/browser/stickyScrollController.ts index 15047ea258ec2..e49b64c7b99a0 100644 --- a/src/vs/editor/contrib/stickyScroll/browser/stickyScrollController.ts +++ b/src/vs/editor/contrib/stickyScroll/browser/stickyScrollController.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { Disposable, DisposableStore, toDisposable } from '../../../../base/common/lifecycle.js'; +import { IDisposable, Disposable, DisposableStore, toDisposable } from '../../../../base/common/lifecycle.js'; import { IActiveCodeEditor, ICodeEditor, MouseTargetType } from '../../../browser/editorBrowser.js'; import { IEditorContribution, ScrollType } from '../../../common/editorCommon.js'; import { ILanguageFeaturesService } from '../../../common/services/languageFeatures.js'; @@ -75,6 +75,7 @@ export class StickyScrollController extends Disposable implements IEditorContrib private _showEndForLine: number | undefined; private _minRebuildFromLine: number | undefined; private _mouseTarget: EventTarget | null = null; + private _cursorPositionListener: IDisposable | undefined; private readonly _onDidChangeStickyScrollHeight = this._register(new Emitter<{ height: number }>()); public readonly onDidChangeStickyScrollHeight = this._onDidChangeStickyScrollHeight.event; @@ -475,10 +476,16 @@ export class StickyScrollController extends Disposable implements IEditorContrib const lineNumberOption = this._editor.getOption(EditorOption.lineNumbers); if (lineNumberOption.renderType === RenderLineNumbersType.Relative) { - this._sessionStore.add(this._editor.onDidChangeCursorPosition(() => { - this._showEndForLine = undefined; - this._renderStickyScroll(0); - })); + if (!this._cursorPositionListener) { + this._cursorPositionListener = this._editor.onDidChangeCursorPosition(() => { + this._showEndForLine = undefined; + this._renderStickyScroll(0); + }); + this._sessionStore.add(this._cursorPositionListener); + } + } else if (this._cursorPositionListener) { + this._sessionStore.delete(this._cursorPositionListener); + this._cursorPositionListener = undefined; } }