From b63c810ef6e18c736579e7844fba56edcd7590f6 Mon Sep 17 00:00:00 2001 From: jez Date: Mon, 16 May 2011 11:21:35 -0400 Subject: Don't enter insert mode when clicking on radio buttons and checkboxes. This closes issue #149. Tighten up the check for contentEditable as well -- isContentEditable covers the case where editability is inherited. See http://www.w3.org/TR/html5/editing.html#contenteditable for more details. --- vimiumFrontend.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/vimiumFrontend.js b/vimiumFrontend.js index 2ac7c32c..de21c682 100644 --- a/vimiumFrontend.js +++ b/vimiumFrontend.js @@ -542,14 +542,17 @@ function isEmbed(element) { return ["embed", "object"].indexOf(element.nodeName. * Input or text elements are considered focusable and able to receieve their own keyboard events, * and will enter enter mode if focused. Also note that the "contentEditable" attribute can be set on * any element which makes it a rich text editor, like the notes on jjot.com. - * Note: we used to discriminate for text-only inputs, but this is not accurate since all input fields - * can be controlled via the keyboard, particuarlly SELECT combo boxes. */ function isEditable(target) { - if (target.getAttribute("contentEditable") == "true") + if (target.isContentEditable) return true; - var focusableInputs = ["input", "textarea", "select", "button"]; - return focusableInputs.indexOf(target.nodeName.toLowerCase()) >= 0; + var nodeName = target.nodeName.toLowerCase(); + // use a blacklist instead of a whitelist because new form controls are still being implemented for html5 + var noFocus = ["radio", "checkbox"]; + if (nodeName == "input" && noFocus.indexOf(target.type) == -1) + return true; + var focusableElements = ["textarea", "select"]; + return focusableElements.indexOf(nodeName) >= 0; } function enterInsertMode() { -- cgit v1.2.3