TypeScript
perf(server): colored terminal output no longer copies history one character at a time (#21209)
Alyxc6dfda8e56d3
diff --git a/apps/server/src/terminal/Manager.ts b/apps/server/src/terminal/Manager.tsindex 0be928ce98a..3bb561aef25 100644--- a/apps/server/src/terminal/Manager.ts+++ b/apps/server/src/terminal/Manager.ts@@ -1061,6 +1061,7 @@ function findEscapeSequenceEndIndex(input: string, start: number): number | null// eslint-disable-next-line no-control-regex -- Terminal sequence introducers must reach the parser.const HISTORY_SEQUENCE_START = /[\u001b\u0090\u009b\u009d\u009e\u009f]/;+const NEXT_HISTORY_SEQUENCE_START = new RegExp(HISTORY_SEQUENCE_START.source, "g");function sanitizeTerminalHistoryChunk(pendingControlSequence: string,@@ -1175,8 +1176,11 @@ function sanitizeTerminalHistoryChunk(continue;}- append(input[index] ?? "");- index += 1;+ // One slice per printable run: every chunk of coloured output reaches this loop.+ NEXT_HISTORY_SEQUENCE_START.lastIndex = index + 1;+ const nextSequenceStart = NEXT_HISTORY_SEQUENCE_START.exec(input)?.index ?? input.length;+ append(input.slice(index, nextSequenceStart));+ index = nextSequenceStart;}return { visibleText, pendingControlSequence: "" };