This commit is contained in:
Alex Yatskov 2016-03-28 19:06:01 -07:00
parent d77319e328
commit 537d91dd10

View File

@ -27,32 +27,32 @@ class Client {
$('body').append(this.popup); $('body').append(this.popup);
chrome.runtime.onMessage.addListener(this.onMessage.bind(this)); chrome.runtime.onMessage.addListener(this.onMessage.bind(this));
window.addEventListener('mousedown', this.onMouseAction.bind(this)); window.addEventListener('mousedown', this.onMouseDown.bind(this));
window.addEventListener('mousemove', this.onMouseAction.bind(this)); window.addEventListener('mousemove', this.onMouseMove.bind(this));
window.addEventListener('keydown', this.onKeyAction.bind(this)); window.addEventListener('keydown', this.onKeyDown.bind(this));
getState((state) => this.setEnabled(state === 'enabled')); getState((state) => this.setEnabled(state === 'enabled'));
} }
onKeyAction(e) { onKeyDown(e) {
if (!this.enabled) { if (this.enabled && this.lastMousePos !== null && (e.keyCode === 16 || e.charCode === 16)) {
return;
}
if (this.lastMousePos !== null && (e.keyCode === 16 || e.charCode === 16)) {
this.searchAtPoint(this.lastMousePos); this.searchAtPoint(this.lastMousePos);
} }
} }
onMouseAction(e) { onMouseMove(e) {
this.lastMousePos = {x: e.clientX, y: e.clientY}; this.lastMousePos = {x: e.clientX, y: e.clientY};
if (this.enabled && (e.shiftKey || e.which === 2)) {
if (!this.enabled) { this.searchAtPoint(this.lastMousePos);
return; }
} }
if (e.shiftKey || e.which === 2) { onMouseDown(e) {
this.lastMousePos = {x: e.clientX, y: e.clientY};
if (this.enabled && (e.shiftKey || e.which === 2)) {
this.searchAtPoint(this.lastMousePos); this.searchAtPoint(this.lastMousePos);
} else {
this.hidePopup();
} }
} }