microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.24k stars 28.88k forks source link

Pressing `shift-left/right` will exit multi-caret mode #112064

Open imkzh opened 3 years ago

imkzh commented 3 years ago

When multiple carets are inserted, no matter with or without selections, pressing shift-left or shift-right exits the multi-caret mode (in some cases), and selecting texts only under the first caret, instead of initiate(or adjust) text selections for every caret.

Scenario:

As i remembered, there was a time when i could adjust multiple text selections simultaneously/synchronized. (confirmed: that is PyCharm instead of vscode)

It seems adjusting multiple selection will only work when all carets are "aligned" and "not modified yet", at present. Would this be a bug?

Also: move lines up and down does not work under multi-caret mode either, but this seems unrelated to this issue (i'm too lazy to submit this in a new issue).

======================

Tested: behaves exactly the same when all extensions are disabled.

======================

Version: 1.51.1 Commit: e5a624b788d92b8d34d1392e4c4d9789406efe8f Date: 2020-11-10T23:31:29.624Z (3 wks ago) Electron: 9.3.3 Chrome: 83.0.4103.122 Node.js: 12.14.1 V8: 8.3.110.13-electron.0 OS: Linux x64 4.15.0-23-generic (note: Ubuntu 16.04)

alexdima commented 3 years ago

Let's first try to find out what command executes on your machine, with your settings and your keybindings when pressing shift+right. Could you please try the following:

If you are having trouble understanding the output, please feel free to paste here and I can try to help.

imkzh commented 3 years ago

Here is the output from keyboard shortcuts troubleshooting console: (manually formatted) it seems the problem is related to Column Selection Mode (i turned it on because i was working on some text based table from terminal output). @alexdima

# scope: column selection mode enabled:

    # action: holding alt and click to insert some carets:
    [2020-12-08 16:44:29.395] [renderer1] [info] [KeybindingService]: / Received  keydown event - modifiers: [alt], code: AltLeft, keyCode: 18, key: Alt
    [2020-12-08 16:44:29.395] [renderer1] [info] [KeybindingService]: | Converted keydown event - modifiers: [alt], code: AltLeft, keyCode: 6 ('Alt')
    [2020-12-08 16:44:29.396] [renderer1] [info] [KeybindingService]: \ Keyboard event cannot be dispatched.

    # action: press shift+right
    [2020-12-08 16:44:41.331] [renderer1] [info] [KeybindingService]: / Received  keydown event - modifiers: [shift], code: ShiftLeft, keyCode: 16, key: Shift
    [2020-12-08 16:44:41.331] [renderer1] [info] [KeybindingService]: | Converted keydown event - modifiers: [shift], code: ShiftLeft, keyCode: 4 ('Shift')
    [2020-12-08 16:44:41.331] [renderer1] [info] [KeybindingService]: \ Keyboard event cannot be dispatched.
    [2020-12-08 16:44:41.555] [renderer1] [info] [KeybindingService]: / Received  keydown event - modifiers: [shift], code: ArrowRight, keyCode: 39, key: ArrowRight
    [2020-12-08 16:44:41.555] [renderer1] [info] [KeybindingService]: | Converted keydown event - modifiers: [shift], code: ArrowRight, keyCode: 17 ('RightArrow')
    [2020-12-08 16:44:41.555] [renderer1] [info] [KeybindingService]: | Resolving shift+[ArrowRight]
    [2020-12-08 16:44:41.555] [renderer1] [info] [KeybindingService]: \ From 2 keybinding entries, matched cursorColumnSelectRight, when: editorColumnSelection && textInputFocus, source: built-in.

# scope: column selection mode disabled:
#    (in this scope, adjusting/initiating selection works fine)

    # action: hold alt and click to insert some carets:
    [2020-12-08 16:46:31.764] [renderer1] [info] [KeybindingService]: / Received  keydown event - modifiers: [alt], code: AltLeft, keyCode: 18, key: Alt
    [2020-12-08 16:46:31.765] [renderer1] [info] [KeybindingService]: | Converted keydown event - modifiers: [alt], code: AltLeft, keyCode: 6 ('Alt')
    [2020-12-08 16:46:31.765] [renderer1] [info] [KeybindingService]: \ Keyboard event cannot be dispatched.

    # action: press shift+right
    [2020-12-08 16:46:40.241] [renderer1] [info] [KeybindingService]: / Received  keydown event - modifiers: [shift], code: ShiftLeft, keyCode: 16, key: Shift
    [2020-12-08 16:46:40.241] [renderer1] [info] [KeybindingService]: | Converted keydown event - modifiers: [shift], code: ShiftLeft, keyCode: 4 ('Shift')
    [2020-12-08 16:46:40.241] [renderer1] [info] [KeybindingService]: \ Keyboard event cannot be dispatched.
    [2020-12-08 16:46:40.469] [renderer1] [info] [KeybindingService]: / Received  keydown event - modifiers: [shift], code: ArrowRight, keyCode: 39, key: ArrowRight
    [2020-12-08 16:46:40.469] [renderer1] [info] [KeybindingService]: | Converted keydown event - modifiers: [shift], code: ArrowRight, keyCode: 17 ('RightArrow')
    [2020-12-08 16:46:40.470] [renderer1] [info] [KeybindingService]: | Resolving shift+[ArrowRight]
    [2020-12-08 16:46:40.470] [renderer1] [info] [KeybindingService]: \ From 2 keybinding entries, matched cursorRightSelect, when: textInputFocus, source: built-in.
alexdima commented 3 years ago

@imkzh Thank you for the extra information. This works as expected, when in column selection mode, the multiple cursors will always try to become aligned by columns (like a box).

By the way, the Selection > Column Selection Mode toggle is just one of multiple ways to create column selection. You can also:

imkzh commented 3 years ago

@alexdima thank you for the alt-key modifier solution.

But I still think there would be a bug. The carets can stay aligned or become unaligned after moving, even with carets still aligned, i could not initiate selection with keyboard.

Maybe we can make the program to check if the carets are still aligned before exiting the multi caret mode.

In column selection mode, make the following selection: contents in [] are selected, and a | denotes a caret.

L[or]|em ipsum dolor sit amet,
b[la]|h blah blah blah
f[oo]| bar

moving carets left will cancel the selection, but they are still aligned:

L|orem ipsum dolor sit amet,
b|lah blah blah blah
f|oo bar

and shift+right to initiate a new selection: what i expected:

L[o]|rem ipsum dolor sit amet,
b[l]|ah blah blah blah
f[o]|o bar

what i got:

L[o]|rem ipsum dolor sit amet,
blah blah blah blah
foo bar
alexdima commented 3 years ago

@imkzh How did you create the initial state?

L[or]|em ipsum dolor sit amet,
b[la]|h blah blah blah
f[oo]| bar
imkzh commented 3 years ago

@alexdima under column selection mode, click down after L on the first line and drag to select second o on the third line.

hediet commented 2 years ago

Still reproducable:

recording

Seems like in column-selection mode, shift+left/right does not work for multi-cursors.

hediet commented 2 years ago

@alexdima What is the difference between CursorColumnSelectLeft and CursorLeftSelect? ColumnSelectCommand does not seem to be multi-cursor ready (it only uses primary cursor).

alexdima commented 2 years ago

CursorLeftSelect is the regular shift+left that can result that multiple cursors become "unaligned" e.g. image

CursorColumnSelectLeft is only bound by default on Windows I believe and makes sure the result is a "column" selection (i.e. box selection). It also does not loop back to the end of the previous line, etc. image