Skip to content

Commit a6628d5

Browse files
authored
Assistant: Improves inline chat text editing (#10911)
Fixes an issue in Assistant's streaming text replacement logic when inserting text across multiple lines in inline chat. The existing logic did not reset the insertion position's character location when moving to a new line, leading to text being inserted mid-way through a line - possibly interposing with existing text. Addresses #10914
1 parent 6c59780 commit a6628d5

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

extensions/positron-assistant/src/replaceSelectionProcessor.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,12 @@ export class ReplaceSelectionProcessor {
102102
const lines = text.split(/\r?\n/);
103103
const lineDelta = lines.length - 1;
104104
const characterDelta = lines.at(-1)!.length;
105-
this._insertPosition = this._insertPosition!.translate(lineDelta, characterDelta);
105+
if (lineDelta === 0) {
106+
this._insertPosition = this._insertPosition!.translate(lineDelta, characterDelta);
107+
} else {
108+
// If we added new lines, reset the character position to the length of the last line.
109+
this._insertPosition = this._insertPosition.translate({ lineDelta }).with({ character: characterDelta });
110+
}
106111
}
107112

108113
private onReplaceSelectionClose(): void {

0 commit comments

Comments
 (0)