Skip to content

Commit 6ceb862

Browse files
committed
PromptInputModel: Ensure ghostTextIndex >= cursorIndex
1 parent 5d09b38 commit 6ceb862

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/vs/platform/terminal/common/capabilities/commandDetection/promptInputModel.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export class PromptInputModel extends Disposable implements IPromptInputModel {
150150
// non-italic/dim text in the cell closest non-whitespace cell before the cursor
151151
if (absoluteCursorY === commandStartY && buffer.cursorX > 1) {
152152
// Ghost text in pwsh only appears to happen on the cursor line
153-
ghostTextIndex = this._scanForGhostText(buffer, line);
153+
ghostTextIndex = this._scanForGhostText(buffer, line, cursorIndex);
154154
}
155155

156156
// IDEA: Detect line continuation if it's not set
@@ -184,6 +184,8 @@ export class PromptInputModel extends Disposable implements IPromptInputModel {
184184
} else {
185185
break;
186186
}
187+
} else {
188+
break;
187189
}
188190
}
189191

@@ -203,7 +205,7 @@ export class PromptInputModel extends Disposable implements IPromptInputModel {
203205
* Detect ghost text by looking for italic or dim text in or after the cursor and
204206
* non-italic/dim text in the cell closest non-whitespace cell before the cursor.
205207
*/
206-
private _scanForGhostText(buffer: IBuffer, line: IBufferLine): number {
208+
private _scanForGhostText(buffer: IBuffer, line: IBufferLine, cursorIndex: number): number {
207209
// Check last non-whitespace character has non-ghost text styles
208210
let ghostTextIndex = -1;
209211
let proceedWithGhostTextCheck = false;
@@ -230,7 +232,7 @@ export class PromptInputModel extends Disposable implements IPromptInputModel {
230232
break;
231233
}
232234
if (this._isCellStyledLikeGhostText(cell)) {
233-
ghostTextIndex = this._cursorIndex + potentialGhostIndexOffset;
235+
ghostTextIndex = cursorIndex + potentialGhostIndexOffset;
234236
break;
235237
}
236238
potentialGhostIndexOffset += cell.getChars().length;

0 commit comments

Comments
 (0)