edit icon indicating copy to clipboard operation
edit copied to clipboard

Add support for block selections

Open vefatica opened this issue 8 months ago • 3 comments

Can block selection (Esc + key/mouse selection) be added?

vefatica avatar May 20 '25 15:05 vefatica

Of course we can add block selection! 😅

I guess it requires tagging up the TextBufferSelection struct with a bool and handling everything accordingly. However, I'll mark this up as low priority until others ask for this as well, because I think that multi-cursor support falls in a similar space and I consider it more important personally.

lhecker avatar May 20 '25 16:05 lhecker

So far I've found one use case for preferring a block selection over multi-cursor. Or, more accurately, a use case to prefer block editing. Block selects can be a bit smart, and assume that you're only selecting and editing visible text (not newlines). While multi-cursors, at least as I've experienced them, won't ignore newlines, and end up deleting them where it's unwanted.

Take this block of text:

// do_something();
//
// do_another_thing();

I want to uncomment the code by deleting the // (note the space). So the desired result is this:

do_something();

do_another_thing();

If I put 3 cursors at the start of each line, and hit delete 3 times, then:

  1. The first / is deleted from each line
  2. The second / is deleted from each line
  3. The leading space is deleted from line 1 and 3, but the newline is deleted from line 2, so I've lost the empty line separating lines 1 and 3.

This is the behavior I get with VS Code's and Helix's multi-cursor. But if I made a block selection 3 columns wide and 3 rows tall in Vim, it will know not to delete the newline on line 2 when I delete the selected text. I'll actually sometimes switch out of an editor and into Vim just to use its visual block select :laughing: Although maybe I'm showing a bias for Vim and a lack of understanding of better ways in VS Code :thinking:

tl;dr As I've experienced them, deleting a block selection won't delete a newline, which is nice to help avoid unintentionally removing empty lines.

spenserblack avatar Jun 10 '25 14:06 spenserblack

FWIW, the way to do this in VS Code today is this way:

https://github.com/user-attachments/assets/b45cf3d8-7074-42f3-826a-14b7a95ca567

This is because the editor keeps track of a "preferred" column when navigating the cursor. This editor does the same.

I understand your example, though. I'm sure there are more in similar spirit. 🙂

lhecker avatar Jun 10 '25 14:06 lhecker