Просмотр исходного кода

[cm6] Improve keyboard shortcuts for toggling line comments (#13067)

GitOrigin-RevId: dd08778ea3621eefa75f306b2dada3f2c484f76c
Alf Eaton 3 лет назад
Родитель
Сommit
c8a72e96d4

+ 16 - 2
services/web/frontend/js/features/source-editor/extensions/shortcuts.ts

@@ -59,21 +59,35 @@ export const shortcuts = Prec.high(
       preventDefault: true,
       run: redo,
     },
+
+    // defaultKeymap maps Mod-/ to toggleLineComment, but
+    // w3c-keyname has a hard-coded mapping of Shift+key => character
+    // which uses a US keyboard layout, so we need to add more mappings.
+
+    // Mod-/, but Spanish, Portuguese, German and Swedish keyboard layouts have / at Shift+7
+    // (keyCode 55, mapped with Shift to &)
     {
-      key: 'Mod-Shift-/',
+      key: 'Mod-&',
       preventDefault: true,
       run: toggleLineComment,
     },
+    // Mod-/, but German keyboard layouts have / at Cmd+Shift+ß
+    // Mod-/, but Czech keyboard layouts have / at Shift-ú
+    // (keyCode 191, mapped with Shift to ?)
     {
-      key: 'Mod-ß',
+      key: 'Mod-?',
       preventDefault: true,
       run: toggleLineComment,
     },
+    // German keyboard layouts map 0xBF to #,
+    // so VS Code on Windows/Linux uses Ctrl-# to toggle line comments.
+    // This is an additional, undocumented shortcut for compatibility.
     {
       key: 'Ctrl-#',
       preventDefault: true,
       run: toggleLineComment,
     },
+
     {
       key: 'Ctrl-u',
       preventDefault: true,

+ 0 - 18
services/web/test/frontend/features/source-editor/components/codemirror-editor-shortcuts.spec.tsx

@@ -36,15 +36,6 @@ describe('keyboard shortcuts', { scrollBehavior: false }, function () {
     window.metaAttributesCache = new Map()
   })
 
-  it('comment line with {meta+shift+/}', function () {
-    cy.get('@line')
-      .type('text')
-      .type(`{${metaKey}+shift+/}`)
-      .should('have.text', '% text')
-
-    cy.get('@line').type(`{${metaKey}+shift+/}`).should('have.text', 'text')
-  })
-
   it('comment line with {meta+/}', function () {
     cy.get('@line')
       .type('text')
@@ -54,15 +45,6 @@ describe('keyboard shortcuts', { scrollBehavior: false }, function () {
     cy.get('@line').type(`{${metaKey}+/}`).should('have.text', 'text')
   })
 
-  it('comment line with {meta+ß}', function () {
-    cy.get('@line')
-      .type('text')
-      .type(`{${metaKey}+ß}`)
-      .should('have.text', '% text')
-
-    cy.get('@line').type(`{${metaKey}+ß}`).should('have.text', 'text')
-  })
-
   it('comment line with {ctrl+#}', function () {
     cy.get('@line').type('text')
     cy.get('@editor').trigger('keydown', { key: '#', ctrlKey: true })