Skip to content

Commit

Permalink
add layout to ITerminalContribution (#176979)
Browse files Browse the repository at this point in the history
  • Loading branch information
meganrogge authored Mar 13, 2023
1 parent 870b587 commit dc99c29
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
5 changes: 1 addition & 4 deletions src/vs/workbench/contrib/terminal/browser/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/
import { Dimension } from 'vs/base/browser/dom';
import { Orientation } from 'vs/base/browser/ui/splitview/splitview';
import { AutoOpenBarrier } from 'vs/base/common/async';
import { Color } from 'vs/base/common/color';
import { Event } from 'vs/base/common/event';
import { IDisposable } from 'vs/base/common/lifecycle';
Expand Down Expand Up @@ -38,6 +37,7 @@ export const ITerminalInstanceService = createDecorator<ITerminalInstanceService
* been initialized.
*/
export interface ITerminalContribution extends IDisposable {
layout?(xterm: IXtermTerminal & { raw: RawXtermTerminal }): void;
xtermReady?(xterm: IXtermTerminal & { raw: RawXtermTerminal }): void;
}

Expand Down Expand Up @@ -602,9 +602,6 @@ export interface ITerminalInstance {
/** A promise that resolves when the terminal's pty/process have been created. */
readonly processReady: Promise<void>;

/** A barrier that opens when the terminal's container is ready */
readonly containerReadyBarrier: AutoOpenBarrier;

/** Whether the terminal's process has child processes (ie. is dirty/busy). */
readonly hasChildProcesses: boolean;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
private _areLinksReady: boolean = false;
private _initialDataEvents: string[] | undefined = [];
private _containerReadyBarrier: AutoOpenBarrier;
get containerReadyBarrier(): AutoOpenBarrier { return this._containerReadyBarrier; }
private _attachBarrier: AutoOpenBarrier;
private _icon: TerminalIcon | undefined;
private _messageTitleDisposable: IDisposable | undefined;
Expand Down Expand Up @@ -1859,6 +1858,13 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {

// Signal the container is ready
this._containerReadyBarrier.open();

for (const contribution of this._contributions) {
if (!this.xterm) {
this._xtermReadyPromise.then(() => contribution[1].layout?.(this.xterm!));
}
contribution[1].layout?.(this.xterm!);
}
}

@debounce(50)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ class AccessibleBufferContribution extends DisposableStore implements ITerminalC
) {
super();
}

xtermReady(xterm: IXtermTerminal & { raw: Terminal }): void {
this._instance.containerReadyBarrier.wait().then(() => {
layout(xterm: IXtermTerminal & { raw: Terminal }): void {
if (!this._accessibleBufferWidget) {
this._accessibleBufferWidget = this._instantiationService.createInstance(AccessibleBufferWidget, this._instance.instanceId, xterm);
});
}
}
show(): void {
this._accessibleBufferWidget?.show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export class AccessibleBufferWidget extends DisposableStore {
this._accessibleBuffer.ariaRoleDescription = localize('terminal.integrated.accessibleBuffer', 'Terminal buffer');
this._accessibleBuffer.classList.add('accessible-buffer');
this._editorContainer = document.createElement('div');
this._accessibleBuffer.tabIndex = -1;
this._bufferEditor = this._instantiationService.createInstance(CodeEditorWidget, this._editorContainer, editorOptions, codeEditorWidgetOptions);
this._accessibleBuffer.replaceChildren(this._editorContainer);
this._xtermElement.insertAdjacentElement('beforebegin', this._accessibleBuffer);
Expand All @@ -98,7 +99,14 @@ export class AccessibleBufferWidget extends DisposableStore {
await this._updateEditor(true);
}
}));
this.add(this._bufferEditor.onDidFocusEditorText(() => this._accessibleBuffer.classList.add('active')));
this._updateEditor();
this.add(this._bufferEditor.onDidFocusEditorText(async () => {
// if the editor is focused via tab, we need to update the model
// and show it
await this._updateEditor();
this._accessibleBuffer.classList.add(Constants.Active);
this._xtermElement.classList.add(Constants.Hide);
}));
}

private _hide(): void {
Expand Down Expand Up @@ -135,7 +143,6 @@ export class AccessibleBufferWidget extends DisposableStore {
this._bufferEditor.setSelection({ startLineNumber: lineNumber, startColumn: 1, endLineNumber: lineNumber, endColumn: 1 });
}
this._bufferEditor.setScrollTop(this._bufferEditor.getScrollHeight());
this._bufferEditor.focus();
}

async show(): Promise<void> {
Expand All @@ -144,6 +151,7 @@ export class AccessibleBufferWidget extends DisposableStore {
this._bufferEditor.layout({ width: this._xtermElement.clientWidth, height: this._xtermElement.clientHeight });
this._accessibleBuffer.classList.add(Constants.Active);
this._xtermElement.classList.add(Constants.Hide);
this._bufferEditor.focus();
}

private async _getTextModel(resource: URI): Promise<ITextModel | null> {
Expand Down

0 comments on commit dc99c29

Please sign in to comment.