(input: string)
| 333 | |
| 334 | // Fallback paste detection: detects rapid chunks by timing and size RAPID_INPUT_THRESHOLD |
| 335 | private handleRapidInput(input: string): boolean { |
| 336 | const now = Date.now(); |
| 337 | const timeSinceLastInput = now - this._lastInputTime; |
| 338 | |
| 339 | // If we're already in rapid input mode and this comes quickly, add to buffer |
| 340 | if (this._rapidInputBuffer.length > 0 && timeSinceLastInput < 200) { |
| 341 | const isLikelyTyping = input.length < 50 && timeSinceLastInput >= 50; |
| 342 | |
| 343 | if (!isLikelyTyping) { |
| 344 | this._rapidInputBuffer += input; |
| 345 | this._lastInputTime = now; |
| 346 | |
| 347 | if (this._rapidInputTimer) { |
| 348 | clearTimeout(this._rapidInputTimer); |
| 349 | } |
| 350 | |
| 351 | // Reset timer: 200ms pause indicates end of paste |
| 352 | this._rapidInputTimer = setTimeout(() => { |
| 353 | this.finalizeRapidInput(); |
| 354 | }, 200); |
| 355 | |
| 356 | return true; |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | // Fallback paste detection: some terminals send large pastes as rapid chunks |
| 361 | // instead of using bracketed paste mode. We detect this by timing between inputs. |
| 362 | // The >= 50 char threshold was restored to detect Terminal.app/Ghostty split pastes |
| 363 | if ( |
| 364 | input.length > RAPID_INPUT_THRESHOLD || |
| 365 | (input.length >= 50 && this._rapidInputBuffer.length === 0) |
| 366 | ) { |
| 367 | this._rapidInputStartPos = this._cursor; |
| 368 | |
| 369 | // Accumulate chunks without inserting to avoid visual flicker |
| 370 | this._rapidInputBuffer = input; |
| 371 | this._lastInputTime = now; |
| 372 | |
| 373 | if (this._rapidInputTimer) { |
| 374 | clearTimeout(this._rapidInputTimer); |
| 375 | } |
| 376 | |
| 377 | // 200ms pause indicates end of paste |
| 378 | this._rapidInputTimer = setTimeout(() => { |
| 379 | this.finalizeRapidInput(); |
| 380 | }, 200); |
| 381 | |
| 382 | return true; // Consume input without inserting until finalized |
| 383 | } |
| 384 | |
| 385 | this._lastInputTime = now; |
| 386 | return false; |
| 387 | } |
| 388 | |
| 389 | // Called after rapid input timer expires to collapse or insert buffered content |
| 390 | private finalizeRapidInput(): void { |
no test coverage detected