microsoft / vscode

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

Cursor moving left when typing brackets #194977

Open alekob opened 1 year ago

alekob commented 1 year ago

Does this issue occur when all extensions are disabled?: Yes

Steps to Reproduce:

  1. Open new / existing file, e. g. python script, makefile, etc
  2. At the end of a line (after some code), enter a opening square / curly bracket
  3. The bracket is inserted after the cursor is moved one character to the left
  4. e. g when trying to type "field[]" the result is "fiel[d"
ulugbekna commented 10 months ago

Hi @alekob 🙂

Thanks for filing this issue!

Could you please try the following:

  1. Run the command "Developer: Toggle Keyboard Shortcuts Troubleshooting" (you can, for example, run it from the Command Palette).

    This will activate logging of dispatched keyboard shortcuts and will open an output panel with the corresponding log file.

  2. Press exactly the keybinding you desire

  3. Check what VS Code detects

If you are having trouble understanding the output, please feel free to paste here and we'll be happy to help ☺️

alekob commented 10 months ago

Hi,

Thanks for taking care of this issue!

Please find below what VS Code (1.84.2) outputs when I insert a "[":

2023-12-05 13:10:45.046 [info] [KeybindingService]: / Soft dispatching keyboard event 2023-12-05 13:10:45.046 [info] [KeybindingService]: \ Keyboard event cannot be dispatched 2023-12-05 13:10:45.047 [info] [KeybindingService]: / Received keydown event - modifiers: [ctrl], code: ControlLeft, keyCode: 17, key: Control 2023-12-05 13:10:45.047 [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl], code: ControlLeft, keyCode: 5 ('Ctrl') 2023-12-05 13:10:45.048 [info] [KeybindingService]: \ Keyboard event cannot be dispatched in keydown phase. 2023-12-05 13:10:45.066 [info] [KeybindingService]: / Soft dispatching keyboard event 2023-12-05 13:10:45.067 [info] [KeybindingService]: \ Keyboard event cannot be dispatched 2023-12-05 13:10:45.067 [info] [KeybindingService]: / Received keydown event - modifiers: [ctrl,alt], code: AltLeft, keyCode: 18, key: Alt 2023-12-05 13:10:45.067 [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl,alt], code: AltLeft, keyCode: 6 ('Alt') 2023-12-05 13:10:45.068 [info] [KeybindingService]: \ Keyboard event cannot be dispatched in keydown phase. 2023-12-05 13:10:45.787 [info] [KeybindingService]: + Ignoring single modifier alt due to it being pressed together with other keys. 2023-12-05 13:10:45.788 [info] [KeybindingService]: / Soft dispatching keyboard event 2023-12-05 13:10:45.789 [info] [KeybindingService]: | Resolving [ArrowLeft] 2023-12-05 13:10:45.789 [info] [KeybindingService]: \ From 11 keybinding entries, matched cursorLeft, when: textInputFocus, source: built-in. 2023-12-05 13:10:45.790 [info] [KeybindingService]: / Received keydown event - modifiers: [], code: ArrowLeft, keyCode: 225, key: AltGraph 2023-12-05 13:10:45.790 [info] [KeybindingService]: | Converted keydown event - modifiers: [], code: ArrowLeft, keyCode: 0 ('unknown') 2023-12-05 13:10:45.790 [info] [KeybindingService]: | Resolving [ArrowLeft] 2023-12-05 13:10:45.790 [info] [KeybindingService]: \ From 11 keybinding entries, matched cursorLeft, when: textInputFocus, source: built-in. 2023-12-05 13:10:45.791 [info] [KeybindingService]: + Invoking command cursorLeft. 2023-12-05 13:10:45.792 [info] [KeybindingService]: / Soft dispatching keyboard event 2023-12-05 13:10:45.792 [info] [KeybindingService]: | Resolving [Digit8] 2023-12-05 13:10:45.792 [info] [KeybindingService]: \ No keybinding entries. 2023-12-05 13:10:45.793 [info] [KeybindingService]: / Received keydown event - modifiers: [], code: Digit8, keyCode: 56, key: [ 2023-12-05 13:10:45.793 [info] [KeybindingService]: | Converted keydown event - modifiers: [], code: Digit8, keyCode: 29 ('8') 2023-12-05 13:10:45.793 [info] [KeybindingService]: | Resolving [Digit8] 2023-12-05 13:10:45.793 [info] [KeybindingService]: \ No keybinding entries. 2023-12-05 13:10:45.803 [info] [KeybindingService]: / Soft dispatching keyboard event 2023-12-05 13:10:45.803 [info] [KeybindingService]: \ Keyboard event cannot be dispatched 2023-12-05 13:10:45.804 [info] [KeybindingService]: / Received keydown event - modifiers: [alt], code: AltLeft, keyCode: 18, key: Alt 2023-12-05 13:10:45.804 [info] [KeybindingService]: | Converted keydown event - modifiers: [alt], code: AltLeft, keyCode: 6 ('Alt') 2023-12-05 13:10:45.805 [info] [KeybindingService]: \ Keyboard event cannot be dispatched in keydown phase. 2023-12-05 13:10:45.805 [info] [KeybindingService]: / Soft dispatching keyboard event 2023-12-05 13:10:45.805 [info] [KeybindingService]: \ Keyboard event cannot be dispatched 2023-12-05 13:10:45.805 [info] [KeybindingService]: / Received keydown event - modifiers: [ctrl,alt], code: ControlLeft, keyCode: 17, key: Control 2023-12-05 13:10:45.806 [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl,alt], code: ControlLeft, keyCode: 5 ('Ctrl') 2023-12-05 13:10:45.806 [info] [KeybindingService]: \ Keyboard event cannot be dispatched in keydown phase. 2023-12-05 13:10:46.056 [info] [KeybindingService]: + Ignoring single modifier alt due to it being pressed together with other keys. 2023-12-05 13:11:00.181 [info] [KeybindingService]: / Soft dispatching keyboard event 2023-12-05 13:11:00.214 [info] [KeybindingService]: \ Keyboard event cannot be dispatched 2023-12-05 13:11:00.236 [info] [KeybindingService]: / Received keydown event - modifiers: [ctrl], code: ControlLeft, keyCode: 17, key: Control 2023-12-05 13:11:00.236 [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl], code: ControlLeft, keyCode: 5 ('Ctrl') 2023-12-05 13:11:00.236 [info] [KeybindingService]: \ Keyboard event cannot be dispatched in keydown phase. 2023-12-05 13:11:00.242 [info] [KeybindingService]: + Storing single modifier for possible chord ctrl. 2023-12-05 13:11:00.542 [info] [KeybindingService]: + Clearing single modifier due to 300ms elapsed. 2023-12-05 13:13:07.912 [info] [KeybindingService]: / Soft dispatching keyboard event 2023-12-05 13:13:07.912 [info] [KeybindingService]: \ Keyboard event cannot be dispatched 2023-12-05 13:13:07.914 [info] [KeybindingService]: / Received keydown event - modifiers: [ctrl], code: ControlLeft, keyCode: 17, key: Control 2023-12-05 13:13:07.915 [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl], code: ControlLeft, keyCode: 5 ('Ctrl') 2023-12-05 13:13:07.915 [info] [KeybindingService]: \ Keyboard event cannot be dispatched in keydown phase. 2023-12-05 13:13:07.925 [info] [KeybindingService]: / Soft dispatching keyboard event 2023-12-05 13:13:07.925 [info] [KeybindingService]: \ Keyboard event cannot be dispatched 2023-12-05 13:13:07.925 [info] [KeybindingService]: / Received keydown event - modifiers: [ctrl,shift], code: ShiftLeft, keyCode: 16, key: Shift 2023-12-05 13:13:07.926 [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl,shift], code: ShiftLeft, keyCode: 4 ('Shift') 2023-12-05 13:13:07.926 [info] [KeybindingService]: \ Keyboard event cannot be dispatched in keydown phase. 2023-12-05 13:13:10.757 [info] [KeybindingService]: + Storing single modifier for possible chord shift. 2023-12-05 13:13:11.038 [info] [KeybindingService]: / Soft dispatching keyboard event 2023-12-05 13:13:11.039 [info] [KeybindingService]: \ Keyboard event cannot be dispatched 2023-12-05 13:13:11.039 [info] [KeybindingService]: / Received keydown event - modifiers: [ctrl], code: ControlLeft, keyCode: 17, key: Control 2023-12-05 13:13:11.039 [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl], code: ControlLeft, keyCode: 5 ('Ctrl') 2023-12-05 13:13:11.040 [info] [KeybindingService]: \ Keyboard event cannot be dispatched in keydown phase. 2023-12-05 13:13:11.058 [info] [KeybindingService]: + Clearing single modifier due to 300ms elapsed. 2023-12-05 13:13:11.153 [info] [KeybindingService]: + Storing single modifier for possible chord ctrl. 2023-12-05 13:13:11.454 [info] [KeybindingService]: + Clearing single modifier due to 300ms elapsed. 2023-12-05 13:13:21.231 [info] [KeybindingService]: / Soft dispatching keyboard event 2023-12-05 13:13:21.232 [info] [KeybindingService]: \ Keyboard event cannot be dispatched 2023-12-05 13:13:21.232 [info] [KeybindingService]: / Received keydown event - modifiers: [ctrl], code: ControlLeft, keyCode: 17, key: Control 2023-12-05 13:13:21.232 [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl], code: ControlLeft, keyCode: 5 ('Ctrl') 2023-12-05 13:13:21.233 [info] [KeybindingService]: \ Keyboard event cannot be dispatched in keydown phase. 2023-12-05 13:13:21.567 [info] [KeybindingService]: / Soft dispatching keyboard event 2023-12-05 13:13:21.568 [info] [KeybindingService]: | Resolving ctrl+[KeyA] 2023-12-05 13:13:21.568 [info] [KeybindingService]: \ From 2 keybinding entries, matched editor.action.selectAll, when: no when condition, source: built-in. 2023-12-05 13:13:21.569 [info] [KeybindingService]: / Received keydown event - modifiers: [ctrl], code: KeyA, keyCode: 65, key: a 2023-12-05 13:13:21.569 [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl], code: KeyA, keyCode: 31 ('A') 2023-12-05 13:13:21.569 [info] [KeybindingService]: | Resolving ctrl+[KeyA] 2023-12-05 13:13:21.570 [info] [KeybindingService]: \ From 2 keybinding entries, matched editor.action.selectAll, when: no when condition, source: built-in. 2023-12-05 13:13:21.570 [info] [KeybindingService]: + Invoking command editor.action.selectAll. 2023-12-05 13:13:21.668 [info] [KeybindingService]: + Ignoring single modifier ctrl due to it being pressed together with other keys. 2023-12-05 13:13:26.577 [info] [KeybindingService]: / Soft dispatching keyboard event 2023-12-05 13:13:26.578 [info] [KeybindingService]: \ Keyboard event cannot be dispatched 2023-12-05 13:13:26.578 [info] [KeybindingService]: / Received keydown event - modifiers: [ctrl], code: ControlLeft, keyCode: 17, key: Control 2023-12-05 13:13:26.578 [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl], code: ControlLeft, keyCode: 5 ('Ctrl') 2023-12-05 13:13:26.579 [info] [KeybindingService]: \ Keyboard event cannot be dispatched in keydown phase. 2023-12-05 13:13:26.739 [info] [KeybindingService]: + Storing single modifier for possible chord ctrl. 2023-12-05 13:13:27.039 [info] [KeybindingService]: + Clearing single modifier due to 300ms elapsed.

scaidermern commented 7 months ago

Sounds like the issue from https://stackoverflow.com/questions/67804948/vscode-cursor-moves-left-on-altgr-how-to-fix-it. The workaround is to set keyboard.dispatch to keyCode.

alekob commented 7 months ago

Hi @scaidermern, thanks for the hint, this setting fixed my problem indeed! :blush:

VSCodeTriageBot commented 5 months ago

Hey @ulugbekna, this issue might need further attention.

@alekob, you can help us out by closing this issue if the problem no longer exists, or adding more information.

alekob commented 5 months ago

Hi, with VS Code v1.89.0 it's still necessary to set keyboard.dispatch = keyCode as a workaround. The default value "code" still causes the problem