Skip to content

Commit 655f127

Browse files
authored
Merge pull request microsoft#182917 from jeanp413/fix-178017
Fix Improve terminal find behavior when there are more than 1000 results
2 parents c97098e + 59041c8 commit 655f127

File tree

5 files changed

+34
-19
lines changed

5 files changed

+34
-19
lines changed

src/vs/workbench/contrib/codeEditor/browser/find/simpleFindWidget.css

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
border: 1px solid var(--vscode-contrastBorder);
3535
border-bottom-left-radius: 4px;
3636
border-bottom-right-radius: 4px;
37+
font-size: 12px;
3738
}
3839

3940
.monaco-workbench.reduce-motion .monaco-editor .find-widget {
@@ -57,9 +58,9 @@
5758
}
5859

5960
.monaco-workbench .simple-find-part .matchesCount {
60-
width: 68px;
61-
max-width: 68px;
62-
min-width: 68px;
61+
width: 73px;
62+
max-width: 73px;
63+
min-width: 73px;
6364
padding-left: 5px;
6465
}
6566

src/vs/workbench/contrib/codeEditor/browser/find/simpleFindWidget.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@ interface IFindOptions {
3737
appendCaseSensitiveLabel?: string;
3838
appendRegexLabel?: string;
3939
appendWholeWordsLabel?: string;
40+
matchesLimit?: number;
4041
type?: 'Terminal' | 'Webview';
4142
}
4243

4344
const SIMPLE_FIND_WIDGET_INITIAL_WIDTH = 310;
44-
const MATCHES_COUNT_WIDTH = 68;
45+
const MATCHES_COUNT_WIDTH = 73;
4546

