summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/components/shared/text-buffer.ts
diff options
context:
space:
mode:
authorJacob Richman <[email protected]>2025-07-31 16:16:29 -0700
committerGitHub <[email protected]>2025-07-31 23:16:29 +0000
commit61e382444a69409b066a6c8382379f86492d579f (patch)
tree9f66858195607aea50eb421a581d5cd934fe56b9 /packages/cli/src/ui/components/shared/text-buffer.ts
parent32809a7be795b974506b893a179091a83b285b7b (diff)
fix(ux) bug in replaceRange dealing with newLines that was breaking vim support (#5320)
Diffstat (limited to 'packages/cli/src/ui/components/shared/text-buffer.ts')
-rw-r--r--packages/cli/src/ui/components/shared/text-buffer.ts35
1 files changed, 16 insertions, 19 deletions
diff --git a/packages/cli/src/ui/components/shared/text-buffer.ts b/packages/cli/src/ui/components/shared/text-buffer.ts
index d2d9087a..cf5ce889 100644
--- a/packages/cli/src/ui/components/shared/text-buffer.ts
+++ b/packages/cli/src/ui/components/shared/text-buffer.ts
@@ -271,26 +271,23 @@ export const replaceRangeInternal = (
.replace(/\r/g, '\n');
const replacementParts = normalisedReplacement.split('\n');
- // Replace the content
- if (startRow === endRow) {
- newLines[startRow] = prefix + normalisedReplacement + suffix;
+ // The combined first line of the new text
+ const firstLine = prefix + replacementParts[0];
+
+ if (replacementParts.length === 1) {
+ // No newlines in replacement: combine prefix, replacement, and suffix on one line.
+ newLines.splice(startRow, endRow - startRow + 1, firstLine + suffix);
} else {
- const firstLine = prefix + replacementParts[0];
- if (replacementParts.length === 1) {
- // Single line of replacement text, but spanning multiple original lines
- newLines.splice(startRow, endRow - startRow + 1, firstLine + suffix);
- } else {
- // Multi-line replacement text
- const lastLine = replacementParts[replacementParts.length - 1] + suffix;
- const middleLines = replacementParts.slice(1, -1);
- newLines.splice(
- startRow,
- endRow - startRow + 1,
- firstLine,
- ...middleLines,
- lastLine,
- );
- }
+ // Newlines in replacement: create new lines.
+ const lastLine = replacementParts[replacementParts.length - 1] + suffix;
+ const middleLines = replacementParts.slice(1, -1);
+ newLines.splice(
+ startRow,
+ endRow - startRow + 1,
+ firstLine,
+ ...middleLines,
+ lastLine,
+ );
}
const finalCursorRow = startRow + replacementParts.length - 1;