MCPcopy Create free account
hub / github.com/coder/ghostty-web / observeResize

Method observeResize

lib/addons/fit.ts:207–241  ·  view source on GitHub ↗

* 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.

()

Source from the content-addressed store, hash-verified

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}

Callers 1

fit.test.tsFile · 0.80

Calls 1

fitMethod · 0.95

Tested by

no test coverage detected