From c835fb63c391fcf99b95d850c55140403b1647f2 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 1 Apr 2015 12:52:46 -0700 Subject: [PATCH] Add select all on focus behavior to entity properties window --- examples/html/entityProperties.html | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/examples/html/entityProperties.html b/examples/html/entityProperties.html index 1c5fd58084..cdd0fa4773 100644 --- a/examples/html/entityProperties.html +++ b/examples/html/entityProperties.html @@ -477,6 +477,28 @@ ev.initEvent("change", true, true); document.activeElement.dispatchEvent(ev); } + + // For input and textarea elements, select all of the text on focus + // WebKit-based browsers, such as is used with QWebView, have a quirk + // where the mouseup event comes after the focus event, causing the + // text to be deselected immediately after selecting all of the text. + // To make this work we block the first mouseup event after the elements + // received focus. If we block all mouseup events the user will not + // be able to click within the selected text. + var els = document.querySelectorAll("input, textarea"); + for (var i = 0; i < els.length; i++) { + var clicked = false; + els[i].onfocus = function() { + this.select(); + clicked = false; + }; + els[i].onmouseup = function(e) { + if (!clicked) { + e.preventDefault(); + clicked = true; + } + }; + } }