mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-21 10:00:39 +00:00
fix(tui): refactor the multi-line insertion handling
This commit is contained in:
parent
7d2d170c1b
commit
609095b0b6
1 changed files with 12 additions and 19 deletions
|
|
@ -849,30 +849,23 @@ export class Editor implements Component, Focusable {
|
||||||
this.state.cursorCol += normalized.length;
|
this.state.cursorCol += normalized.length;
|
||||||
} else {
|
} else {
|
||||||
// Multi-line insertion
|
// Multi-line insertion
|
||||||
const newLines: string[] = [];
|
this.state.lines = [
|
||||||
|
// All lines before current line
|
||||||
|
...this.state.lines.slice(0, this.state.cursorLine),
|
||||||
|
|
||||||
// Add all lines before current line
|
// The first inserted line merged with text before cursor
|
||||||
for (let i = 0; i < this.state.cursorLine; i++) {
|
beforeCursor + insertedLines[0],
|
||||||
newLines.push(this.state.lines[i] || "");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the first inserted line merged with text before cursor
|
// All middle inserted lines
|
||||||
newLines.push(beforeCursor + (insertedLines[0] || ""));
|
...insertedLines.slice(1, -1),
|
||||||
|
|
||||||
// Add all middle inserted lines
|
// The last inserted line with text after cursor
|
||||||
for (let i = 1; i < insertedLines.length - 1; i++) {
|
insertedLines[insertedLines.length - 1] + afterCursor,
|
||||||
newLines.push(insertedLines[i] || "");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the last inserted line with text after cursor
|
// All lines after current line
|
||||||
newLines.push((insertedLines[insertedLines.length - 1] || "") + afterCursor);
|
...this.state.lines.slice(this.state.cursorLine + 1),
|
||||||
|
];
|
||||||
|
|
||||||
// Add all lines after current line
|
|
||||||
for (let i = this.state.cursorLine + 1; i < this.state.lines.length; i++) {
|
|
||||||
newLines.push(this.state.lines[i] || "");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.state.lines = newLines;
|
|
||||||
this.state.cursorLine += insertedLines.length - 1;
|
this.state.cursorLine += insertedLines.length - 1;
|
||||||
this.state.cursorCol = (insertedLines[insertedLines.length - 1] || "").length;
|
this.state.cursorCol = (insertedLines[insertedLines.length - 1] || "").length;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue