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

Remove alt -> ctrl+arrow hack in favor of embedder-specific solutions #4538

Open
Tyriar opened this issue May 24, 2023 · 6 comments
Open

Remove alt -> ctrl+arrow hack in favor of embedder-specific solutions #4538

Tyriar opened this issue May 24, 2023 · 6 comments
Labels

Comments

@Tyriar
Copy link
Member

Tyriar commented May 24, 2023

Context: #264 (comment)

Finding the commit they were added to confirm is also a good idea.

case 37:
// left-arrow
if (ev.metaKey) {
break;
}
if (modifiers) {
result.key = C0.ESC + '[1;' + (modifiers + 1) + 'D';
// HACK: Make Alt + left-arrow behave like Ctrl + left-arrow: move one word backwards
// http://unix.stackexchange.com/a/108106
// macOS uses different escape sequences than linux
if (result.key === C0.ESC + '[1;3D') {
result.key = C0.ESC + (isMac ? 'b' : '[1;5D');
}
} else if (applicationCursorMode) {
result.key = C0.ESC + 'OD';
} else {
result.key = C0.ESC + '[D';
}
break;
case 39:
// right-arrow
if (ev.metaKey) {
break;
}
if (modifiers) {
result.key = C0.ESC + '[1;' + (modifiers + 1) + 'C';
// HACK: Make Alt + right-arrow behave like Ctrl + right-arrow: move one word forward
// http://unix.stackexchange.com/a/108106
// macOS uses different escape sequences than linux
if (result.key === C0.ESC + '[1;3C') {
result.key = C0.ESC + (isMac ? 'f' : '[1;5C');
}
} else if (applicationCursorMode) {
result.key = C0.ESC + 'OC';
} else {
result.key = C0.ESC + '[C';
}
break;
case 38:
// up-arrow
if (ev.metaKey) {
break;
}
if (modifiers) {
result.key = C0.ESC + '[1;' + (modifiers + 1) + 'A';
// HACK: Make Alt + up-arrow behave like Ctrl + up-arrow
// http://unix.stackexchange.com/a/108106
// macOS uses different escape sequences than linux
if (!isMac && result.key === C0.ESC + '[1;3A') {
result.key = C0.ESC + '[1;5A';
}
} else if (applicationCursorMode) {
result.key = C0.ESC + 'OA';
} else {
result.key = C0.ESC + '[A';
}
break;
case 40:
// down-arrow
if (ev.metaKey) {
break;
}
if (modifiers) {
result.key = C0.ESC + '[1;' + (modifiers + 1) + 'B';
// HACK: Make Alt + down-arrow behave like Ctrl + down-arrow
// http://unix.stackexchange.com/a/108106
// macOS uses different escape sequences than linux
if (!isMac && result.key === C0.ESC + '[1;3B') {
result.key = C0.ESC + '[1;5B';
}
} else if (applicationCursorMode) {
result.key = C0.ESC + 'OB';
} else {
result.key = C0.ESC + '[B';
}
break;

@fifv
Copy link

fifv commented Nov 28, 2023

Thank you Tyriar for saving my life. I have spent hours to figure out why my Alt key doesn't work...

For anyone who wants a workaround, here is my hack for Tabby (other terminals should be similar):

  1. Open the file contains xterm.js's bundled codes (C:\Users\<USER>\AppData\Local\Programs\Tabby\resources\builtin-plugins\tabby-terminal\dist\index.js)

    • This is xterm.js ‘s problem, and Tabby use xterm.js as a plugin, note it belongs to builtin-plugins instead of main tabby app
  2. Fix for Arrows:

    Find [1;5D (may ~27452 at Tabby 1.0.196)

    Remove these selected

    image

  3. Fix for PageUp/PageDown:

    Find [5~ (may ~27479 at Tabby 1.0.196, just near the above ones)

    Add these selected

    image

@dmarcuse
Copy link

Is there any recent update on this? I've been frustrated by this behavior in VS code and finally figured out this was the cause (and found the linked workaround via VS code's shortcuts). I see the help wanted tag - if it's just a matter of getting someone to do it, I'm happy to make the changes.

@Tyriar
Copy link
Member Author

Tyriar commented Aug 15, 2024

@dmarcuse no updates, just needs someone to help out. We'll need this removed in xterm.js and then some default keybindings added to VS Code. So then disabling this in VS Code would be a matter or disabling keybindings (as opposed to creating new ones which is more difficult).

@dmarcuse
Copy link

Sounds good, I'll set aside some time to work on this over the weekend then.

@balthild
Copy link

You could just "fix" it by simply override the key binding if you're using vscode. Maybe the workbench.action.terminal.sendSequence action does not send sequences via xterm.js, but through conpty directly, so it would not be modified?

    {
        "key": "alt+left",
        "command": "workbench.action.terminal.sendSequence",
        "args": {
            "text": "\u001b[1;3D"
        },
        "when": "terminalFocus"
    },
    {
        "key": "alt+right",
        "command": "workbench.action.terminal.sendSequence",
        "args": {
            "text": "\u001b[1;3C"
        },
        "when": "terminalFocus"
    },

Result:

image

image

@Tyriar
Copy link
Member Author

Tyriar commented Sep 20, 2024

@balthild yep, we just need that keybinding built in to VS Code. So those keybindings added somewhere over here: https://github.com/microsoft/vscode/blob/3ae6c5ef651585b12870828230f214eed2e6ef07/src/vs/workbench/contrib/terminal/browser/terminal.contribution.ts#L245-L249

And then remove the overrides from xterm.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants