Skip to content

Commit 7e9d977

Browse files
committed
Test ghost text in simple unit test
1 parent 36e5971 commit 7e9d977

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,16 +217,18 @@ export class PromptInputModel extends Disposable implements IPromptInputModel {
217217
// Check to the end of the line for possible ghost text. For example pwsh's ghost text
218218
// can look like this `Get-|Ch[ildItem]`
219219
if (proceedWithGhostTextCheck) {
220+
let potentialGhostIndexOffset = 0;
220221
let x = buffer.cursorX;
221222
while (x < line.length) {
222223
const cell = line.getCell(x++);
223224
if (!cell || cell.getCode() === 0) {
224225
break;
225226
}
226227
if (this._isCellStyledLikeGhostText(cell)) {
227-
ghostTextIndex = this._cursorIndex;
228+
ghostTextIndex = this._cursorIndex + potentialGhostIndexOffset;
228229
break;
229230
}
231+
potentialGhostIndexOffset += cell.getChars().length;
230232
}
231233
}
232234

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ suite('PromptInputModel', () => {
4848

4949
const actualValueWithCursor = promptInputModel.getCombinedString();
5050
strictEqual(
51-
actualValueWithCursor.replaceAll('\n', '\u23CE'),
51+
actualValueWithCursor,
5252
valueWithCursor.replaceAll('\n', '\u23CE')
5353
);
5454

@@ -110,6 +110,18 @@ suite('PromptInputModel', () => {
110110
assertPromptInput('foo bar|');
111111
});
112112

113+
test('ghost text', async () => {
114+
await writePromise('$ ');
115+
fireCommandStart();
116+
assertPromptInput('|');
117+
118+
await writePromise('foo\x1b[2m bar\x1b[0m\x1b[4D');
119+
assertPromptInput('foo|[ bar]');
120+
121+
await writePromise('\x1b[2D');
122+
assertPromptInput('f|oo[ bar]');
123+
});
124+
113125
test('wide input (Korean)', async () => {
114126
await writePromise('$ ');
115127
fireCommandStart();

0 commit comments

Comments
 (0)