Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/vs/editor/contrib/find/browser/findWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import * as platform from '../../../../base/common/platform.js';
import * as strings from '../../../../base/common/strings.js';
import './findWidget.css';
import { ICodeEditor, IOverlayWidget, IOverlayWidgetPosition, IViewZone, OverlayWidgetPositionPreference } from '../../../browser/editorBrowser.js';
import { StickyScrollController } from '../../stickyScroll/browser/stickyScrollController.js';
import { ConfigurationChangedEvent, EditorOption } from '../../../common/config/editorOptions.js';
import { Range } from '../../../common/core/range.js';
import { CONTEXT_FIND_INPUT_FOCUSED, CONTEXT_FIND_WIDGET_FOCUSED, CONTEXT_REPLACE_INPUT_FOCUSED, FIND_IDS, MATCHES_LIMIT } from './findModel.js';
Expand Down Expand Up @@ -84,6 +85,8 @@ const FIND_INPUT_AREA_WIDTH = PART_WIDTH - 54;
let MAX_MATCHES_COUNT_WIDTH = 69;
// let FIND_ALL_CONTROLS_WIDTH = 17/** Find Input margin-left */ + (MAX_MATCHES_COUNT_WIDTH + 3 + 1) /** Match Results */ + 23 /** Button */ * 4 + 2/** sash */;

const FIND_WIDGET_TOP_MARGIN = 4;

const FIND_INPUT_AREA_HEIGHT = 33; // The height of Find Widget when Replace Input is not visible.

const ctrlKeyMod = (platform.isMacintosh ? KeyMod.WinCtrl : KeyMod.CtrlCmd);
Expand Down Expand Up @@ -162,6 +165,8 @@ export class FindWidget extends Widget implements IOverlayWidget, IVerticalSashL
private _resizeSash!: Sash;
private _resized!: boolean;
private readonly _updateHistoryDelayer: Delayer<void>;
private _stickyScrollInitialized: boolean = false;
private _stickyScrollHeight: number = 0;

constructor(
codeEditor: ICodeEditor,
Expand Down Expand Up @@ -241,6 +246,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IVerticalSashL
}
}
}));
this._initStickyScroll();
this._findInputFocused = CONTEXT_FIND_INPUT_FOCUSED.bindTo(contextKeyService);
this._findFocusTracker = this._register(dom.trackFocus(this._findInput.inputBox.inputElement));
this._register(this._findFocusTracker.onDidFocus(() => {
Expand Down Expand Up @@ -526,6 +532,27 @@ export class FindWidget extends Widget implements IOverlayWidget, IVerticalSashL
}
}

private _initStickyScroll(): void {
const controller = StickyScrollController.get(this._codeEditor);
if (!controller) {
return;
}
this._stickyScrollInitialized = true;
this._stickyScrollHeight = controller.stickyScrollWidgetHeight;
this._register(controller.onDidChangeStickyScrollHeight(({ height }) => {
this._stickyScrollHeight = height;
this._updateStickyScrollOffset();
}));
}

private _updateStickyScrollOffset(): void {
if (this._stickyScrollHeight > 0) {
this._domNode.style.marginTop = `${this._stickyScrollHeight + FIND_WIDGET_TOP_MARGIN}px`;
} else {
this._domNode.style.marginTop = '';
}
}

private _updateButtons(): void {
this._findInput.setEnabled(this._isVisible);
this._replaceInput.setEnabled(this._isVisible && this._isReplaceVisible);
Expand Down Expand Up @@ -579,6 +606,11 @@ export class FindWidget extends Widget implements IOverlayWidget, IVerticalSashL
this._tryUpdateWidgetWidth();
this._updateButtons();

if (!this._stickyScrollInitialized) {
this._initStickyScroll();
}
this._updateStickyScrollOffset();

this._revealTimeouts.push(setTimeout(() => {
this._domNode.classList.add('visible');
this._domNode.setAttribute('aria-hidden', 'false');
Expand Down