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

GitOrigin-RevId: dd08778ea3621eefa75f306b2dada3f2c484f76c
This commit is contained in:
Alf Eaton 2023-05-16 13:20:47 +01:00 committed by Copybot
parent c8c17bca38
commit c8a72e96d4
2 changed files with 16 additions and 20 deletions

View file

@ -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,

View file

@ -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 })