From b8789c56b0ee96ee1eca75291028017c4f9d89cc Mon Sep 17 00:00:00 2001 From: Jez Ng Date: Sun, 22 Jan 2012 00:39:13 -0500 Subject: Make do defocusing. Vimium will try to blur the active element first. If there is no element to be blurred, we select the topmost frame instead. Thus the user is able to use to return Vimium fully to its 'default' state. Closes #426. --- vimiumFrontend.js | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'vimiumFrontend.js') diff --git a/vimiumFrontend.js b/vimiumFrontend.js index 6a3fd698..a175f0eb 100644 --- a/vimiumFrontend.js +++ b/vimiumFrontend.js @@ -510,6 +510,8 @@ function onKeydown(event) { } else if (isEscape(event)) { keyPort.postMessage({keyChar:"", frameId:frameId}); + handleEscapeForNormalMode(); + suppressEvent(event); } } @@ -980,6 +982,13 @@ function hideHelpDialog(clickEvent) { clickEvent.preventDefault(); } +function handleEscapeForNormalMode() { + if (document.activeElement !== document.body) + document.activeElement.blur(); + else if (window.top !== window.self) + chrome.extension.sendRequest({ handler: "focusTopFrame" }); +} + /* * A heads-up-display (HUD) for showing Vimium page operations. * Note: you cannot interact with the HUD until document.body is available. -- cgit v1.2.3