Re: [PATCH] optimize liverator.events.feedkeys
Thanks for review.
> Is it necessary to have two "<return>" srtings in regexp here?
>
> + var keyStrings = keys.split(/<return>|<cr>|<return>/i);
Thiis is a mistake
Best regards.
On Thu, Aug 14, 2008 at 9:53 PM, Konstantin Stepanov
<milezv@...> wrote:
> Is it necessary to have two "<return>" srtings in regexp here?
>
> + var keyStrings = keys.split(/<return>|<cr>|<return>/i);
>
>
> 14.08.08, 15:46, "M.Terada" :
>
>> Hi
>> Now, completions list has been to opened dualing "wildoptions" is
>> setted to "auto"
>> when we type a map which is seted like ":echo 'OK'"
>> This patch fixes that.
>> Best regards.
>> --
>> teramako
>> http://d.hatena.ne.jp/teramako/
>
> _______________________________________________
> Vimperator mailing list
> Vimperator@...
> https://www.mozdev.org/mailman/listinfo/vimperator
>
>
--
teramako
http://d.hatena.ne.jp/teramako/
Index: src/content/events.js
===================================================================
RCS file: /cvs/vimperator/src/content/events.js,v
retrieving revision 1.122
diff -u -r1.122 events.js
--- src/content/events.js 14 Aug 2008 09:38:59 -0000 1.122
+++ src/content/events.js 14 Aug 2008 13:00:15 -0000
@@ -779,67 +779,91 @@
noremap = !!noremap;
- for (var i = 0; i < keys.length; i++)
+ function dispatchKeyEvents(keys)
{
- var charCode = keys.charCodeAt(i);
- var keyCode = 0;
- var shift = false, ctrl = false, alt = false, meta = false;
- //if (charCode == 92) // the '\' key FIXME: support the escape key
- if (charCode == 60 && !escapeKey) // the '<' key starts a complex key
+ for (var i = 0; i < keys.length; i++)
{
- var matches = keys.substr(i + 1).match(/([CSMAcsma]-)*([^>]+)/);
- if (matches && matches[2])
+ var charCode = keys.charCodeAt(i);
+ var keyCode = 0;
+ var shift = false, ctrl = false, alt = false, meta = false;
+ //if (charCode == 92) // the '\' key FIXME: support the escape key
+ if (charCode == 60 && !escapeKey) // the '<' key starts a complex key
{
- if (matches[1]) // check for modifiers
+ var matches = keys.substr(i + 1).match(/([CSMAcsma]-)*([^>]+)/);
+ if (matches && matches[2])
{
- ctrl = /[cC]-/.test(matches[1]);
- alt = /[aA]-/.test(matches[1]);
- shift = /[sS]-/.test(matches[1]);
- meta = /[mM]-/.test(matches[1]);
- }
- if (matches[2].length == 1)
- {
- if (!ctrl && !alt && !shift && !meta)
- return false; // an invalid key like <a>
- charCode = matches[2].charCodeAt(0);
- }
- else if (matches[2].toLowerCase() == "space")
- {
- charCode = 32;
- }
- else if (keyCode = getKeyCode(matches[2]))
- {
- charCode = 0;
- }
- else // an invalid key like <A-xxx> was found, stop propagation here (like Vim)
- {
- return false;
+ if (matches[1]) // check for modifiers
+ {
+ ctrl = /[cC]-/.test(matches[1]);
+ alt = /[aA]-/.test(matches[1]);
+ shift = /[sS]-/.test(matches[1]);
+ meta = /[mM]-/.test(matches[1]);
+ }
+ if (matches[2].length == 1)
+ {
+ if (!ctrl && !alt && !shift && !meta)
+ return false; // an invalid key like <a>
+ charCode = matches[2].charCodeAt(0);
+ }
+ else if (matches[2].toLowerCase() == "space")
+ {
+ charCode = 32;
+ }
+ else if (keyCode = getKeyCode(matches[2]))
+ {
+ charCode = 0;
+ }
+ else // an invalid key like <A-xxx> was found, stop propagation here (like Vim)
+ {
+ return false;
+ }
+
+ i += matches[0].length + 1;
}
+ }
+ else // a simple key
+ {
+ // FIXME: does not work for non A-Z keys like Ã,Ã,...
+ shift = (keys[i] >= "A" && keys[i] <= "Z");
+ }
- i += matches[0].length + 1;
+ var elem = window.document.commandDispatcher.focusedElement;
+ if (!elem)
+ elem = window.content;
+
+ var evt = doc.createEvent("KeyEvents");
+ evt.initKeyEvent("keypress", true, true, view, ctrl, alt, shift, meta, keyCode, charCode);
+ evt.noremap = noremap;
+ elem.dispatchEvent(evt);
+ // stop feeding keys if page loading failed
+ if (liberator.modes.isReplaying)
+ {
+ if (!waitForPageLoaded())
+ return;
+ // else // a short break between keys often helps
+ // liberator.sleep(50);
}
}
- else // a simple key
- {
- // FIXME: does not work for non A-Z keys like Ã,Ã,...
- shift = (keys[i] >= "A" && keys[i] <= "Z");
- }
+ }
- var elem = window.document.commandDispatcher.focusedElement;
- if (!elem)
- elem = window.content;
-
- var evt = doc.createEvent("KeyEvents");
- evt.initKeyEvent("keypress", true, true, view, ctrl, alt, shift, meta, keyCode, charCode);
- evt.noremap = noremap;
- elem.dispatchEvent(evt);
- // stop feeding keys if page loading failed
- if (liberator.modes.isReplaying)
- {
- if (!waitForPageLoaded())
- return;
- // else // a short break between keys often helps
- // liberator.sleep(50);
+ var keyStrings = keys.split(/<return>|<cr>|<enter>/i);
+ var length = keyStrings.length;
+ for (var i = 0; i < length; i++)
+ {
+ var keys = keyStrings[i];
+ if (keys == "")
+ continue;
+ else if (keys.charAt(0) == ":")
+ {
+ if (i == length -1)
+ liberator.commandline.open(":",keys.substr(1),liberator.modes.EX);
+ else
+ liberator.execute(keys);
+ }
+ else
+ {
+ keys += i == length - 1 ? "" : "<Return>";
+ dispatchKeyEvents(keys);
}
}
return true;
Index: src/content/events.js
===================================================================
RCS file: /cvs/vimperator/src/content/events.js,v
retrieving revision 1.122
diff -u -r1.122 events.js
--- src/content/events.js 14 Aug 2008 09:38:59 -0000 1.122
+++ src/content/events.js 14 Aug 2008 13:00:15 -0000
@@ -779,67 +779,91 @@
noremap = !!noremap;
- for (var i = 0; i < keys.length; i++)
+ function dispatchKeyEvents(keys)
{
- var charCode = keys.charCodeAt(i);
- var keyCode = 0;
- var shift = false, ctrl = false, alt = false, meta = false;
- //if (charCode == 92) // the '\' key FIXME: support the escape key
- if (charCode == 60 && !escapeKey) // the '<' key starts a complex key
+ for (var i = 0; i < keys.length; i++)
{
- var matches = keys.substr(i + 1).match(/([CSMAcsma]-)*([^>]+)/);
- if (matches && matches[2])
+ var charCode = keys.charCodeAt(i);
+ var keyCode = 0;
+ var shift = false, ctrl = false, alt = false, meta = false;
+ //if (charCode == 92) // the '\' key FIXME: support the escape key
+ if (charCode == 60 && !escapeKey) // the '<' key starts a complex key
{
- if (matches[1]) // check for modifiers
+ var matches = keys.substr(i + 1).match(/([CSMAcsma]-)*([^>]+)/);
+ if (matches && matches[2])
{
- ctrl = /[cC]-/.test(matches[1]);
- alt = /[aA]-/.test(matches[1]);
- shift = /[sS]-/.test(matches[1]);
- meta = /[mM]-/.test(matches[1]);
- }
- if (matches[2].length == 1)
- {
- if (!ctrl && !alt && !shift && !meta)
- return false; // an invalid key like <a>
- charCode = matches[2].charCodeAt(0);
- }
- else if (matches[2].toLowerCase() == "space")
- {
- charCode = 32;
- }
- else if (keyCode = getKeyCode(matches[2]))
- {
- charCode = 0;
- }
- else // an invalid key like <A-xxx> was found, stop propagation here (like Vim)
- {
- return false;
+ if (matches[1]) // check for modifiers
+ {
+ ctrl = /[cC]-/.test(matches[1]);
+ alt = /[aA]-/.test(matches[1]);
+ shift = /[sS]-/.test(matches[1]);
+ meta = /[mM]-/.test(matches[1]);
+ }
+ if (matches[2].length == 1)
+ {
+ if (!ctrl && !alt && !shift && !meta)
+ return false; // an invalid key like <a>
+ charCode = matches[2].charCodeAt(0);
+ }
+ else if (matches[2].toLowerCase() == "space")
+ {
+ charCode = 32;
+ }
+ else if (keyCode = getKeyCode(matches[2]))
+ {
+ charCode = 0;
+ }
+ else // an invalid key like <A-xxx> was found, stop propagation here (like Vim)
+ {
+ return false;
+ }
+
+ i += matches[0].length + 1;
}
+ }
+ else // a simple key
+ {
+ // FIXME: does not work for non A-Z keys like Ã,Ã,...
+ shift = (keys[i] >= "A" && keys[i] <= "Z");
+ }
- i += matches[0].length + 1;
+ var elem = window.document.commandDispatcher.focusedElement;
+ if (!elem)
+ elem = window.content;
+
+ var evt = doc.createEvent("KeyEvents");
+ evt.initKeyEvent("keypress", true, true, view, ctrl, alt, shift, meta, keyCode, charCode);
+ evt.noremap = noremap;
+ elem.dispatchEvent(evt);
+ // stop feeding keys if page loading failed
+ if (liberator.modes.isReplaying)
+ {
+ if (!waitForPageLoaded())
+ return;
+ // else // a short break between keys often helps
+ // liberator.sleep(50);
}
}
- else // a simple key
- {
- // FIXME: does not work for non A-Z keys like Ã,Ã,...
- shift = (keys[i] >= "A" && keys[i] <= "Z");
- }
+ }
- var elem = window.document.commandDispatcher.focusedElement;
- if (!elem)
- elem = window.content;
-
- var evt = doc.createEvent("KeyEvents");
- evt.initKeyEvent("keypress", true, true, view, ctrl, alt, shift, meta, keyCode, charCode);
- evt.noremap = noremap;
- elem.dispatchEvent(evt);
- // stop feeding keys if page loading failed
- if (liberator.modes.isReplaying)
- {
- if (!waitForPageLoaded())
- return;
- // else // a short break between keys often helps
- // liberator.sleep(50);
+ var keyStrings = keys.split(/<return>|<cr>|<enter>/i);
+ var length = keyStrings.length;
+ for (var i = 0; i < length; i++)
+ {
+ var keys = keyStrings[i];
+ if (keys == "")
+ continue;
+ else if (keys.charAt(0) == ":")
+ {
+ if (i == length -1)
+ liberator.commandline.open(":",keys.substr(1),liberator.modes.EX);
+ else
+ liberator.execute(keys);
+ }
+ else
+ {
+ keys += i == length - 1 ? "" : "<Return>";
+ dispatchKeyEvents(keys);
}
}
return true;