mirror of
https://github.com/FoggedLens/iD.git
synced 2026-04-21 11:16:36 +02:00
Ignore Ctrl and Alt if both are present (e.g. AltGr on Windows)
(see #4096)
This commit is contained in:
@@ -66,8 +66,10 @@ export function d3keybinding(namespace) {
|
||||
}
|
||||
|
||||
// test modifier keys
|
||||
if (event.ctrlKey !== binding.event.modifiers.ctrlKey) return false;
|
||||
if (event.altKey !== binding.event.modifiers.altKey) return false;
|
||||
if (!(event.ctrlKey && event.altKey)) { // if both are set, assume AltGr and skip it - #4096
|
||||
if (event.ctrlKey !== binding.event.modifiers.ctrlKey) return false;
|
||||
if (event.altKey !== binding.event.modifiers.altKey) return false;
|
||||
}
|
||||
if (event.metaKey !== binding.event.modifiers.metaKey) return false;
|
||||
if (testShift && event.shiftKey !== binding.event.modifiers.shiftKey) return false;
|
||||
|
||||
|
||||
@@ -38,6 +38,30 @@ describe('d3.keybinding', function() {
|
||||
expect(spy).to.have.been.calledOnce;
|
||||
});
|
||||
|
||||
it('matches the binding even when shift is present', function () {
|
||||
d3.select(document).call(keybinding.on('A', spy));
|
||||
|
||||
happen.keydown(document, {keyCode: 65, shiftKey: true});
|
||||
expect(spy).to.have.been.calledOnce;
|
||||
});
|
||||
|
||||
it('matches shifted bindings before unshifted bindings', function () {
|
||||
var spy2 = sinon.spy();
|
||||
d3.select(document).call(keybinding.on('A', spy2));
|
||||
d3.select(document).call(keybinding.on('⇧A', spy));
|
||||
|
||||
happen.keydown(document, {keyCode: 65, shiftKey: true});
|
||||
expect(spy).to.have.been.calledOnce;
|
||||
expect(spy2).not.to.have.been.called;
|
||||
});
|
||||
|
||||
it('ignores alt and control if both are present (e.g. as AltGr) #4096', function () {
|
||||
d3.select(document).call(keybinding.on('A', spy));
|
||||
|
||||
happen.keydown(document, {keyCode: 65, altKey: true, ctrlKey: true});
|
||||
expect(spy).to.have.been.calledOnce;
|
||||
});
|
||||
|
||||
it('adds multiple bindings given an array of keys', function () {
|
||||
d3.select(document).call(keybinding.on(['A','B'], spy));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user