diff --git a/arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts b/arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts index 122000941..743296fd1 100644 --- a/arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts +++ b/arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts @@ -355,6 +355,8 @@ import { StylingParticipant } from '@theia/core/lib/browser/styling-service'; import { MonacoEditorMenuContribution } from './theia/monaco/monaco-menu'; import { MonacoEditorMenuContribution as TheiaMonacoEditorMenuContribution } from '@theia/monaco/lib/browser/monaco-menu'; import { UpdateArduinoState } from './contributions/update-arduino-state'; +import { TerminalWidgetImpl } from './theia/terminal/terminal-widget-impl'; +import { TerminalWidget } from '@theia/terminal/lib/browser/base/terminal-widget'; // Hack to fix copy/cut/paste issue after electron version update in Theia. // https://github.com/eclipse-theia/theia/issues/12487 @@ -1026,4 +1028,7 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => { rebind(TheiaMonacoEditorMenuContribution).toService( MonacoEditorMenuContribution ); + + // Patch terminal issues. + rebind(TerminalWidget).to(TerminalWidgetImpl).inTransientScope(); }); diff --git a/arduino-ide-extension/src/browser/theia/terminal/terminal-widget-impl.ts b/arduino-ide-extension/src/browser/theia/terminal/terminal-widget-impl.ts new file mode 100644 index 000000000..310a659d1 --- /dev/null +++ b/arduino-ide-extension/src/browser/theia/terminal/terminal-widget-impl.ts @@ -0,0 +1,23 @@ +import { injectable } from '@theia/core/shared/inversify'; +import { TerminalWidgetImpl as TheiaTerminalWidgetImpl } from '@theia/terminal/lib/browser/terminal-widget-impl'; +import debounce from 'p-debounce'; + +// Patch for https://github.com/eclipse-theia/theia/pull/12587 +@injectable() +export class TerminalWidgetImpl extends TheiaTerminalWidgetImpl { + private readonly debouncedResizeTerminal = debounce( + () => this.doResizeTerminal(), + 50 + ); + + protected override resizeTerminal(): void { + this.debouncedResizeTerminal(); + } + + private doResizeTerminal(): void { + const geo = this.fitAddon.proposeDimensions(); + const cols = geo.cols; + const rows = geo.rows - 1; // subtract one row for margin + this.term.resize(cols, rows); + } +}