-
Notifications
You must be signed in to change notification settings - Fork 974
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -198,6 +198,18 @@ function hasSelection (node) { | |
return false | ||
} | ||
|
||
/** | ||
* Whether an element is editable or can be typed into. | ||
* @param {Element} elem | ||
* @return {boolean} | ||
*/ | ||
function isEditable (elem) { | ||
// TODO: find other node types that are editable | ||
return (elem.contentEditable === 'true' || | ||
elem.nodeName === 'INPUT' || | ||
elem.nodeName === 'TEXTAREA') | ||
} | ||
|
||
document.addEventListener('contextmenu', (e) => { | ||
var name = e.target.nodeName.toUpperCase() | ||
var nodeProps = { | ||
|
@@ -211,6 +223,7 @@ document.addEventListener('contextmenu', (e) => { | |
}, false) | ||
|
||
var shiftDown = false | ||
var cmdDown = false | ||
document.onkeydown = (e) => { | ||
switch (e.keyCode) { | ||
case KeyCodes.ESC: | ||
|
@@ -219,24 +232,42 @@ document.onkeydown = (e) => { | |
break | ||
case KeyCodes.BACKSPACE: | ||
const msg = shiftDown ? messages.GO_FORWARD : messages.GO_BACK | ||
const elem = document.activeElement | ||
if (elem.contentEditable !== 'true' && | ||
elem.nodeName !== 'INPUT' && | ||
elem.nodeName !== 'TEXTAREA') { | ||
// TODO: find other node types where this shortcut should be disabled | ||
if (!isEditable(document.activeElement)) { | ||
ipc.send(msg) | ||
} | ||
break | ||
case KeyCodes.SHIFT: | ||
shiftDown = true | ||
break | ||
case KeyCodes.CMD1: | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
bbondy
Member
|
||
cmdDown = true | ||
break | ||
case KeyCodes.CMD2: | ||
cmdDown = true | ||
break | ||
This comment has been minimized.
Sorry, something went wrong.
bbondy
Member
|
||
case KeyCodes.LEFT: | ||
if (cmdDown && !isEditable(document.activeElement)) { | ||
ipc.send(messages.GO_BACK) | ||
} | ||
break | ||
case KeyCodes.RIGHT: | ||
if (cmdDown && !isEditable(document.activeElement)) { | ||
ipc.send(messages.GO_FORWARD) | ||
} | ||
break | ||
} | ||
} | ||
document.onkeyup = (e) => { | ||
switch (e.keyCode) { | ||
case KeyCodes.SHIFT: | ||
shiftDown = false | ||
break | ||
case KeyCodes.CMD1: | ||
cmdDown = false | ||
break | ||
case KeyCodes.CMD2: | ||
cmdDown = false | ||
break | ||
} | ||
} | ||
|
||
|
3 comments
on commit 735a60a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
++ great stuff
Can we do this for the chrome inputs too? (urlbar and findbar, but we'll have others later like in preferences)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bbondy cmd+left,right are already mapped to jump to start/end of line in chrome inputs (by the operating system)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bbondy cmd+left,right are already mapped to jump to start/end of line in chrome inputs (by the operating system)
Sorry if that's the case, I have a VM so hard to tell because they rewrite those.
Should this be OSX only and command on windows?