提交 c68ad4f5 编写于 作者: D Daniel Imms

Use new event api

上级 488e986f
......@@ -30,7 +30,7 @@ export class TerminalCommandTracker implements ITerminalCommandTracker, IDisposa
constructor(
private _xterm: Terminal
) {
this._xterm.on('key', key => this._onKey(key));
this._xterm.onKey(e => this._onKey(e.key));
}
public dispose(): void {
......
......@@ -371,7 +371,7 @@ export class TerminalInstance implements ITerminalInstance {
// it gets removed and then added back to the DOM (resetting scrollTop to 0).
// Upstream issue: https://github.com/sourcelair/xterm.js/issues/291
if (this._xterm) {
this._xterm.emit('scroll', this._xterm._core.buffer.ydisp);
this._xterm._core._onScroll.fire(this._xterm._core.buffer.ydisp);
}
}
......@@ -421,12 +421,12 @@ export class TerminalInstance implements ITerminalInstance {
if (this._shellLaunchConfig.initialText) {
this._xterm.writeln(this._shellLaunchConfig.initialText);
}
this._xterm.on('linefeed', () => this._onLineFeed());
this._xterm.on('key', (key, ev) => this._onKey(key, ev));
this._xterm.onLineFeed(() => this._onLineFeed());
this._xterm.onKey(e => this._onKey(e.key, e.domEvent));
if (this._processManager) {
this._processManager.onProcessData(data => this._onProcessData(data));
this._xterm.on('data', data => this._processManager!.write(data));
this._xterm.onData(data => this._processManager!.write(data));
// TODO: How does the cwd work on detached processes?
this.processReady.then(async () => {
this._linkHandler.processCwd = await this._processManager!.getInitialCwd();
......@@ -445,11 +445,11 @@ export class TerminalInstance implements ITerminalInstance {
} else if (this.shellLaunchConfig.isRendererOnly) {
this._linkHandler = this._instantiationService.createInstance(TerminalLinkHandler, this._xterm, undefined, undefined);
}
this._xterm.on('focus', () => this._onFocus.fire(this));
this._xterm.textarea.addEventListener('focus', () => this._onFocus.fire(this));
// Register listener to trigger the onInput ext API if the terminal is a renderer only
if (this._shellLaunchConfig.isRendererOnly) {
this._xterm.on('data', (data) => this._sendRendererInput(data));
this._xterm.onData(data => this._sendRendererInput(data));
}
this._commandTracker = new TerminalCommandTracker(this._xterm);
......@@ -858,7 +858,7 @@ export class TerminalInstance implements ITerminalInstance {
// necessary if the number of rows in the terminal has decreased while it was in the
// background since scrollTop changes take no effect but the terminal's position does
// change since the number of visible rows decreases.
this._xterm.emit('scroll', this._xterm._core.buffer.ydisp);
this._xterm._core._onScroll.fire(this._xterm._core.buffer.ydisp);
if (this._container && this._container.parentElement) {
// Force a layout when the instance becomes invisible. This is particularly important
// for ensuring that terminals that are created in the background by an extension will
......
......@@ -61,15 +61,15 @@ export class WindowsShellHelper implements IWindowsShellHelper {
// If this is done on every linefeed, parsing ends up taking
// significantly longer due to resetting timers. Note that this is
// private API.
this._xterm.on('linefeed', () => this._newLineFeed = true);
this._xterm.on('cursormove', () => {
this._xterm.onLineFeed(() => this._newLineFeed = true);
this._xterm.onCursorMove(() => {
if (this._newLineFeed) {
this._onCheckShell.fire(undefined);
}
});
// Fire a new check for the shell when any key is pressed.
this._xterm.on('keypress', () => this._onCheckShell.fire(undefined));
this._xterm.onKey(() => this._onCheckShell.fire(undefined));
});
}
......
......@@ -46,13 +46,13 @@ suite('Workbench - TerminalCommandTracker', () => {
test('should track commands when the prompt is of sufficient size', () => {
assert.equal(xterm.markers.length, 0);
syncWrite(xterm, '\x1b[3G'); // Move cursor to column 3
xterm.emit('key', '\x0d');
xterm._core._onKey.fire({ key: '\x0d' });
assert.equal(xterm.markers.length, 1);
});
test('should not track commands when the prompt is too small', () => {
assert.equal(xterm.markers.length, 0);
syncWrite(xterm, '\x1b[2G'); // Move cursor to column 2
xterm.emit('key', '\x0d');
xterm._core._onKey.fire({ key: '\x0d' });
assert.equal(xterm.markers.length, 0);
});
});
......@@ -60,7 +60,7 @@ suite('Workbench - TerminalCommandTracker', () => {
suite('Commands', () => {
test('should scroll to the next and previous commands', () => {
syncWrite(xterm, '\x1b[3G'); // Move cursor to column 3
xterm.emit('key', '\x0d'); // Mark line #10
xterm._core._onKey.fire({ key: '\x0d' }); // Mark line #10
assert.equal(xterm.markers[0].line, 9);
for (let i = 0; i < 20; i++) {
......@@ -94,11 +94,11 @@ suite('Workbench - TerminalCommandTracker', () => {
syncWrite(xterm, '\r0');
syncWrite(xterm, '\n\r1');
syncWrite(xterm, '\x1b[3G'); // Move cursor to column 3
xterm.emit('key', '\x0d'); // Mark line
xterm._core._onKey.fire({ key: '\x0d' }); // Mark line
assert.equal(xterm.markers[0].line, 10);
syncWrite(xterm, '\n\r2');
syncWrite(xterm, '\x1b[3G'); // Move cursor to column 3
xterm.emit('key', '\x0d'); // Mark line
xterm._core._onKey.fire({ key: '\x0d' }); // Mark line
assert.equal(xterm.markers[1].line, 11);
syncWrite(xterm, '\n\r3');
......@@ -124,11 +124,11 @@ suite('Workbench - TerminalCommandTracker', () => {
syncWrite(xterm, '\r0');
syncWrite(xterm, '\n\r1');
syncWrite(xterm, '\x1b[3G'); // Move cursor to column 3
xterm.emit('key', '\x0d'); // Mark line
xterm._core._onKey.fire({ key: '\x0d' }); // Mark line
assert.equal(xterm.markers[0].line, 10);
syncWrite(xterm, '\n\r2');
syncWrite(xterm, '\x1b[3G'); // Move cursor to column 3
xterm.emit('key', '\x0d'); // Mark line
xterm._core._onKey.fire({ key: '\x0d' }); // Mark line
assert.equal(xterm.markers[1].line, 11);
syncWrite(xterm, '\n\r3');
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册