@@ -19,6 +19,7 @@ import { ESC } from '../utils/input.js';
1919import { parseMouseEvent } from '../utils/mouse.js' ;
2020import { FOCUS_IN , FOCUS_OUT } from '../hooks/useFocus.js' ;
2121import { appEvents , AppEvent } from '../../utils/events.js' ;
22+ import { terminalCapabilityManager } from '../utils/terminalCapabilityManager.js' ;
2223
2324export const BACKSLASH_ENTER_TIMEOUT = 5 ;
2425export const ESC_TIMEOUT = 50 ;
@@ -143,6 +144,30 @@ function nonKeyboardEventFilter(
143144 } ;
144145}
145146
147+ /**
148+ * Converts return keys pressed quickly after other keys into plain
149+ * insertable return characters.
150+ *
151+ * This is to accommodate older terminals that paste text without bracketing.
152+ */
153+ function bufferFastReturn ( keypressHandler : KeypressHandler ) : KeypressHandler {
154+ let lastKeyTime = 0 ;
155+ return ( key : Key ) => {
156+ const now = Date . now ( ) ;
157+ if ( key . name === 'return' && now - lastKeyTime <= FAST_RETURN_TIMEOUT ) {
158+ keypressHandler ( {
159+ ...key ,
160+ name : '' ,
161+ sequence : '\r' ,
162+ insertable : true ,
163+ } ) ;
164+ } else {
165+ keypressHandler ( key ) ;
166+ }
167+ lastKeyTime = now ;
168+ } ;
169+ }
170+
146171/**
147172 * Buffers "/" keys to see if they are followed return.
148173 * Will flush the buffer if no data is received for DRAG_COMPLETION_TIMEOUT_MS
@@ -641,6 +666,9 @@ export function KeypressProvider({
641666 process . stdin . setEncoding ( 'utf8' ) ; // Make data events emit strings
642667
643668 let processor = nonKeyboardEventFilter ( broadcast ) ;
669+ if ( ! terminalCapabilityManager . isKittyProtocolEnabled ( ) ) {
670+ processor = bufferFastReturn ( processor ) ;
671+ }
644672 processor = bufferBackslashEnter ( processor ) ;
645673 processor = bufferPaste ( processor ) ;
646674 let dataListener = createDataListener ( processor ) ;
0 commit comments