Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes find widget shall be shown per split terminal #155361

Merged
merged 8 commits into from Sep 2, 2022
Expand Up @@ -11,7 +11,7 @@
right: 18px;
max-width: calc(100% - 28px - 28px - 8px);
pointer-events: none;
padding: 0 10px 10px;
padding: 0 10px 0px 10px;
}

.simple-find-part .monaco-inputbox > .ibwrapper > input {
Expand Down Expand Up @@ -46,6 +46,17 @@
flex: 1;
}

.monaco-workbench .simple-find-part .matchesCount {
width: 68px;
max-width: 68px;
min-width: 68px;
padding-left: 5px;
}

.monaco-workbench .simple-find-part.reduced-find-widget .matchesCount {
display: none;
}

.monaco-workbench .simple-find-part .button {
min-width: 20px;
width: 20px;
Expand Down
Expand Up @@ -41,6 +41,9 @@ interface IFindOptions {
type?: 'Terminal' | 'Webview';
}

const SIMPLE_FIND_WIDGET_INITIAL_WIDTH = 310;
const MATCHES_COUNT_WIDTH = 68;

export abstract class SimpleFindWidget extends Widget {
private readonly _findInput: FindInput;
private readonly _domNode: HTMLElement;
Expand All @@ -54,6 +57,7 @@ export abstract class SimpleFindWidget extends Widget {

private _isVisible: boolean = false;
private _foundMatch: boolean = false;
private _width: number = 0;

constructor(
state: FindReplaceState = new FindReplaceState(),
Expand Down Expand Up @@ -177,6 +181,9 @@ export abstract class SimpleFindWidget extends Widget {

if (options?.showResultCount) {
this._domNode.classList.add('result-count');
this._matchesCount = document.createElement('div');
this._matchesCount.className = 'matchesCount';
this._findInput.domNode.insertAdjacentElement('afterend', this._matchesCount);
this._register(this._findInput.onDidChange(() => {
this.updateResultCount();
this.updateButtons(this._foundMatch);
Expand Down Expand Up @@ -238,6 +245,10 @@ export abstract class SimpleFindWidget extends Widget {
}
}

public isVisible(): boolean {
return this._isVisible;
}

public getDomNode() {
return this._domNode;
}
Expand All @@ -254,6 +265,7 @@ export abstract class SimpleFindWidget extends Widget {

this._isVisible = true;
this.updateButtons(this._foundMatch);
this.layout();

setTimeout(() => {
this._innerDomNode.classList.add('visible', 'visible-transition');
Expand All @@ -268,6 +280,7 @@ export abstract class SimpleFindWidget extends Widget {
}

this._isVisible = true;
this.layout();

setTimeout(() => {
this._innerDomNode.classList.add('visible', 'visible-transition');
Expand All @@ -288,6 +301,22 @@ export abstract class SimpleFindWidget extends Widget {
}
}

public layout(width: number = this._width): void {
this._width = width;

if (!this._isVisible) {
return;
}

if (this._matchesCount) {
let reducedFindWidget = false;
if (SIMPLE_FIND_WIDGET_INITIAL_WIDTH + MATCHES_COUNT_WIDTH + 28 >= width) {
reducedFindWidget = true;
}
this._innerDomNode.classList.toggle('reduced-find-widget', reducedFindWidget);
}
}

protected _delayedUpdateHistory() {
this._updateHistoryDelayer.trigger(this._updateHistory.bind(this));
}
Expand Down Expand Up @@ -322,11 +351,11 @@ export abstract class SimpleFindWidget extends Widget {
}

async updateResultCount(): Promise<void> {
const count = await this._getResultCount();
if (!this._matchesCount) {
this._matchesCount = document.createElement('div');
this._matchesCount.className = 'matchesCount';
return;
}

const count = await this._getResultCount();
this._matchesCount.innerText = '';
let label = '';
this._matchesCount.classList.toggle('no-results', false);
Expand All @@ -340,7 +369,6 @@ export abstract class SimpleFindWidget extends Widget {
}
alertFn(this._announceSearchResults(label, this.inputValue));
this._matchesCount.appendChild(document.createTextNode(label));
this._findInput?.domNode.insertAdjacentElement('afterend', this._matchesCount);
this._foundMatch = !!count && count.resultCount > 0;
}

Expand Down
13 changes: 0 additions & 13 deletions src/vs/workbench/contrib/terminal/browser/media/terminal.css
Expand Up @@ -93,19 +93,6 @@
z-index: 33 !important;
}

.result-count .simple-find-part {
width: 330px;
max-width: 330px;
min-width: 330px;
}

.result-count .matchesCount {
width: 68px;
max-width: 68px;
min-width: 68px;
padding-left: 5px;
}

.xterm .xterm-accessibility {
z-index: 32 !important;
pointer-events: none;
Expand Down
23 changes: 6 additions & 17 deletions src/vs/workbench/contrib/terminal/browser/terminal.ts
Expand Up @@ -16,6 +16,7 @@ import { IGenericMarkProperties } from 'vs/platform/terminal/common/terminalProc
import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
import { IEditableData } from 'vs/workbench/common/views';
import { TerminalFindWidget } from 'vs/workbench/contrib/terminal/browser/terminalFindWidget';
import { ITerminalStatusList } from 'vs/workbench/contrib/terminal/browser/terminalStatusList';
import { INavigationMode, IRegisterContributedProfileArgs, IRemoteTerminalAttachTarget, IStartExtensionTerminalRequest, ITerminalBackend, ITerminalConfigHelper, ITerminalFont, ITerminalProcessExtHostProxy } from 'vs/workbench/contrib/terminal/common/terminal';
import { EditorGroupColumn } from 'vs/workbench/services/editor/common/editorGroupColumn';
Expand Down Expand Up @@ -149,7 +150,6 @@ export interface ITerminalService extends ITerminalInstanceHost {
onDidInputInstanceData: Event<ITerminalInstance>;
onDidRegisterProcessSupport: Event<void>;
onDidChangeConnectionState: Event<void>;
onDidRequestHideFindWidget: Event<void>;

/**
* Creates a terminal.
Expand Down Expand Up @@ -210,7 +210,6 @@ export interface ITerminalService extends ITerminalInstanceHost {

getDefaultInstanceHost(): ITerminalInstanceHost;
getInstanceHost(target: ITerminalLocationOptions | undefined): ITerminalInstanceHost;
getFindHost(instance?: ITerminalInstance): ITerminalFindHost;

resolveLocation(location?: ITerminalLocationOptions): TerminalLocation | undefined;
setNativeDelegate(nativeCalls: ITerminalServiceNativeDelegate): void;
Expand All @@ -230,7 +229,7 @@ export interface ITerminalServiceNativeDelegate {
* This service is responsible for integrating with the editor service and managing terminal
* editors.
*/
export interface ITerminalEditorService extends ITerminalInstanceHost, ITerminalFindHost {
export interface ITerminalEditorService extends ITerminalInstanceHost {
readonly _serviceBrand: undefined;

/** Gets all _terminal editor_ instances. */
Expand Down Expand Up @@ -304,7 +303,7 @@ export interface TerminalEditorLocation {
* This service is responsible for managing terminal groups, that is the terminals that are hosted
* within the terminal panel, not in an editor.
*/
export interface ITerminalGroupService extends ITerminalInstanceHost, ITerminalFindHost {
export interface ITerminalGroupService extends ITerminalInstanceHost {
readonly _serviceBrand: undefined;

/** Gets all _terminal view_ instances, ie. instances contained within terminal groups. */
Expand Down Expand Up @@ -376,14 +375,6 @@ export interface ITerminalInstanceHost {
getInstanceFromResource(resource: URI | undefined): ITerminalInstance | undefined;
}

export interface ITerminalFindHost {
focusFindWidget(): void;
hideFindWidget(): void;
getFindState(): FindReplaceState;
findNext(): void;
findPrevious(): void;
}

/**
* Similar to xterm.js' ILinkProvider but using promises and hides xterm.js internals (like buffer
* positions, decorations, etc.) from the rest of vscode. This is the interface to use for
Expand Down Expand Up @@ -460,6 +451,9 @@ export interface ITerminalInstance {

readonly statusList: ITerminalStatusList;

readonly findState: FindReplaceState;
readonly findWidget: TerminalFindWidget;

/**
* The process ID of the shell process, this is undefined when there is no process associated
* with this terminal.
Expand Down Expand Up @@ -723,11 +717,6 @@ export interface ITerminalInstance {
*/
selectAll(): void;

/**
* Notifies the terminal that the find widget's focus state has been changed.
*/
notifyFindWidgetFocusChanged(isFocused: boolean): void;

/**
* Focuses the terminal instance if it's able to (xterm.js instance exists).
*
Expand Down
27 changes: 14 additions & 13 deletions src/vs/workbench/contrib/terminal/browser/terminalActions.ts
Expand Up @@ -1045,7 +1045,7 @@ export function registerTerminalActions() {
});
}
run(accessor: ServicesAccessor) {
accessor.get(ITerminalService).getFindHost().focusFindWidget();
accessor.get(ITerminalService).activeInstance?.findWidget.reveal();
}
});
registerAction2(class extends Action2 {
Expand All @@ -1065,7 +1065,7 @@ export function registerTerminalActions() {
});
}
run(accessor: ServicesAccessor) {
accessor.get(ITerminalService).getFindHost().hideFindWidget();
accessor.get(ITerminalService).activeInstance?.findWidget.hide();
}
});

Expand Down Expand Up @@ -1419,9 +1419,8 @@ export function registerTerminalActions() {
}
run(accessor: ServicesAccessor) {
const terminalService = accessor.get(ITerminalService);
const instanceHost = terminalService.getFindHost();
const state = instanceHost.getFindState();
state.change({ isRegex: !state.isRegex }, false);
const state = terminalService.activeInstance?.findState;
state?.change({ isRegex: !state.isRegex }, false);
}
});
registerAction2(class extends Action2 {
Expand All @@ -1442,9 +1441,8 @@ export function registerTerminalActions() {
}
run(accessor: ServicesAccessor) {
const terminalService = accessor.get(ITerminalService);
const instanceHost = terminalService.getFindHost();
const state = instanceHost.getFindState();
state.change({ wholeWord: !state.wholeWord }, false);
const state = terminalService.activeInstance?.findState;
state?.change({ wholeWord: !state.wholeWord }, false);
}
});
registerAction2(class extends Action2 {
Expand All @@ -1465,9 +1463,8 @@ export function registerTerminalActions() {
}
run(accessor: ServicesAccessor) {
const terminalService = accessor.get(ITerminalService);
const instanceHost = terminalService.getFindHost();
const state = instanceHost.getFindState();
state.change({ matchCase: !state.matchCase }, false);
const state = terminalService.activeInstance?.findState;
state?.change({ matchCase: !state.matchCase }, false);
}
});
registerAction2(class extends Action2 {
Expand All @@ -1494,7 +1491,9 @@ export function registerTerminalActions() {
});
}
run(accessor: ServicesAccessor) {
accessor.get(ITerminalService).getFindHost().findNext();
const terminalService = accessor.get(ITerminalService);
terminalService.activeInstance?.findWidget.show();
terminalService.activeInstance?.findWidget.find(false);
}
});
registerAction2(class extends Action2 {
Expand All @@ -1521,7 +1520,9 @@ export function registerTerminalActions() {
});
}
run(accessor: ServicesAccessor) {
accessor.get(ITerminalService).getFindHost().findPrevious();
const terminalService = accessor.get(ITerminalService);
terminalService.activeInstance?.findWidget.show();
terminalService.activeInstance?.findWidget.find(true);
}
});
registerAction2(class extends Action2 {
Expand Down