未验证 提交 bffa4045 编写于 作者: T Tyler James Leonhardt 提交者: GitHub

Have TentativeBoundary trigger rollback (#112510)

* have TentativeBoundary trigger rollback

* add test

* simplify test

* add additional test
上级 9f27d99a
......@@ -330,7 +330,8 @@ class TentativeBoundary implements IPrediction {
return '';
}
public rollback() {
public rollback(cursor: Cursor) {
this.inner.rollback(cursor);
return '';
}
......
......@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { Terminal } from 'xterm';
import { IBuffer, Terminal } from 'xterm';
import { SinonStub, stub, useFakeTimers } from 'sinon';
import { Emitter } from 'vs/base/common/event';
import { CharPredictState, IPrediction, PredictionStats, TypeAheadAddon } from 'vs/workbench/contrib/terminal/browser/terminalTypeAheadAddon';
......@@ -14,6 +14,11 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
const CSI = `\x1b[`;
const enum CursorMoveDirection {
Back = 'D',
Forwards = 'C',
}
suite('Workbench - Terminal Typeahead', () => {
suite('PredictionStats', () => {
let stats: PredictionStats;
......@@ -139,6 +144,42 @@ suite('Workbench - Terminal Typeahead', () => {
assert.strictEqual(addon.stats?.accuracy, 0);
});
test('handles left arrow when we hit the boundary', () => {
const t = createMockTerminal({ lines: ['|'] });
addon.activate(t.terminal);
addon.unlockLeftNavigating();
const cursorXBefore = addon.getCursor(t.terminal.buffer.active)?.x!;
t.onData(`${CSI}${CursorMoveDirection.Back}`);
t.expectWritten('');
// Trigger rollback because we don't expect this data
onBeforeProcessData.fire({ data: 'xy' });
assert.strictEqual(
addon.getCursor(t.terminal.buffer.active)?.x,
// The cursor should not have changed because we've hit the
// boundary (start of prompt)
cursorXBefore);
});
test('internal cursor state is reset when all predictions are undone', () => {
const t = createMockTerminal({ lines: ['|'] });
addon.activate(t.terminal);
addon.unlockLeftNavigating();
const cursorXBefore = addon.getCursor(t.terminal.buffer.active)?.x!;
t.onData(`${CSI}${CursorMoveDirection.Back}`);
t.expectWritten('');
addon.undoAllPredictions();
assert.strictEqual(
addon.getCursor(t.terminal.buffer.active)?.x,
// The cursor should not have changed because we've hit the
// boundary (start of prompt)
cursorXBefore);
});
test('restores cursor graphics mode', () => {
const t = createMockTerminal({
lines: ['hello|'],
......@@ -296,6 +337,14 @@ class TestTypeAheadAddon extends TypeAheadAddon {
public get isShowing() {
return !!this.timeline?.isShowingPredictions;
}
public undoAllPredictions() {
this.timeline?.undoAllPredictions();
}
public getCursor(buffer: IBuffer) {
return this.timeline?.getCursor(buffer);
}
}
function upcastPartial<T>(v: Partial<T>): T {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册