Ignore Ctrl and Alt if both are present (e.g. AltGr on Windows)

(see #4096)
This commit is contained in:
Bryan Housel
2017-06-09 11:42:35 -04:00
parent 70d0a68c6d
commit 2d665dbc1b
2 changed files with 28 additions and 2 deletions
+4 -2
View File
@@ -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;
+24
View File
@@ -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));