mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-15 21:48:20 +02:00
Handle multi-character keys in iD.ui.cmd (closes #2786)
This commit is contained in:
+14
-12
@@ -1,28 +1,30 @@
|
||||
// Translate a MacOS key command into the appropriate Windows/Linux equivalent.
|
||||
// For example, ⌘Z -> Ctrl+Z
|
||||
iD.ui.cmd = function(code) {
|
||||
if (iD.detect().os === 'mac')
|
||||
if (iD.detect().os === 'mac') {
|
||||
return code;
|
||||
|
||||
var replacements = {
|
||||
'⌘': 'Ctrl',
|
||||
'⇧': 'Shift',
|
||||
'⌥': 'Alt',
|
||||
'⌫': 'Backspace',
|
||||
'⌦': 'Delete'
|
||||
}, keys = [];
|
||||
}
|
||||
|
||||
if (iD.detect().os === 'win') {
|
||||
if (code === '⌘⇧Z') return 'Ctrl+Y';
|
||||
}
|
||||
|
||||
var result = '',
|
||||
replacements = {
|
||||
'⌘': 'Ctrl',
|
||||
'⇧': 'Shift',
|
||||
'⌥': 'Alt',
|
||||
'⌫': 'Backspace',
|
||||
'⌦': 'Delete'
|
||||
};
|
||||
|
||||
for (var i = 0; i < code.length; i++) {
|
||||
if (code[i] in replacements) {
|
||||
keys.push(replacements[code[i]]);
|
||||
result += replacements[code[i]] + '+';
|
||||
} else {
|
||||
keys.push(code[i]);
|
||||
result += code[i];
|
||||
}
|
||||
}
|
||||
|
||||
return keys.join('+');
|
||||
return result;
|
||||
};
|
||||
|
||||
+20
-3
@@ -14,12 +14,29 @@ describe('iD.ui.cmd', function () {
|
||||
|
||||
it('does not overwrite mac keybindings', function () {
|
||||
os = 'mac';
|
||||
expect(iD.ui.cmd('⌘a')).to.eql('⌘a');
|
||||
expect(iD.ui.cmd('⌘A')).to.eql('⌘A');
|
||||
});
|
||||
|
||||
it('changes keys to linux versions', function () {
|
||||
os = 'linux';
|
||||
expect(iD.ui.cmd('⌘a')).to.eql('Ctrl+a');
|
||||
expect(iD.ui.cmd('⇧a')).to.eql('Shift+a');
|
||||
expect(iD.ui.cmd('⌘A')).to.eql('Ctrl+A');
|
||||
expect(iD.ui.cmd('⇧A')).to.eql('Shift+A');
|
||||
expect(iD.ui.cmd('⌘⇧A')).to.eql('Ctrl+Shift+A');
|
||||
expect(iD.ui.cmd('⌘⇧Z')).to.eql('Ctrl+Shift+Z');
|
||||
});
|
||||
|
||||
it('changes keys to win versions', function () {
|
||||
os = 'win';
|
||||
expect(iD.ui.cmd('⌘A')).to.eql('Ctrl+A');
|
||||
expect(iD.ui.cmd('⇧A')).to.eql('Shift+A');
|
||||
expect(iD.ui.cmd('⌘⇧A')).to.eql('Ctrl+Shift+A');
|
||||
expect(iD.ui.cmd('⌘⇧Z')).to.eql('Ctrl+Y'); // special case
|
||||
});
|
||||
|
||||
it('handles multi-character keys', function () {
|
||||
os = 'win';
|
||||
expect(iD.ui.cmd('f11')).to.eql('f11');
|
||||
expect(iD.ui.cmd('⌘plus')).to.eql('Ctrl+plus');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user