| 38 | // ============================================================================ |
| 39 | |
| 40 | export class FitAddon implements ITerminalAddon { |
| 41 | private _terminal?: ITerminalCore; |
| 42 | private _resizeObserver?: ResizeObserver; |
| 43 | private _resizeDebounceTimer?: ReturnType<typeof setTimeout>; |
| 44 | private _lastCols?: number; |
| 45 | private _lastRows?: number; |
| 46 | private _isResizing: boolean = false; |
| 47 | |
| 48 | /** |
| 49 | * Activate the addon (called by Terminal.loadAddon) |
| 50 | */ |
| 51 | public activate(terminal: ITerminalCore): void { |
| 52 | this._terminal = terminal; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Dispose the addon and clean up resources |
| 57 | */ |
| 58 | public dispose(): void { |
| 59 | // Disconnect ResizeObserver |
| 60 | if (this._resizeObserver) { |
| 61 | this._resizeObserver.disconnect(); |
| 62 | this._resizeObserver = undefined; |
| 63 | } |
| 64 | |
| 65 | // Clear pending debounce timer |
| 66 | if (this._resizeDebounceTimer) { |
| 67 | clearTimeout(this._resizeDebounceTimer); |
| 68 | this._resizeDebounceTimer = undefined; |
| 69 | } |
| 70 | |
| 71 | // Clear stored dimensions |
| 72 | this._lastCols = undefined; |
| 73 | this._lastRows = undefined; |
| 74 | |
| 75 | this._terminal = undefined; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Fit the terminal to its container |
| 80 | * |
| 81 | * Calculates optimal dimensions and resizes the terminal. |
| 82 | * Does nothing if dimensions cannot be calculated or haven't changed. |
| 83 | */ |
| 84 | public fit(): void { |
| 85 | // Prevent re-entrant calls during resize |
| 86 | if (this._isResizing) { |
| 87 | return; |
| 88 | } |
| 89 | |
| 90 | const dims = this.proposeDimensions(); |
| 91 | if (!dims || !this._terminal) { |
| 92 | return; |
| 93 | } |
| 94 | |
| 95 | // Access terminal to check current dimensions |
| 96 | const terminal = this._terminal as any; |
| 97 | const currentCols = terminal.cols; |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…