From 67817c33a13a3868b710b4fb1b92882b81f5695f Mon Sep 17 00:00:00 2001 From: rebornix Date: Wed, 11 Nov 2020 15:37:14 -0800 Subject: [PATCH] fix #40713. --- src/vs/editor/contrib/find/findController.ts | 8 ++++++ src/vs/editor/contrib/find/findWidget.ts | 27 ++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/vs/editor/contrib/find/findController.ts b/src/vs/editor/contrib/find/findController.ts index db45b86d8fc..fa6cb0f5814 100644 --- a/src/vs/editor/contrib/find/findController.ts +++ b/src/vs/editor/contrib/find/findController.ts @@ -473,6 +473,14 @@ export class FindController extends CommonFindController implements IFindControl this._widget = this._register(new FindWidget(this._editor, this, this._state, this._contextViewService, this._keybindingService, this._contextKeyService, this._themeService, this._storageService, this._notificationService)); this._findOptionsWidget = this._register(new FindOptionsWidget(this._editor, this._state, this._keybindingService, this._themeService)); } + + saveViewState(): any { + return this._widget?.getViewState(); + } + + restoreViewState(state: any): void { + this._widget?.setViewState(state); + } } export class StartFindAction extends MultiEditorAction { diff --git a/src/vs/editor/contrib/find/findWidget.ts b/src/vs/editor/contrib/find/findWidget.ts index d37402f1e8c..59dbea74148 100644 --- a/src/vs/editor/contrib/find/findWidget.ts +++ b/src/vs/editor/contrib/find/findWidget.ts @@ -582,7 +582,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IVerticalSashL } } - private _layoutViewZone() { + private _layoutViewZone(targetScrollTop?: number) { const addExtraSpaceOnTop = this._codeEditor.getOption(EditorOption.find).addExtraSpaceOnTop; if (!addExtraSpaceOnTop) { @@ -602,7 +602,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IVerticalSashL viewZone.heightInPx = this._getHeight(); this._viewZoneId = accessor.addZone(viewZone); // scroll top adjust to make sure the editor doesn't scroll when adding viewzone at the beginning. - this._codeEditor.setScrollTop(this._codeEditor.getScrollTop() + viewZone.heightInPx); + this._codeEditor.setScrollTop(targetScrollTop || this._codeEditor.getScrollTop() + viewZone.heightInPx); }); } @@ -1266,6 +1266,29 @@ export class FindWidget extends Widget implements IOverlayWidget, IVerticalSashL const value = this._codeEditor.getOption(EditorOption.accessibilitySupport); this._findInput.setFocusInputOnOptionClick(value !== AccessibilitySupport.Enabled); } + + getViewState() { + let widgetViewZoneVisible = false; + if (this._viewZone && this._viewZoneId) { + widgetViewZoneVisible = this._viewZone.heightInPx > this._codeEditor.getScrollTop(); + } + + return { + widgetViewZoneVisible, + scrollTop: this._codeEditor.getScrollTop() + }; + } + + setViewState(state?: { widgetViewZoneVisible: boolean; scrollTop: number }) { + if (!state) { + return; + } + + if (state.widgetViewZoneVisible) { + // we should add the view zone + this._layoutViewZone(state.scrollTop); + } + } } export interface ISimpleButtonOpts { -- GitLab