Open Bug 627640 Opened 13 years ago Updated 13 years ago

Focus to the main input is lot every time you click anywhere on Chatzilla

Categories

(Other Applications :: ChatZilla, defect)

x86
All
defect
Not set
normal

Tracking

(Not tracked)

UNCONFIRMED

People

(Reporter: jdecaron, Assigned: rginda)

Details

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13
Build Identifier: 0.9.86-rdmsoft

index 7480c4e..fc4d94e 100755
--- a/content/chatzilla/handlers.js
+++ b/content/chatzilla/handlers.js
@@ -111,6 +111,7 @@ function initHandlers()
     node.active = false;
     node = document.getElementById("security-button");
     node.addEventListener("dblclick", onSecurityIconDblClick, false);
+    document.addEventListener("keypress", onDocumentKeyPress, false);

     window.onkeypress = onWindowKeyPress;

@@ -357,6 +358,16 @@ function onTooltip(event)
     return false;
 }

+function onDocumentKeyPress(e)
+{
+    if(document.activeElement.tagName == 'browser')
+    {
+        var input = document.getElementById('input');
+        input.focus();
+        input.value += String.fromCharCode(e.charCode));
+    }
+}
+

Reproducible: Always

Steps to Reproduce:
1. Give the focus to any window on your desktop.
2. Click back on Chatzilla on the main chat element or anywhere that you doesn't necessary need to type.
Actual Results:  
Your text input lose focus, if you don't pay close attention you can easily type 10-15 characters before you realize that you weren't typing anything.

Expected Results:  
Fill the typed characters into the input box.
This code does add 2 bugs that has been found already, I fixed one (Ctrl+C wasn't working in the main window). But it still breaks the title modification for channels.

diff --git a/content/chatzilla/handlers.js b/content/chatzilla/handlers.js
index 7480c4e..6f0abe6 100755
--- a/content/chatzilla/handlers.js
+++ b/content/chatzilla/handlers.js
@@ -111,6 +111,7 @@ function initHandlers()
     node.active = false;
     node = document.getElementById("security-button");
     node.addEventListener("dblclick", onSecurityIconDblClick, false);
+    document.addEventListener("keypress", onDocumentKeyPress, false);

     window.onkeypress = onWindowKeyPress;

@@ -357,6 +358,16 @@ function onTooltip(event)
     return false;
 }

+function onDocumentKeyPress(e)
+{
+    if(document.activeElement.tagName == 'browser' && !(e.ctrlKey || e.altKey))
+    {
+        var input = document.getElementById('input');
+        input.focus();
+        input.value += String.fromCharCode(e.charCode);
+    }
+}
+
 function onInputKeyPress (e)
 {
     if (client.prefs["outgoing.colorCodes"])
It's possible to fix the title bug by doing a document search "document.getElementByTagName('textbox')" and not focus the input box if there's already an textbox that has the focus somewhere.
ChatZilla has a "vi style" shortcut key, pressing the escape key will always focus the input box.

Bash escape a few times before you begin typing - Trying to catch all the edge cases with some sort of key press handler on elements that are not the input box will be a nightmare.
You need to log in before you can comment on or make changes to this bug.