4647
export abstract class SimpleFindWidget extends Widget {
4748
private readonly _findInput: FindInput;
@@ -52,6 +53,7 @@ export abstract class SimpleFindWidget extends Widget {
5253
private readonly _updateHistoryDelayer: Delayer<void>;
5354
private readonly prevBtn: SimpleButton;
5455
private readonly nextBtn: SimpleButton;
56+
private readonly _matchesLimit: number;
5557
private _matchesCount: HTMLElement | undefined;
5658

5759
private _isVisible: boolean = false;
@@ -68,6 +70,8 @@ export abstract class SimpleFindWidget extends Widget {
6870
) {
6971
super();
7072

73+
this._matchesLimit = options.matchesLimit ?? Number.MAX_SAFE_INTEGER;
74+
7175
this._findInput = this._register(new ContextScopedFindInput(null, contextViewService, {
7276
label: NLS_FIND_INPUT_LABEL,
7377
placeholder: NLS_FIND_INPUT_PLACEHOLDER,
@@ -251,7 +255,7 @@ export abstract class SimpleFindWidget extends Widget {
251255
}
252256

253257
this._isVisible = true;
254-
this.updateButtons(this._foundMatch);
258+
this.updateResultCount();
255259
this.layout();
256260

257261
setTimeout(() => {
@@ -354,15 +358,21 @@ export abstract class SimpleFindWidget extends Widget {
354358

355359
const count = await this._getResultCount();
356360
this._matchesCount.innerText = '';
361+
const showRedOutline = (this.inputValue.length > 0 && count?.resultCount === 0);
362+
this._matchesCount.classList.toggle('no-results', showRedOutline);
357363
let label = '';
358-
this._matchesCount.classList.toggle('no-results', false);
359-
if (count?.resultCount !== undefined && count?.resultCount === 0) {
360-
label = NLS_NO_RESULTS;
361-
if (!!this.inputValue) {
362-
this._matchesCount.classList.toggle('no-results', true);
364+
if (count?.resultCount) {
365+
let matchesCount: string = String(count.resultCount);
366+
if (count.resultCount >= this._matchesLimit) {
367+
matchesCount += '+';
363368
}
364-
} else if (count?.resultCount) {
365-
label = strings.format(NLS_MATCHES_LOCATION, count.resultIndex + 1, count?.resultCount);
369+
let matchesPosition: string = String(count.resultIndex + 1);
370+
if (matchesPosition === '0') {
371+
matchesPosition = '?';
372+
}
373+
label = strings.format(NLS_MATCHES_LOCATION, matchesPosition, matchesCount);
374+
} else {
375+
label = NLS_NO_RESULTS;
366376
}
367377
alertFn(this._announceSearchResults(label, this.inputValue));
368378
this._matchesCount.appendChild(document.createTextNode(label));

src/vs/workbench/contrib/terminal/browser/terminal.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,10 @@ export interface ITerminalChildElement {
955955
xtermReady?(xterm: IXtermTerminal): void;
956956
}
957957

958+
export const enum XtermTerminalConstants {
959+
SearchHighlightLimit = 1000
960+
}
961+
958962
export interface IXtermTerminal {
959963
/**
960964
* An object that tracks when commands are run and enables navigating and selecting between
@@ -968,7 +972,7 @@ export interface IXtermTerminal {
968972
readonly shellIntegration: IShellIntegration;
969973

970974
readonly onDidChangeSelection: Event<void>;
971-
readonly onDidChangeFindResults: Event<{ resultIndex: number; resultCount: number } | undefined>;
975+
readonly onDidChangeFindResults: Event<{ resultIndex: number; resultCount: number }>;
972976

973977
/**
974978
* Gets a view of the current texture atlas used by the renderers.

src/vs/workbench/contrib/terminal/browser/xterm/xtermTerminal.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { IEditorOptions } from 'vs/editor/common/config/editorOptions';
1818
import { IShellIntegration, TerminalSettingId } from 'vs/platform/terminal/common/terminal';
1919
import { ITerminalFont } from 'vs/workbench/contrib/terminal/common/terminal';
2020
import { isSafari } from 'vs/base/browser/browser';
21-
import { IMarkTracker, IInternalXtermTerminal, IXtermTerminal, ISuggestController, IXtermColorProvider } from 'vs/workbench/contrib/terminal/browser/terminal';
21+
import { IMarkTracker, IInternalXtermTerminal, IXtermTerminal, ISuggestController, IXtermColorProvider, XtermTerminalConstants } from 'vs/workbench/contrib/terminal/browser/terminal';
2222
import { ILogService } from 'vs/platform/log/common/log';
2323
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
2424
import { TerminalStorageKeys } from 'vs/workbench/contrib/terminal/common/terminalStorageKeys';
@@ -152,7 +152,7 @@ export class XtermTerminal extends DisposableStore implements IXtermTerminal, II
152152
readonly onDidRequestSendText = this._onDidRequestSendText.event;
153153
private readonly _onDidRequestFreePort = new Emitter<string>();
154154
readonly onDidRequestFreePort = this._onDidRequestFreePort.event;
155-
private readonly _onDidChangeFindResults = new Emitter<{ resultIndex: number; resultCount: number } | undefined>();
155+
private readonly _onDidChangeFindResults = new Emitter<{ resultIndex: number; resultCount: number }>();
156156
readonly onDidChangeFindResults = this._onDidChangeFindResults.event;
157157
private readonly _onDidChangeSelection = new Emitter<void>();
158158
readonly onDidChangeSelection = this._onDidChangeSelection.event;
@@ -409,9 +409,9 @@ export class XtermTerminal extends DisposableStore implements IXtermTerminal, II
409409
return this._searchAddon;
410410
}
411411
const AddonCtor = await this._getSearchAddonConstructor();
412-
this._searchAddon = new AddonCtor();
412+
this._searchAddon = new AddonCtor({ highlightLimit: XtermTerminalConstants.SearchHighlightLimit });
413413
this.raw.loadAddon(this._searchAddon);
414-
this._searchAddon.onDidChangeResults((results: { resultIndex: number; resultCount: number } | undefined) => {
414+
this._searchAddon.onDidChangeResults((results: { resultIndex: number; resultCount: number }) => {
415415
this._lastFindResult = results;
416416
this._onDidChangeFindResults.fire(results);
417417
});

src/vs/workbench/contrib/terminalContrib/find/browser/terminalFindWidget.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { SimpleFindWidget } from 'vs/workbench/contrib/codeEditor/browser/find/simpleFindWidget';
77
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
88
import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
9-
import { ITerminalInstance, IXtermTerminal } from 'vs/workbench/contrib/terminal/browser/terminal';
9+
import { ITerminalInstance, IXtermTerminal, XtermTerminalConstants } from 'vs/workbench/contrib/terminal/browser/terminal';
1010
import { TerminalContextKeys } from 'vs/workbench/contrib/terminal/common/terminalContextKey';
1111
import { IThemeService } from 'vs/platform/theme/common/themeService';
1212
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
@@ -27,7 +27,7 @@ export class TerminalFindWidget extends SimpleFindWidget {
2727
@IThemeService private readonly _themeService: IThemeService,
2828
@IConfigurationService private readonly _configurationService: IConfigurationService
2929
) {
30-
super({ showCommonFindToggles: true, checkImeCompletionState: true, showResultCount: true, type: 'Terminal' }, _contextViewService, _contextKeyService, keybindingService);
30+
super({ showCommonFindToggles: true, checkImeCompletionState: true, showResultCount: true, type: 'Terminal', matchesLimit: XtermTerminalConstants.SearchHighlightLimit }, _contextViewService, _contextKeyService, keybindingService);
3131

3232
this._register(this.state.onFindReplaceStateChange(() => {
3333
this.show();

0 commit comments

Comments
 (0)