Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support alt+enter key signal by default #2718

Merged
merged 6 commits into from
Apr 11, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/InputHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1788,6 +1788,9 @@ export class InputHandler extends Disposable implements IInputHandler {
case 25: // show cursor
this._coreService.isCursorHidden = false;
break;
case 1039:
this._coreService.decPrivateModes.altEnterMode = true;
break;
case 1048: // alt screen cursor
this.saveCursor();
break;
Expand Down Expand Up @@ -2003,6 +2006,9 @@ export class InputHandler extends Disposable implements IInputHandler {
case 25: // hide cursor
this._coreService.isCursorHidden = true;
break;
case 1039:
this._coreService.decPrivateModes.altEnterMode = false;
break;
case 1048: // alt screen cursor
this.restoreCursor();
break;
Expand Down
2 changes: 1 addition & 1 deletion src/Terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
return false;
}

const result = evaluateKeyboardEvent(event, this._coreService.decPrivateModes.applicationCursorKeys, this.browser.isMac, this.options.macOptionIsMeta);
const result = evaluateKeyboardEvent(event, this._coreService.decPrivateModes.altEnterMode, this._coreService.decPrivateModes.applicationCursorKeys, this.browser.isMac, this.options.macOptionIsMeta);

this.updateCursorStyle(event);

Expand Down
1 change: 1 addition & 0 deletions src/common/TestUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export class MockCoreService implements ICoreService {
isCursorHidden: boolean = false;
isFocused: boolean = false;
decPrivateModes: IDecPrivateModes = {
altEnterMode: true,
applicationCursorKeys: false,
applicationKeypad: false,
origin: false,
Expand Down
1 change: 1 addition & 0 deletions src/common/Types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export interface IMarker extends IDisposable {
}

export interface IDecPrivateModes {
altEnterMode: boolean;
applicationCursorKeys: boolean;
applicationKeypad: boolean;
origin: boolean;
Expand Down
7 changes: 6 additions & 1 deletion src/common/input/Keyboard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function testEvaluateKeyboardEvent(partialEvent: {
key?: string;
type?: string;
}, partialOptions: {
altEnterMode?: boolean;
applicationCursorMode?: boolean;
isMac?: boolean;
macOptionIsMeta?: boolean;
Expand All @@ -30,11 +31,12 @@ function testEvaluateKeyboardEvent(partialEvent: {
type: partialEvent.type || ''
};
const options = {
altEnterMode: partialOptions.altEnterMode || true,
applicationCursorMode: partialOptions.applicationCursorMode || false,
isMac: partialOptions.isMac || false,
macOptionIsMeta: partialOptions.macOptionIsMeta || false
};
return evaluateKeyboardEvent(event, options.applicationCursorMode, options.isMac, options.macOptionIsMeta);
return evaluateKeyboardEvent(event, options.altEnterMode, options.applicationCursorMode, options.isMac, options.macOptionIsMeta);
}

describe('Keyboard', () => {
Expand Down Expand Up @@ -86,6 +88,9 @@ describe('Keyboard', () => {
it('should return \\x1b[3;3~ for alt+delete', () => {
assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 46 }).key, '\x1b[3;3~');
});
it('should return \\x1b\\r for alt+enter', () => {
assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 13 }).key, '\x1b\r');
});
it('should return \\x1b[5D for ctrl+left', () => {
assert.equal(testEvaluateKeyboardEvent({ ctrlKey: true, keyCode: 37 }).key, '\x1b[1;5D'); // CSI 5 D
});
Expand Down
8 changes: 7 additions & 1 deletion src/common/input/Keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const KEYCODE_KEY_MAPPINGS: { [key: number]: [string, string]} = {

export function evaluateKeyboardEvent(
ev: IKeyboardEvent,
altEnterMode: boolean,
applicationCursorMode: boolean,
isMac: boolean,
macOptionIsMeta: boolean
Expand Down Expand Up @@ -103,7 +104,12 @@ export function evaluateKeyboardEvent(
break;
case 13:
// return/enter
result.key = C0.CR;
if (altEnterMode && modifiers === 2) {
result.key = C0.ESC + C0.CR;
}
else {
result.key = C0.CR;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not tested xterm's behavior, but I think DECSET 1039 is meant to switch the leading ESC on/off for any key? Thus we would have to extend the flag to other keys as well.

result.cancel = true;
break;
case 27:
Expand Down
1 change: 1 addition & 0 deletions src/common/services/CoreService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { IDecPrivateModes, ICharset } from 'common/Types';
import { clone } from 'common/Clone';

const DEFAULT_DEC_PRIVATE_MODES: IDecPrivateModes = Object.freeze({
altEnterMode: true,
applicationCursorKeys: false,
applicationKeypad: false,
origin: false,
Expand Down