aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2015-01-10 16:01:40 +0000
committerStephen Blott2015-01-10 16:21:28 +0000
commit704ae28629154a732e20e16d56b23af265d51b85 (patch)
tree2a376ded6d1f2890f345c04b5e09f5a49966c7a7
parentc554d1fd5b6d81506864516b6f86a14f8672bec5 (diff)
downloadvimium-704ae28629154a732e20e16d56b23af265d51b85.tar.bz2
Modes; better printable detection, move to keyboard_utils.
-rw-r--r--content_scripts/mode.coffee2
-rw-r--r--content_scripts/mode_insert.coffee2
-rw-r--r--lib/dom_utils.coffee3
-rw-r--r--lib/keyboard_utils.coffee6
4 files changed, 8 insertions, 5 deletions
diff --git a/content_scripts/mode.coffee b/content_scripts/mode.coffee
index 5c6201e0..19354d94 100644
--- a/content_scripts/mode.coffee
+++ b/content_scripts/mode.coffee
@@ -119,7 +119,7 @@ class Mode
@unshift
_name: "mode-#{@id}/suppressPrintableEvents"
keypress: (event) =>
- if DomUtils.isPrintable(event) and
+ if KeyboardUtils.isPrintable(event) and
event.srcElement == @options.suppressPrintableEvents then @suppressEvent else @continueBubbling
Mode.updateBadge() if @badge
diff --git a/content_scripts/mode_insert.coffee b/content_scripts/mode_insert.coffee
index b907f22e..31bae8ec 100644
--- a/content_scripts/mode_insert.coffee
+++ b/content_scripts/mode_insert.coffee
@@ -121,7 +121,7 @@ new class ContentEditableTrap extends Mode
element = document.getSelection()?.anchorNode?.parentElement
return element?.isContentEditable and
document.activeElement and
- DomUtils. isPrintable event and
+ KeyboardUtils.isPrintable(event) and
DomUtils.isDOMDescendant document.activeElement, element
root = exports ? window
diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee
index fd2427c4..322188b3 100644
--- a/lib/dom_utils.coffee
+++ b/lib/dom_utils.coffee
@@ -212,8 +212,5 @@ DomUtils =
@remove()
false
- isPrintable: (event) ->
- not (event.metaKey or event.ctrlKey or event.altKey)
-
root = exports ? window
root.DomUtils = DomUtils
diff --git a/lib/keyboard_utils.coffee b/lib/keyboard_utils.coffee
index d2a843f9..30d99656 100644
--- a/lib/keyboard_utils.coffee
+++ b/lib/keyboard_utils.coffee
@@ -55,6 +55,12 @@ KeyboardUtils =
# c-[ is mapped to ESC in Vim by default.
(event.keyCode == @keyCodes.ESC) || (event.ctrlKey && @getKeyChar(event) == '[')
+ # TODO. This is probably a poor way of detecting printable characters. However, it shouldn't incorrectly
+ # identify any of chrome's own keyboard shortcuts as printable.
+ isPrintable: (event) ->
+ return false if event.metaKey or event.ctrlKey or event.altKey
+ @getKeyChar(event)?.length == 1
+
KeyboardUtils.init()
root = exports ? window