vscode-emacs-mcx icon indicating copy to clipboard operation
vscode-emacs-mcx copied to clipboard

The mark set by Control+Space is moved when trying to select words with Control+Left/Right

Open BraisLP opened this issue 3 years ago • 12 comments

I usually set marks with Control+Space to start selecting code. Then press Control+Left or Right to select whole words. This works in emacs, but with this extension, the mark seems to change location instead of letting me select words.

If I set a mark and then use Control+A or Control+E, it correctly selects from the mark to the beginning or end of the line. Control+Left/Right should have the analogous behaviour :-)

BraisLP avatar Apr 21 '21 08:04 BraisLP

Similarly, I usually use Control+Up and Control+Down to select whole paragraphs after setting a mark in emacs. VS Code moves the scroll bar instead.

BraisLP avatar Apr 21 '21 09:04 BraisLP

I can't work on it soon because currently I only have macOS environment where ctrl + left/right are assigned to other functionality. I appreciate if you add new keybindings that work on your environment for this purpose and create a pull-request.

whitphx avatar Jul 12 '21 13:07 whitphx

A workaround is to configure the command for those keybindings. Below works for me (place it in your keybindings.json file):

    {
        "key": "ctrl+left",
        "command": "emacs-mcx.backwardWord",
        "when": "editorTextFocus && !config.emacs-mcx.useMetaPrefixMacCmd"
    },
    {
        "key": "ctrl+left",
        "command": "-cursorWordLeft",
        "when": "textInputFocus && !accessibilityModeEnabled"
    },
    {
        "key": "ctrl+right",
        "command": "emacs-mcx.forwardWord",
        "when": "editorTextFocus && !config.emacs-mcx.useMetaPrefixMacCmd"
    },
    {
        "key": "ctrl+right",
        "command": "-cursorWordEndRight",
        "when": "textInputFocus && !accessibilityModeEnabled"
    }

This will remove the standard mapping for Ctrl + left/right and then set them to be the same as what Alt + b/f is set to.

marcus-lundgren avatar Nov 02 '21 19:11 marcus-lundgren

To add on to the feature request, could we also get support for moving to the next blank line up or down with mark support per @marcus-lundgren workaround. So we can round out movement with the up and down keys and not just left right word

 {
    "key": "alt+up",
    "command": "cursorMove",
    "args": {
      "to": "prevBlankLine",
      "select": false
    },
    "when": "editorTextFocus"
  },

  {
    "key": "alt+down",
    "command": "cursorMove",
    "args": {
      "to": "nextBlankLine",
      "select": false
    },
    "when": "editorTextFocus"
  },

ZelCloud avatar Nov 09 '22 21:11 ZelCloud

Development note:

  • For C-<left> and C-<right>, we should implement left-word and right-word and assign them. M-<left> and M-<right> should also so as described atthis document.
    • These are same as backward-word and forward-word in left-to-right languages, and VSCode is not supporting RTL (https://github.com/microsoft/vscode/issues/86667), so we can simply use these.
  • For C-<up> and C-<down>, it looks like they are assigned to backward-paragraph and forward-paragraph on my local Emacs, but they are not documented. These commands are currently assigned to M-{ and M-}.

whitphx avatar Nov 24 '22 15:11 whitphx

C-<left>, C-<right>, C-<up>, C-<down> are available with v0.47.0

whitphx avatar Nov 25 '22 02:11 whitphx

vscode default functions has the following bindings, which are overridden by this change.

{ "key": "ctrl+left", "command": "workbench.action.navigateBack" },
{ "key": "ctrl+right", "command": "workbench.action.navigateForward" }

Is there an alternative/replacement way to trigger workbench.action.navigateBack? @whitphx

youyuanwu avatar Dec 24 '22 02:12 youyuanwu

@youyuanwu How about adding the following snippet to your keybindings.json? See https://code.visualstudio.com/docs/getstarted/keybindings#_removing-a-specific-key-binding-rule

{
  "key": "ctrl+left",
  "command": "-emacs-mcx.backwardWord",
  "when": "editorTextFocus"
},
{
  "key": "ctrl+right",
  "command": "-emacs-mcx.forwardWord",
  "when": "editorTextFocus"
},

BTW, what OS, VSCode version, etc, are you using? I could not find those default settings on my env below (copied from the "Code" menu -> "About Visual Studio Code"):

Version: 1.74.1 (Universal) Commit: 1ad8d514439d5077d2b0b7ee64d2ce82a9308e5a Date: 2022-12-14T10:33:40.793Z Electron: 19.1.8 Chromium: 102.0.5005.167 Node.js: 16.14.2 V8: 10.2.154.15-electron.0 OS: Darwin arm64 22.2.0 Sandboxed: No

whitphx avatar Dec 25 '22 05:12 whitphx

@whitphx vscode info:

Version: 1.74.2 (user setup)
Commit: e8a3071ea4344d9d48ef8a4df2c097372b0c5161
Date: 2022-12-20T10:29:14.590Z
Electron: 19.1.8
Chromium: 102.0.5005.167
Node.js: 16.14.2
V8: 10.2.154.15-electron.0
OS: Windows_NT x64 10.0.22621
Sandboxed: No

The removing key binding did not work. But I added the override in the same keybinding json and it worked:

  { "key": "ctrl+left", "command": "workbench.action.navigateBack" },
  { "key": "ctrl+right", "command": "workbench.action.navigateForward" }

Would do accept some other replacement binding for those 2 commands? Visual Studio (not code) uses "ctrl+-" for naviagteBack and "ctrl++" for navigate forward.

youyuanwu avatar Dec 25 '22 08:12 youyuanwu

@youyuanwu Hi, thank you for the info.

Would do accept some other replacement binding for those 2 commands?

Yes, and your suggestion makes sense.


FYI, on my Mac VSCode, ctrl+- is already assigned to workbench.action.navigateBack, while ctrl++ (ctrl+shift+=) is not assigned to any command, regardless of which we should assign them at the extension level.

whitphx avatar Dec 28 '22 23:12 whitphx

@youyuanwu Would you like to work on it and create the PR? If not, I can do it too.

whitphx avatar Dec 28 '22 23:12 whitphx

@whitphx created PR. But tested ctrl+- and ctrl++ does not work on windows during manual testing. Alternative bindings used in the PR.

youyuanwu avatar Dec 29 '22 02:12 youyuanwu