From de6c623b65f072650e70c8c5acf8c9d809bc64f5 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Fri, 4 Mar 2016 06:44:36 +0000 Subject: Refactor hints; no need to guard against no rect. - The check for whether a rect is defined is only used in one of the three cases. So we don't need it. - Also, better veriable name. --- content_scripts/link_hints.coffee | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'content_scripts') diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index cfacb862..57fec611 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -393,7 +393,7 @@ class LinkHintsMode else if userMightOverType # Block keyboard events while the user is still typing. The intention is to prevent the user from # inadvertently launching Vimium commands when (over-)typing the link text. - new TypingProtector 200, linkMatched?.rect, linkActivator + new TypingProtector 200, linkMatched.rect, linkActivator else DomUtils.flashRect linkMatched.rect linkActivator() @@ -633,24 +633,22 @@ class TypingProtector extends Mode constructor: (delay, rect, callback) -> @timer = Utils.setTimeout delay, => @exit() - handler = (event) => + resetExitTimer = (event) => clearTimeout @timer @timer = Utils.setTimeout delay, => @exit() super name: "hint/typing-protector" suppressAllKeyboardEvents: true - keydown: handler - keypress: handler - - if rect - # We keep a "flash" overlay active while the user is typing; this provides visual feeback that something - # has been selected. - flashEl = DomUtils.addFlashRect rect - @onExit -> DomUtils.removeElement flashEl + keydown: resetExitTimer + keypress: resetExitTimer @onExit callback + # We keep a "flash" overlay active while the user is typing; this provides visual feeback that something + # has been selected. + flashEl = DomUtils.addFlashRect rect + @onExit -> DomUtils.removeElement flashEl class WaitForEnter extends Mode constructor: (rect, callback) -> -- cgit v1.2.3