Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Unified Diff: go-back-with-backspace/content_script.js

Issue 2326083002: Attach to window, add some editable markers, and add a license file. (Closed) Base URL: https://chromium.googlesource.com/chromium/extensions-by-google.git@master
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « go-back-with-backspace/LICENSE ('k') | go-back-with-backspace/is_editable.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: go-back-with-backspace/content_script.js
diff --git a/go-back-with-backspace/content_script.js b/go-back-with-backspace/content_script.js
index 32fff927f8e80fe94fee0fc0c711ce42554a484f..ba90ed7b77d216a3357fb64941dbd115edd1da42 100644
--- a/go-back-with-backspace/content_script.js
+++ b/go-back-with-backspace/content_script.js
@@ -1,11 +1,15 @@
// Listen for shift-backspace or unmodified backspace and navigate if not in
-// an editable field.
-document.addEventListener('keydown', function(e) {
+// an editable field. We capture the event at the Window to let any handlers
+// or listeners registered on the Document have a chance to handle it first.
+window.addEventListener('keydown', function(e) {
+ // Listening on the Window means the event has no path, so we'll have to
+ // look at the focused (active) element.
if (e.key === 'Backspace' &&
+ !e.defaultPrevented &&
!e.altKey &&
!e.ctrlKey &&
!e.metaKey &&
- !isEditable(e.path)) {
+ !isEditable(document.activeElement)) {
ojan 2016/09/09 18:06:30 This won't do the right thing with shadow DOM. h
e.shiftKey ? window.history.forward(): window.history.back();
e.preventDefault();
}
« no previous file with comments | « go-back-with-backspace/LICENSE ('k') | go-back-with-backspace/is_editable.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698