Skip to content

Commit 5f31504

Browse files
committed
Update on write parsed as well
1 parent 5e1674b commit 5f31504

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { Emitter, type Event } from 'vs/base/common/event';
6+
import { Emitter, Event } from 'vs/base/common/event';
77
import { Disposable } from 'vs/base/common/lifecycle';
88
import { ILogService, LogLevel } from 'vs/platform/log/common/log';
99
import type { ITerminalCommand } from 'vs/platform/terminal/common/capabilities/capabilities';
10-
import { debounce } from 'vs/base/common/decorators';
10+
import { throttle } from 'vs/base/common/decorators';
1111

1212
// Importing types is safe in any layer
1313
// eslint-disable-next-line local/code-import-patterns
@@ -67,7 +67,11 @@ export class PromptInputModel extends Disposable implements IPromptInputModel {
6767
super();
6868

6969
this._register(this._xterm.onData(e => this._handleInput(e)));
70-
this._register(this._xterm.onCursorMove(() => this._sync()));
70+
this._register(Event.any(
71+
// TODO: Upstream me to headless
72+
(this._xterm as any).onWriteParsed,
73+
this._xterm.onCursorMove,
74+
)(() => this._sync()));
7175

7276
this._register(onCommandStart(e => this._handleCommandStart(e as { marker: IMarker })));
7377
this._register(onCommandExecuted(() => this._handleCommandExecuted()));
@@ -115,7 +119,7 @@ export class PromptInputModel extends Disposable implements IPromptInputModel {
115119
this._sync();
116120
}
117121

118-
@debounce(50)
122+
@throttle(0)
119123
private _sync() {
120124
this._syncNow();
121125
}

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type { ITerminalCommand } from 'vs/platform/terminal/common/capabilities/
1212
// eslint-disable-next-line local/code-import-patterns, local/code-amd-node-module
1313
import { Terminal } from '@xterm/headless';
1414
import { strictEqual } from 'assert';
15+
import { timeout } from 'vs/base/common/async';
1516

1617
class TestPromptInputModel extends PromptInputModel {
1718
forceSync() {
@@ -285,6 +286,42 @@ suite('PromptInputModel', () => {
285286
fireCommandStart();
286287
assertPromptInput('|');
287288
});
289+
290+
test.only('input, go to start (ctrl+home), delete word in front (ctrl+delete)', async () => {
291+
await replayEvents([
292+
'[?25l]0;C:\Program Files\WindowsApps\Microsoft.PowerShell_7.4.2.0_x64__8wekyb3d8bbwe\pwsh.exe[?25h',
293+
'[?25l\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n[?25h',
294+
']633;P;IsWindows=True',
295+
']633;P;ContinuationPrompt=\x1b[38\x3b5\x3b8m∙\x1b[0m ',
296+
']633;A]633;P;Cwd=C:\x5cGithub\x5cmicrosoft\x5cvscode]633;B',
297+
'\r\n16:07:06  vscode   tyriar/210662  $!  via  v18.18.2 \r\n❯ ',
298+
]);
299+
fireCommandStart();
300+
assertPromptInput('|');
301+
302+
await replayEvents([
303+
'[?25lGit push[?25h',
304+
'',
305+
'[?25lGet-ChildItem -Path a[?25h',
306+
'',
307+
'[?25lGet-ChildItem -Path a[?25h',
308+
]);
309+
assertPromptInput('Get|[-ChildItem -Path a]');
310+
311+
await replayEvents([
312+
'',
313+
'[?25l[?25h',
314+
'',
315+
]);
316+
317+
// Don't force a sync, the prompt input model should update by itself
318+
await timeout(0);
319+
const actualValueWithCursor = promptInputModel.getCombinedString();
320+
strictEqual(
321+
actualValueWithCursor,
322+
'|'.replaceAll('\n', '\u23CE')
323+
);
324+
});
288325
});
289326
});
290327
});

0 commit comments

Comments
 (0)