From 145c854b5ec0f0ec22e6f4c05bf9470b57f7580f Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Sat, 22 Sep 2007 14:50:19 +0000 Subject: [PATCH] process link text only find modifiers \[uU] before looking for capitalized letters when 'smartcase' is set --- NEWS | 1 + chrome/content/vimperator/commands.js | 26 ++++++++++++++++++++---- chrome/content/vimperator/find.js | 29 +++++++++++++++------------ 3 files changed, 39 insertions(+), 17 deletions(-) diff --git a/NEWS b/NEWS index 290ee2de..9d474404 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,7 @@
 2007-XX-XX:
 	* version 0.5.2
+  	* :buffer partial_string works now as in vim, and with ! even better
 	* merge the existing status bar with the standard FF status bar so that
 	  security information and extension buttons are included
 	* added new :sidebar and :sbclose commands
diff --git a/chrome/content/vimperator/commands.js b/chrome/content/vimperator/commands.js
index d09a7f00..2d2ab225 100644
--- a/chrome/content/vimperator/commands.js
+++ b/chrome/content/vimperator/commands.js
@@ -318,22 +318,40 @@ function Commands() //{{{
     ));
     addDefaultCommand(new Command(["b[uffer]"],
         // TODO: move to v.tabs/buffers
-        function(args)
+        function(args, special)
         {
             var match;
             if (match = args.match(/^(\d+):?/))
                 return vimperator.tabs.select(parseInt(match[1]) - 1, false); // make it zero-based
+
+            var matches = [];
+            var lower_args = args.toLowerCase();
+            var first = vimperator.tabs.index() + 1;
             for (var i = 0; i < getBrowser().browsers.length; i++)
             {
-                var url = getBrowser().getBrowserAtIndex(i).contentDocument.location.href;
+                var index = (i + first) % getBrowser().browsers.length;
+                var url = getBrowser().getBrowserAtIndex(index).contentDocument.location.href;
+                var title = getBrowser().getBrowserAtIndex(index).contentDocument.title.toLowerCase();
                 if (url == args)
-                    return vimperator.tabs.select(i, false);
+                    return vimperator.tabs.select(index, false);
+
+                if (url.indexOf(args) >= 0 || title.indexOf(lower_args) >= 0)
+                    matches.push(index);
             }
+            if (matches.length == 0)
+                vimperator.echoerr("E94: No matching buffer for " + args);
+            else if (matches.length > 1 && !special)
+                vimperator.echoerr("E93: More than one match for " + args);
+            else
+                vimperator.tabs.select(matches[0], false);
         },
         {
-            usage: ["b[uffer] {url|index}"],
+            usage: ["b[uffer][!] {url|index}"],
             short_help: "Go to buffer from buffer list",
             help: "Argument can be either the buffer index or the full URL.
" + + "If argument is neither a full URL nor an index but uniquely identifies a buffer, " + + "it is selected. With [!] the next buffer matching the argument " + + "is selected, even if it cannot be identified uniquely.
" + "Use b as a shortcut to open this prompt.", completer: function(filter) { return vimperator.completion.get_buffer_completions(filter); } } diff --git a/chrome/content/vimperator/find.js b/chrome/content/vimperator/find.js index 0e47db0b..55531ff3 100644 --- a/chrome/content/vimperator/find.js +++ b/chrome/content/vimperator/find.js @@ -70,6 +70,19 @@ function Search() //{{{ search_pattern = pattern; + // links only search - \u wins if both modifiers specified + if (/\\u/.test(pattern)) + links_only = false; + else if (/\U/.test(pattern)) + links_only = true; + else if (vimperator.options["linksearch"]) + links_only = true; + else + links_only = false; + + // strip links-only modifiers + pattern = pattern.replace(/(\\)?\\[uU]/g, function($0, $1) { return $1 ? $0 : "" }); + // case sensitivity - \c wins if both modifiers specified if (/\c/.test(pattern)) case_sensitive = false; @@ -82,20 +95,10 @@ function Search() //{{{ else case_sensitive = true; - // links only search - \u wins if both modifiers specified - if (/\\u/.test(pattern)) - links_only = false; - else if (/\U/.test(pattern)) - links_only = true; - else if (vimperator.options["linksearch"]) - links_only = true; - else - links_only = false; + // strip case-sensitive modifiers + pattern = pattern.replace(/(\\)?\\[cC]/g, function($0, $1) { return $1 ? $0 : "" }); - // strip modifiers - pattern = pattern.replace(/(\\)?\\[cCuU]/g, function($0, $1) { return $1 ? $0 : "" }); - - // remove the modifer escape \ + // remove any modifer escape \ pattern = pattern.replace(/\\(\\[cCuU])/g, '$1') search_string = pattern;