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

Smart Semicolon Detection issue with Swiss German Keyboard #3290

Closed
SKSniperSK opened this issue Sep 13, 2023 · 14 comments · Fixed by #3303
Closed

Smart Semicolon Detection issue with Swiss German Keyboard #3290

SKSniperSK opened this issue Sep 13, 2023 · 14 comments · Fixed by #3303
Assignees
Labels

Comments

@SKSniperSK
Copy link

When editing a Java file in VS Code using a Swiss German Keyboard I can not enter [ü] or [AltGr]+[ü] (which is left square bracket) because java.edit.smartSemicolonDetection.command is fired.

Environment
  • Operating System: Windows 10
  • JDK version: 11
  • Visual Studio Code version: 1.82.1
  • Java extension version: 1.22
Steps To Reproduce
  1. Open a java file on VS Code using Swiss German Keyboard
  2. Try to enter a square bracket, you will get a semicolon

Keybinding logs:

When pressing [ü]:

2023-09-13 17:28:52.958 [info] [KeybindingService]: / Soft dispatching keyboard event
2023-09-13 17:28:52.978 [info] [KeybindingService]: | Resolving ;
2023-09-13 17:28:52.978 [info] [KeybindingService]: \ From 1 keybinding entries, matched java.edit.smartSemicolonDetection.command, when: editorTextFocus && javaLSReady && !editorReadonly && editorLangId == 'java', source: user extension redhat.java.
2023-09-13 17:28:52.978 [info] [KeybindingService]: / Received keydown event - modifiers: [], code: BracketLeft, keyCode: 186, key: ü
2023-09-13 17:28:52.979 [info] [KeybindingService]: | Converted keydown event - modifiers: [], code: BracketLeft, keyCode: 85 (';')
2023-09-13 17:28:52.979 [info] [KeybindingService]: | Resolving ;
2023-09-13 17:28:52.979 [info] [KeybindingService]: \ From 1 keybinding entries, matched java.edit.smartSemicolonDetection.command, when: editorTextFocus && javaLSReady && !editorReadonly && editorLangId == 'java', source: user extension redhat.java.
2023-09-13 17:28:52.979 [info] [KeybindingService]: + Invoking command java.edit.smartSemicolonDetection.command.

When pressing [AltGr]+[ü] (which is "["):

