* Observe the terminal's container for resize events * * Sets up a ResizeObserver to automatically call fit() when the * container size changes. Resize events are debounced to avoid * excessive calls during window drag operations. * * Call dispose() to stop observing.
()
| 205 | * Call dispose() to stop observing. |
| 206 | */ |
| 207 | public observeResize(): void { |
| 208 | if (!this._terminal?.element) { |
| 209 | return; |
| 210 | } |
| 211 | |
| 212 | // Already observing |
| 213 | if (this._resizeObserver) { |
| 214 | return; |
| 215 | } |
| 216 | |
| 217 | // Create ResizeObserver that watches for external size changes |
| 218 | this._resizeObserver = new ResizeObserver((entries) => { |
| 219 | // Ignore resize events while we're actively resizing |
| 220 | if (this._isResizing) { |
| 221 | return; |
| 222 | } |
| 223 | |
| 224 | // Only trigger if the observed element's content rect changed |
| 225 | const entry = entries[0]; |
| 226 | if (!entry) return; |
| 227 | |
| 228 | // Debounce resize events |
| 229 | if (this._resizeDebounceTimer) { |
| 230 | clearTimeout(this._resizeDebounceTimer); |
| 231 | } |
| 232 | |
| 233 | this._resizeDebounceTimer = setTimeout(() => { |
| 234 | this.fit(); |
| 235 | }, RESIZE_DEBOUNCE_MS); |
| 236 | }); |
| 237 | |
| 238 | // Observe the terminal element itself (the container we want to fit into) |
| 239 | // This gives us stable resize events when the CONTAINER changes, not when our canvas changes |
| 240 | this._resizeObserver.observe(this._terminal.element); |
| 241 | } |
| 242 | } |