M.Terada | 14 Aug 13:41

[PATCH] optimize liverator.events.feedkeys

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/
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 11:24:35 -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;
(Continue reading)

Konstantin Stepanov | 14 Aug 14:53
Favicon
Gravatar

Re: [PATCH] optimize liverator.events.feedkeys

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/+P9i1ojmF8zQARNC3f2A@public.gmane.org>

<div><p>Is it necessary to have two "&lt;return&gt;" srtings in regexp here?<br><br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var keyStrings = keys.split(/&lt;return&gt;|&lt;cr&gt;|&lt;return&gt;/i);<br><br><br>14.08.08, 15:46, "M.Terada" :<br><br>&gt; Hi<br>&gt; Now, completions list has been to opened dualing "wildoptions" is<br>&gt; setted to "auto"<br>&gt; when we type a map which is seted like ":echo 'OK'"<br>&gt; This patch fixes that.<br>&gt; Best regards.<br>&gt; -- <br>&gt; teramako<br>&gt; <a mce_href="http://d.hatena.ne.jp/teramako/" href="http://d.hatena.ne.jp/teramako/">http://d.hatena.ne.jp/teramako/</a>+P9i1ojmF8zQARNC3f2A <at> public.gmane.org&gt;<br></p></div>
M.Terada | 14 Aug 15:06

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;
Martin Stubenschrott | 15 Aug 16:47

Re: [PATCH] optimize liverator.events.feedkeys

Hi,

while i'd love to have such a patch, i was reluctant to write one myself
because unfortunatly it's much harder your patch.

While your's works faily well in standard cases, it fails for more
advanced uses which all work in vim:

1.) Command line mappings do not work anymore with "optimized" mappings:
  :map x :echo <S-Ins> 
  or:
  :map x :echo bla<c-w>

2.) Crazy manual mappings like:
  :cmap y <cr>
  :map x :echo "bla"y

3.) Commandline abbreviations like:
  :cabbr a aaa
  :map y :echo a<space>

While all these cases are surely not very common, I think correctness
must be valued over speed in this case. The way to go would be to check
each character for a (command line-) mapping/abbreviation, and only add
it to the command line string if there is no mapping, otherwise execute
it.

Now, that i think of it, probably wouldn't be toooo much work.
Hope you manage to do it (in a clean way).

best regards and thanks for looking into this, as that's actually my
main reason i have disabled wildoptions=auto myself for now :)

--
Martin
Martin Stubenschrott | 15 Aug 15:31

Re: [PATCH] optimize liverator.events.feedkeys

Konstantin Stepanov wrote:

> Is it necessary to have two "<return>" srtings in regexp here?

Good catch, I think I'll request cvs write access for you, so you could
also help me applying patches if you want, and also update your scripts
like colortab.js yourself.

Unless you don't think, that's worth it, I'll ask for an account for you
in the next days.

--
Martin

PS: Does anybody know, how good Mercurial support in mozdev is now? So,
whether it's worth to switch to it now.

Gmane