2023-09-13 17:30:36.525 [info] [KeybindingService]: / Soft dispatching keyboard event
2023-09-13 17:30:36.525 [info] [KeybindingService]: \ Keyboard event cannot be dispatched
2023-09-13 17:30:36.525 [info] [KeybindingService]: / Received keydown event - modifiers: [ctrl], code: ControlLeft, keyCode: 17, key: Control
2023-09-13 17:30:36.525 [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl], code: ControlLeft, keyCode: 5 ('Ctrl')
2023-09-13 17:30:36.525 [info] [KeybindingService]: \ Keyboard event cannot be dispatched in keydown phase.
2023-09-13 17:30:36.525 [info] [KeybindingService]: / Soft dispatching keyboard event
2023-09-13 17:30:36.525 [info] [KeybindingService]: \ Keyboard event cannot be dispatched
2023-09-13 17:30:36.526 [info] [KeybindingService]: / Received keydown event - modifiers: [], code: AltRight, keyCode: 18, key: AltGraph
2023-09-13 17:30:36.526 [info] [KeybindingService]: | Converted keydown event - modifiers: [alt], code: AltRight, keyCode: 6 ('Alt')
2023-09-13 17:30:36.526 [info] [KeybindingService]: \ Keyboard event cannot be dispatched in keydown phase.
2023-09-13 17:30:36.637 [info] [KeybindingService]: / Soft dispatching keyboard event
2023-09-13 17:30:36.637 [info] [KeybindingService]: | Resolving ;
2023-09-13 17:30:36.637 [info] [KeybindingService]: \ From 1 keybinding entries, matched java.edit.smartSemicolonDetection.command, when: editorTextFocus && javaLSReady && !editorReadonly && editorLangId == 'java', source: user extension redhat.java.
2023-09-13 17:30:36.637 [info] [KeybindingService]: / Received keydown event - modifiers: [], code: BracketLeft, keyCode: 186, key: [
2023-09-13 17:30:36.638 [info] [KeybindingService]: | Converted keydown event - modifiers: [], code: BracketLeft, keyCode: 85 (';')
2023-09-13 17:30:36.638 [info] [KeybindingService]: | Resolving ;
2023-09-13 17:30:36.638 [info] [KeybindingService]: \ From 1 keybinding entries, matched java.edit.smartSemicolonDetection.command, when: editorTextFocus && javaLSReady && !editorReadonly && editorLangId == 'java', source: user extension redhat.java.
2023-09-13 17:30:36.638 [info] [KeybindingService]: + Invoking command java.edit.smartSemicolonDetection.command.
2023-09-13 17:30:36.986 [info] [KeybindingService]: + Storing single modifier for possible chord ctrl.
2023-09-13 17:30:36.987 [info] [KeybindingService]: + Clearing single modifier due to modifier mismatch: ctrl alt

This issue can be fixed manually by adjusting the "Java: Java Smart Semicolon Detection" keyboard shortcut in settings (change keybinding from [ü] to [Shift]+[,] (which is ";") but the default value [ü] makes no sense at all, so this should be fixed.

@fbricon
Copy link
Collaborator

fbricon commented Sep 13, 2023

That's weird, the command is properly bound to ; https://github.com/redhat-developer/vscode-java/blob/master/package.json#L1323-L1325

In any case you can disable the smart semicolon feature with "java.edit.smartSemicolonDetection.enabled":false in your settings

@SKSniperSK
Copy link
Author

Thanks for the quick reply. Yes I know this is weird but all I can say is that even when I reset the keybinding now the default value I get is this:

image

So the default for me is "ü" instead of ";" -> I can manually adjust it again to ";" (or to be more precise [Shift]+[,]) and it will work (so this is not an urgent issue) but the default setting I get is definitely wrong, therefore I just wanted to report it.

@SKSniperSK
Copy link
Author

All I can see from the logs is that for this particular key on my keyboard the received and converted event do not match:

When pressing without modifiers:

[info] [KeybindingService]: / Received keydown event - modifiers: [], code: BracketLeft, keyCode: 186, key: ü
[info] [KeybindingService]: | Converted keydown event - modifiers: [], code: BracketLeft, keyCode: 85 (';')

-> ü gets converted to ;

With [AltGr] modifier:

[info] [KeybindingService]: / Received keydown event - modifiers: [], code: BracketLeft, keyCode: 186, key: [
[info] [KeybindingService]: | Converted keydown event - modifiers: [], code: BracketLeft, keyCode: 85 (';')

-> [ gets converted to ;

So perhaps this conversion/mapping might have something to do with it?

@fbricon
Copy link
Collaborator

fbricon commented Sep 13, 2023

I dont know. When I change my keyboard to the German Swiss layout, I even get a different mapping:
Screenshot 2023-09-13 at 18 46 45

@SKSniperSK
Copy link
Author

Yes this would actually be the correct keybinding as [Shift]+[,] on Swiss German layout is the semicolon character. I also checked the other keybindings from the package.json and they are all correct, it is just the semicolon one where I get a different default value. Really strange.

@fbricon
Copy link
Collaborator

fbricon commented Sep 13, 2023

That's some VS Code black magic. @jrieken any idea?

@adietish
Copy link

adietish commented Sep 13, 2023

I dont understand it either. I have a mac with a swiss german layout, everything seems fine for me.
Left square bracket is different than on a PC though, it's [Alt] + [5]. This may explain why I dont face the same problem.

@adietish
Copy link

adietish commented Sep 13, 2023

Checked my old Dell PC Keyboard and I see the "[" on the same key as the "ü". On the Mac, the mapping that's applied when I connect it, would still put the "[" onto the "5" though. So apparently I cannot replicate this with a Mac :(

@snjeza
Copy link
Contributor

snjeza commented Sep 13, 2023

I can reproduce the issue on Windows 10, but can't on Fedora 37.

Fedora 37
smart4

@SKSniperSK
Copy link
Author

Some more info:

I did a downgrade to 1.21 and then went back to 1.22 which did not change anything.

Configuring java.edit.smartSemicolonDetection.enabled only changes the location of the semicolon added but has no effect on the bug itself. So no matter if set to true or false I always get a semicolon when pressing ü, the semicolon only appears at cursor location or at the end of the line depending on the setting (at least the positioning part makes sense).
Therefore disabling the functionality is no workaround, the only workaround is to manually fix the keybinding.

@testforstephen
Copy link
Collaborator

It's better to avoid intercept ; hotkey if users disable java.edit.smartSemicolonDetection.enabled.

VS Code supports checking a setting in a when clause, see https://code.visualstudio.com/api/references/when-clause-contexts#check-a-setting-in-a-when-clause, so we can append config.java.edit.smartSemicolonDetection.enabled to the when clause.

vscode-java/package.json

Lines 1323 to 1326 in 5347cc2

"command": "java.edit.smartSemicolonDetection.command",
"key": ";",
"when": "editorTextFocus && !editorReadonly && javaLSReady && editorLangId == java"
}

@fbricon
Copy link
Collaborator

fbricon commented Sep 14, 2023

@snjeza instead of using a keybinding, can we use something like that instead? :

window.onDidChangeTextDocument((event) => {
        if (!smartSemicolonDetection()){
          return;
        }
        const typedCharacter = getTypedCharacter(event);

        if (typedCharacter === ';') {
            commands.executeCommand('java.edit.smartSemicolonDetection.command');
            //or call the function directly
        }
    });

@fbricon
Copy link
Collaborator

fbricon commented Sep 14, 2023

@SKSniperSK @turkmenugur @polcamps we've released 1.22.1, which now properly respects "java.edit.smartSemicolonDetection.enabled:false", so you can safely disable this feature until it's properly fixed

@rgrunber rgrunber modified the milestone: Mid September 2023 Sep 14, 2023
@snjeza
Copy link
Contributor

snjeza commented Sep 14, 2023

instead of using a keybinding, can we use something like that instead? :

@fbricon I will try
@fbricon @rgrunber @adietish @SKSniperSK @turkmenugur @polcamps Could you check VS Code 1.24.2?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

6 participants