All three paste paths (hotkey, context menu, middle-click) were sending raw clipboard text directly to the session backend via writeToSession(), bypassing xterm's built-in term.paste() which handles bracketed paste wrapping. When a remote application like vim enables bracketed paste mode (CSI ?2004h), pasted text must be wrapped in \e[200~ / \e[201~ so the application can distinguish paste from typed input. Without these markers, vim's autoindent treats each pasted newline as a manual Enter keypress, causing indentation to accumulate progressively with each line (the "staircase effect"). Now checks term.modes.bracketedPasteMode before sending and wraps the text accordingly on all paste paths. Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
36 lines
1.1 KiB
TypeScript
Executable File
36 lines
1.1 KiB
TypeScript
Executable File
import { type ClassValue, clsx } from "clsx"
|
|
import { twMerge } from "tailwind-merge"
|
|
|
|
export function cn(...inputs: ClassValue[]) {
|
|
return twMerge(clsx(inputs))
|
|
}
|
|
|
|
/**
|
|
* Normalize line endings to LF (Unix style).
|
|
* Converts CRLF (Windows) and standalone CR (old Mac) to LF.
|
|
* Used for clipboard paste operations in terminal to avoid extra blank lines.
|
|
*/
|
|
export function normalizeLineEndings(text: string): string {
|
|
return text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
}
|
|
|
|
/**
|
|
* Wrap text in bracketed paste escape sequences.
|
|
* When a terminal application enables bracketed paste mode (CSI ?2004h),
|
|
* pasted text should be wrapped so the application can distinguish paste
|
|
* from typed input (e.g. vim disables autoindent during paste).
|
|
*/
|
|
export function wrapBracketedPaste(text: string): string {
|
|
return `\x1b[200~${text}\x1b[201~`;
|
|
}
|
|
|
|
/**
|
|
* Detect if the current platform is macOS.
|
|
* Used for keyboard shortcut handling to differentiate between Mac and PC shortcuts.
|
|
*/
|
|
export function isMacPlatform(): boolean {
|
|
if (typeof navigator !== 'undefined') {
|
|
return /Mac|iPod|iPhone|iPad/.test(navigator.platform);
|
|
}
|
|
return false;
|
|
} |