Skip to content

Commit ca9fa4f

Browse files
authored
prevent right prompt from being considered ghost text (#269732)
fix #269730
1 parent 32064a7 commit ca9fa4f

4 files changed

Lines changed: 11 additions & 9 deletions

File tree

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,11 @@ export class PromptInputModel extends Disposable implements IPromptInputModel {
546546
// Retrieve the positions of all cells with the same style as `lastNonWhitespaceCell`
547547
const positionsWithGhostStyle = styleMap.get(this._getCellStyleAsString(lastNonWhitespaceCell));
548548
if (positionsWithGhostStyle) {
549+
// Ghost text must start at the cursor or one char after (e.g. a space),
550+
// preventing right-prompt styles from being misdetected as ghost text.
551+
if (positionsWithGhostStyle[0] > buffer.cursorX + 1) {
552+
return -1;
553+
}
549554
// Ensure these positions are contiguous
550555
for (let i = 1; i < positionsWithGhostStyle.length; i++) {
551556
if (positionsWithGhostStyle[i] !== positionsWithGhostStyle[i - 1] + 1) {

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,6 @@ suite('PromptInputModel', () => {
215215

216216
await writePromise('foo\x1b[38;2;255;0;0m bar\x1b[0m\x1b[4D');
217217
await assertPromptInput('foo|[ bar]');
218-
219-
await writePromise('\x1b[2D');
220-
await assertPromptInput('f|oo[ bar]');
221218
});
222219
test('no ghost text when foreground color matches earlier text', async () => {
223220
await writePromise('$ ');

src/vs/workbench/contrib/terminal/test/browser/xterm/recordings/basic/macos_zsh_p10k_ls_one_time.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const events = [
3535
},
3636
{
3737
"type": "promptInputChange",
38-
"data": "| [─╯]"
38+
"data": "| ─╯"
3939
},
4040
{
4141
"type": "input",
@@ -47,7 +47,7 @@ export const events = [
4747
},
4848
{
4949
"type": "promptInputChange",
50-
"data": "l| [─╯]"
50+
"data": "l| ─╯"
5151
},
5252
{
5353
"type": "input",
@@ -59,7 +59,7 @@ export const events = [
5959
},
6060
{
6161
"type": "promptInputChange",
62-
"data": "ls| [─╯]"
62+
"data": "ls| ─╯"
6363
},
6464
{
6565
"type": "input",
@@ -71,7 +71,7 @@ export const events = [
7171
},
7272
{
7373
"type": "promptInputChange",
74-
"data": "ls "
74+
"data": "ls ─╯"
7575
},
7676
{
7777
"type": "output",

src/vs/workbench/contrib/terminal/test/browser/xterm/recordings/rich/windows11_pwsh7_echo_3_times.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ export const events = [
324324
},
325325
{
326326
"type": "promptInputChange",
327-
"data": "echo b|[]"
327+
"data": "echo b|"
328328
},
329329
{
330330
"type": "output",
@@ -491,7 +491,7 @@ export const events = [
491491
},
492492
{
493493
"type": "promptInputChange",
494-
"data": "echo c|[]"
494+
"data": "echo c|"
495495
},
496496
{
497497
"type": "output",

0 commit comments

Comments
 (0)