提交 f68737bd 编写于 作者: D Daniel Imms

Use optional chaining in terminalInstance

上级 00cd1a88
......@@ -524,9 +524,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
throw new Error('The terminal instance has not been attached to a container yet');
}
if (this._wrapperElement.parentNode) {
this._wrapperElement.parentNode.removeChild(this._wrapperElement);
}
this._wrapperElement.parentNode?.removeChild(this._wrapperElement);
this._container = container;
this._container.appendChild(this._wrapperElement);
}
......@@ -544,9 +542,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
}
// The container changed, reattach
if (this._container) {
this._container.removeChild(this._wrapperElement);
}
this._container?.removeChild(this._wrapperElement);
this._container = container;
this._container.appendChild(this._wrapperElement);
}
......@@ -652,11 +648,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
const widgetManager = new TerminalWidgetManager(this._wrapperElement);
this._widgetManager = widgetManager;
this._processManager.onProcessReady(() => {
if (this._linkHandler) {
this._linkHandler.setWidgetManager(widgetManager);
}
});
this._processManager.onProcessReady(() => this._linkHandler?.setWidgetManager(widgetManager));
const computedStyle = window.getComputedStyle(this._container);
const width = parseInt(computedStyle.getPropertyValue('width').replace('px', ''), 10);
......@@ -751,19 +743,13 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
}
public clearSelection(): void {
if (!this._xterm) {
return;
}
this._xterm.clearSelection();
this._xterm?.clearSelection();
}
public selectAll(): void {
if (!this._xterm) {
return;
}
// Focus here to ensure the terminal context key is set
this._xterm.focus();
this._xterm.selectAll();
this._xterm?.focus();
this._xterm?.selectAll();
}
public findNext(term: string, searchOptions: ISearchOptions): boolean {
......@@ -924,45 +910,31 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
}
public scrollDownLine(): void {
if (this._xterm) {
this._xterm.scrollLines(1);
}
this._xterm?.scrollLines(1);
}
public scrollDownPage(): void {
if (this._xterm) {
this._xterm.scrollPages(1);
}
this._xterm?.scrollPages(1);
}
public scrollToBottom(): void {
if (this._xterm) {
this._xterm.scrollToBottom();
}
this._xterm?.scrollToBottom();
}
public scrollUpLine(): void {
if (this._xterm) {
this._xterm.scrollLines(-1);
}
this._xterm?.scrollLines(-1);
}
public scrollUpPage(): void {
if (this._xterm) {
this._xterm.scrollPages(-1);
}
this._xterm?.scrollPages(-1);
}
public scrollToTop(): void {
if (this._xterm) {
this._xterm.scrollToTop();
}
this._xterm?.scrollToTop();
}
public clear(): void {
if (this._xterm) {
this._xterm.clear();
}
this._xterm?.clear();
}
private _refreshSelectionContextKey() {
......@@ -1019,12 +991,8 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
}
private _onProcessData(data: string): void {
if (this._widgetManager) {
this._widgetManager.closeMessage();
}
if (this._xterm) {
this._xterm.write(data);
}
this._widgetManager?.closeMessage();
this._xterm?.write(data);
}
/**
......@@ -1130,10 +1098,8 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
public reuseTerminal(shell: IShellLaunchConfig): void {
// Unsubscribe any key listener we may have.
if (this._pressAnyKeyToCloseListener) {
this._pressAnyKeyToCloseListener.dispose();
this._pressAnyKeyToCloseListener = undefined;
}
this._pressAnyKeyToCloseListener?.dispose();
this._pressAnyKeyToCloseListener = undefined;
// Kill and clear up the process, making the process manager ready for a new process
this._processManager.dispose();
......@@ -1256,10 +1222,8 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
this._navigationModeAddon = new NavigationModeAddon(this._terminalA11yTreeFocusContextKey);
this._xterm!.loadAddon(this._navigationModeAddon);
} else {
if (this._navigationModeAddon) {
this._navigationModeAddon.dispose();
this._navigationModeAddon = undefined;
}
this._navigationModeAddon?.dispose();
this._navigationModeAddon = undefined;
}
this._xterm!.setOption('screenReaderMode', isEnabled);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册