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

Add a mark / select mode #8580

Closed
1 task done
failable opened this issue Feb 29, 2024 · 9 comments · Fixed by #23297
Closed
1 task done

Add a mark / select mode #8580

failable opened this issue Feb 29, 2024 · 9 comments · Fixed by #23297
Labels
enhancement [core label] keymap / key binding Feedback for keyboard shortcuts, key mapping, etc

Comments

@failable
Copy link

failable commented Feb 29, 2024

Check for existing issues

  • Completed

Describe the feature

Currently node selection is handy in Zed. But other (random) selection generally require pressing the shift key. Although it's possible to assign shortcuts to selection without using the shift key, in order to maintain consistency between selection and movement, they usually differ by just one shift key.

This is pain when editing text file or markdown file where one is not always selecting some "syntax node".

Suggest to add a standalone mark mode, like the visual selection in vim or transient-mark-mode in emacs.

Note that this mode is not bound with vim-mode. The transient-mark-mode in emacs can also activated independently.

This feature can greatly reduce the frequency of continuously holding down the shift key to protect the little finger.

When the mode is activated, the shift in the key bindings can be ignored. Normal movements like ctrl-n acts like ctrl-shift-n.

If applicable, add mockups / screenshots to help present your vision of the feature

No response

@failable failable added admin read Pending admin review enhancement [core label] triage Maintainer needs to classify the issue labels Feb 29, 2024
@Moshyfawn Moshyfawn added vim keymap / key binding Feedback for keyboard shortcuts, key mapping, etc and removed triage Maintainer needs to classify the issue labels Feb 29, 2024
@JosephTLyons JosephTLyons removed the admin read Pending admin review label Feb 29, 2024
@ozanmakes
Copy link
Contributor

Add emacs keybindings for mark emulation #22904 implements %95 of Emacs set-mark + movement commands without an explicit "mark-mode". I've been using these for a few days and it is working great in practice.

The "selection" context that enables this is already merged (#21927), so you can test this and provide feedback by copying these keybindings to your keymap.json.

@gree7
Copy link

gree7 commented Jan 10, 2025

Together with

  {
    "context": "Editor",
    "bindings": {
    [...]
      "ctrl-space": "editor::SelectRight",
  }

this is really nice for Emacs. I didn't find anything like editor::Unselect though. That would be perfect to add as ctrl+space in the "context": "Editor && selection" which would emulate emacs reset of the selection mark.

@dmvianna
Copy link

this is really nice for Emacs. I didn't find anything like editor::Unselect though.

Have a look at #4856 for many keybinding options. I just tested and my ctrl-g works just fine to unselect an editor selection.

  {
    "bindings": {
      "ctrl-g": "menu::Cancel",
      "alt-x": "app_menu::OpenApplicationMenu",
      "ctrl-?": null
    }
  },

@gree7
Copy link

gree7 commented Jan 13, 2025

Thanks. "menu::Cancel" didn't work for me, but "editor::Cancel" works nicely.

@notpeter
Copy link
Member

There is an initial implementation of this behavior for the emacs keybinding here:

With this change (available in Preview 0.170 on Wednesday 2025-01-15) if you press ctrl-space and then movement direction it will create a selection and any subsequent cursor will select without requiring holding space. Similarly if create a selection with the mouse you will be in mark mode and can further expand the selection with your keyboard. Cancel the selection with ctrl-g or ctrl-space.

Some known drawbacks of this approach:

  • After pressing ctrl-space you must press do the directional move relatively quickly so it is detected as a chorded keystroke.
  • If you move through the mark character by characters (e.g. ctrl-space right, right, right, left, left, left) the selection mark will be unset.
  • In emacs if you begin a selection using shift (e.g. shift-right) subsequent movements also require holding shift (e.g. emacs does not enter Mark mode) moving the cursor without shift will clear the selection.

@gree7
Copy link

gree7 commented Jan 13, 2025

Aah, I see. The solution with the chords is pretty elegant. I'll try it for a while instead of simple "ctrl-space": "editor::SelectRight", whether I hit the problem with not pressing the direction key fast enough. Thanks for the pointer.

@failable
Copy link
Author

failable commented Jan 14, 2025

After pressing ctrl-space you must press do the directional move relatively quickly so it is detected as a chorded keystroke.

Even thought I have the following setting and move very quickly, sometimes (> 70%) the selection is disappeared after being shown.

image
Screen.Recording.2025-01-14.at.10.51.07.mov

@dmvianna
Copy link

@failable Why are you putting your keybindings under Editor && (mode == full) && !selection when you want to use them with a selection? I would rather have them under "context": "Editor" and use them under any circumstance within it. I wonder if the !selection isn't kicking you out of it when you start the selection.

@failable
Copy link
Author

failable commented Jan 14, 2025

I just copied them from the assets/keymaps/macos/emacs.json.

github-merge-queue bot pushed a commit that referenced this issue Jan 14, 2025
- Reverts #22904
- See also: #8580

After using it full-time for a day I very much think an implicit "mark
mode" when the emacs base keymap is enabled is the wrong approach.

Release Notes:

- Reverted "Add emacs keybindings for mark emulation" #23146 (main only)
@ConradIrwin ConradIrwin removed the vim label Jan 16, 2025
ConradIrwin added a commit that referenced this issue Jan 17, 2025
Updates #21927
Closes #8580

Co-Authored-By: Peter <[email protected]>
notpeter added a commit that referenced this issue Jan 17, 2025
Updates #21927
Closes #8580

Co-Authored-By: Peter <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement [core label] keymap / key binding Feedback for keyboard shortcuts, key mapping, etc
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants