1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-21 22:07:59 +01:00

Many small bugfixes

changed wildsort -> wildoptions=sort
added completion for filenames
This commit is contained in:
Martin Stubenschrott
2007-04-29 15:04:00 +00:00
parent abeafde55f
commit d4844c2429
7 changed files with 95 additions and 37 deletions

View File

@@ -3,7 +3,8 @@ date:
* version 0.4
* extension GUID was changed to 'vimperator@mozdev.net' -> YOU WILL HAVE
TO UNINSTALL ANY OLD VIMPERATOR INSTALLATION BEFORE INSTALLING THIS VERSION
* support for 'wildmode' completion setting
* support for 'wildmode' completion setting with support for matching the
longest common substring
* changed regexp search to normal text search for completion -> massive speedup, but limited functionality
* support for :open ./ , :open .. and :open ... (patch from Lee Hinman)
'gu' and <BackSpace> goes up a directory component, gU and <C-BackSpace> to the root directory
@@ -12,7 +13,7 @@ date:
* :back! goes to beginning of history now
* diabled firefox 3.0 support for now, as there are just too many small
bugs
* :help section supported, :help set will show help for the :set command
* :help section supported, :help :set will show help for the :set command
(patch from Viktor Kojouharov)
* :source support, and auto-sourcing ~/.vimperatorrc on startup
* :javascript <<EOF support to execute multiline javascript code

1
TODO
View File

@@ -31,6 +31,7 @@ FEATURES:
6 :map commands to keys
6 autocommands (BrowserStart, BrowserQuit, TabClose, TabOpen, TabChanged, PageLoaded, any more?)
6 vim like mappings for caret mode and textboxes (i to start caret mode?)
http://nigel.mcnie.name/gnawt/ has a somewhat working implementation
6 pipe selected text/link/website to an external command
6 it would be nice to have :(undo|back|forward) <url> w/ tab completion support
6 macros (qq)

View File

@@ -151,4 +151,32 @@ function parseBookmarkString(str, res)
return true;
}
function getSearchEngines()
{
const nsSS = Components.classes["@mozilla.org/browser/search-service;1"].
getService(Components.interfaces.nsIBrowserSearchService);
var engines = nsSS.getVisibleEngines({ });
for(var i in engines)
{
alert(engines[i].alias);
if (!engines[i].alias || !engines[i].alias.match(/^\w+$/))
{
alias = engines[i].name.replace(/^\W*(\w+).*/, "$1").toLowerCase();
engines[i].alias = alias;
}
// alert(engines[i].alias);
// alert(engines[i].name);
// alert(engines[i].description);
}
// var def = nsSS.getDefaultEngine();
// if(def)
// {
// alert('DEFAULT'):
// alert(def.alias);
// }
// alert(def.name);
// alert(def.description);
}
// vim: set fdm=marker sw=4 ts=4 et:

View File

@@ -191,7 +191,7 @@ var g_commands = [/*{{{*/
["history", "hs"],
["history {filter}"],
"Show recently visited URLs",
"Open the preview window at the bottom of the screen for all history items which match the filter string either in the title or URL.",
"Open the preview window at the bottom of the screen for all history items which match the filter string either in the title or URL."+
"Close this window with <code>:pclose</code> or open entries with double click in the current tab or middle click in a new tab.",
hsshow,
function(filter) { return get_history_completions(filter); }
@@ -591,7 +591,7 @@ var g_mappings = [/*{{{*/
["t"],
["t"],
"Open one or more URLs in a new tab",
"Like <code class=mapping>o</code> but open URLs in a new tab."+
"Like <code class=mapping>o</code> but open URLs in a new tab.<br/>"+
"See <code class=command>:tabopen</code> for more details",
function(count) { openVimperatorBar('tabopen '); }
],
@@ -773,15 +773,15 @@ var g_mappings = [/*{{{*/
function(count) { stepInHistory(count > 0 ? count : 1); }
],
[
["gu", "<BackSpace>"],
["{count}gu", "{count}<BackSpace>"],
["gu", "<BS>"],
["{count}gu", "{count}<BS>"],
"Go to parent directory",
"Count is supported, <code class=mapping>2gu</code> on <code>http://www.example.com/dir1/dir2/file.htm</code> would open <code>http://www.example.com/dir1/</code>",
goUp
],
[
["gU", "<C-BackSpace>"],
["gU", "<C-BackSpace>"],
["gU", "<C-BS>"],
["gU", "<C-BS>"],
"Go to the root of the website",
"<code class=mapping>gU</code> on <code>http://www.example.com/dir1/dir2/file.htm</code> opens <code>http://www.example.com/</code>.<br/>"+
"When browsing a local directory, it goes to the root document.",
@@ -1954,8 +1954,8 @@ function set(args, special)
}
else
{
if (oper == '+' && !cur_val.match(val))
val = cur_val + ',' + val;
if (oper == '+' && !cur_val.match(val) && cur_val.length > 0)
val = cur_val + ',' + val;
if (oper == '-')
{
val = cur_val.replace(new RegExp(',?' + val), '');

View File

@@ -287,15 +287,16 @@ function build_longest_starting_substring(list, filter)/*{{{*/
/*
* filter a list of urls
*
* may consist of searchengines, boorkmarks and history,
* may consist of searchengines, filenames, bookmarks and history,
* depending on the 'complete' option
* if the 'complete' argument is passed like "h", it temproarily overrides the complete option
*/
function get_url_completions(filter)/*{{{*/
function get_url_completions(filter, complete)/*{{{*/
{
g_completions = [];
g_substrings = [];
var cpt = get_pref("complete");
var cpt = complete || get_pref("complete");
// join all completion arrays together
for (var i = 0; i < cpt.length; i++)
{
@@ -305,6 +306,8 @@ function get_url_completions(filter)/*{{{*/
g_completions = g_completions.concat(get_bookmark_completions(filter));
else if (cpt[i] == 'h')
g_completions = g_completions.concat(get_history_completions(filter));
else if (cpt[i] == 'f')
g_completions = g_completions.concat(get_file_completions(filter));
}
return g_completions;
@@ -321,7 +324,10 @@ function filter_url_array(urls, filter)/*{{{*/
if (!filter) return urls.map(function($_) {
return [$_[0], $_[1]]
});
var filter_length = filter.length;
filter = filter.toLowerCase();
/*
* Longest Common Subsequence
* This shouldn't use build_longest_common_substring
@@ -329,26 +335,29 @@ function filter_url_array(urls, filter)/*{{{*/
*/
for (var i = 0; i < urls.length; i++)
{
if (urls[i][0].indexOf(filter) == -1)
var url = urls[i][0].toLowerCase();
var title = urls[i][1].toLowerCase();
if (url.indexOf(filter) == -1)
{
if (urls[i][1].indexOf(filter) != -1)
additional_completions.push([urls[i][0], urls[i][1] ]);
if (title.indexOf(filter) != -1)
additional_completions.push([ urls[i][0], urls[i][1] ]);
continue;
}
if (g_substrings.length == 0) // Build the substrings
{
var last_index = urls[i][0].lastIndexOf(filter);
var url_length = urls[i][0].length;
for (var k = urls[i][0].indexOf(filter); k != -1 && k <= last_index; k = urls[i][0].indexOf(filter, k + 1))
var last_index = url.lastIndexOf(filter);
var url_length = url.length;
for (var k = url.indexOf(filter); k != -1 && k <= last_index; k = url.indexOf(filter, k + 1))
{
for (var l = k + filter_length; l <= url_length; l++)
g_substrings.push(urls[i][0].substring(k, l));
g_substrings.push(url.substring(k, l));
}
}
else
{
g_substrings = g_substrings.filter(function($_) {
return urls[i][0].indexOf($_) >= 0;
return url.indexOf($_) >= 0;
});
}
filtered.push([urls[i][0], urls[i][1]]);
@@ -380,7 +389,7 @@ function get_history_completions(filter)/*{{{*/
history.hidden = false;
var globalHistory = Components.classes["@mozilla.org/browser/global-history;2"].getService(Components.interfaces.nsIRDFDataSource);
history.database.AddDataSource(globalHistory);
history_completions = [];
g_history = [];
}
if (!history.ref)
@@ -414,10 +423,8 @@ function get_history_completions(filter)/*{{{*/
g_history.push([url, title]);
}
// if(url.toLowerCase().indexOf(filter.toLowerCase()) > -1)
history_loaded = true;
}
return filter_url_array(g_history, filter);
}/*}}}*/
@@ -431,14 +438,30 @@ function get_bookmark_completions(filter)/*{{{*/
bookmarks = []; // here getAllChildren will store the bookmarks
g_bookmarks = []; // also clear our bookmark cache
BookmarksUtils.getAllChildren(root, bookmarks);
// alert(bookmarks[0].length);
for(var i = 0; i < bookmarks.length; i++)
{
if (bookmarks[i][0] && bookmarks[i][1])
{
g_bookmarks.push([bookmarks[i][1].Value, bookmarks[i][0].Value ]);
}
// for(var j=0; j < bookmarks[i].length; j++)
// {
// if(bookmarks[i][2])
// alert("2: " + bookmarks[i][2].Value);
// if(bookmarks[i][3])
// alert("3: " + bookmarks[i][3].Value);
// if(bookmarks[i][4])
// alert("4: " + bookmarks[i][4].Value);
// if(bookmarks[i][5])
// alert("5: " + bookmarks[i][5].Value);
//alert("0: " + bookmarks[i][0].Value + " - 1: " + bookmarks[i][1].Value + "- 2:" + bookmarks[i][2].Value);// + "- 3:"+ bookmarks[i][3].Value + "- 4:" + bookmarks[i][4].Value);// + "- 5:" + bookmarks[i][5].Value);
//}
}
bookmarks_loaded = true;
}
return filter_url_array(g_bookmarks, filter);
}/*}}}*/

View File

@@ -64,15 +64,16 @@ var g_settings = [/*{{{*/
"Items which are completed at the :[tab]open prompt",
"Available items:<br>"+
"<ul><li><b>s</b>: Search machines</li><li>"+
" <b>b</b>: Bookmarks</li><li>"+
" <b>h</b>: History</li></ul>"+
"<b>f</b>: Local files</li><li>"+
"<b>b</b>: Bookmarks</li><li>"+
"<b>h</b>: History</li></ul>"+
"The order is important, so <code class=command>:set complete=bs</code> would list bookmarks first, and then any available quick searches.<br/>"+
"Set the <code class=setting>'wildsort'</code> setting if you want all entries sorted.",
"Add 'sort' to the <code class=setting>'wildoptions'</code> setting if you want all entries sorted.",
"charlist",
null,
function(value) { set_pref("complete", value); },
function() { return get_pref("complete"); },
"sbh",
"sfbh",
null
],
[
@@ -262,15 +263,19 @@ var g_settings = [/*{{{*/
null
],
[
["wildsort", "wis", "nowildsort", "nowis"],
["wildsort", "wis"],
"Define whether command line completion is sorted",
"If you don't want a sorted completion list, set this to false.",
"boolean",
["wildoptions", "wop"],
["wildoptions", "wop"],
"Change how command line completion is done",
"A list of words that change how command line completion is done.<br/>"+
"Currently only one word is allowed:<br/>"+
"<table><pre>"+
"<tr><td><b>sort</b></td><td>Always sorts completion list, overriding the <code class=setting>'complete'</code> option.</td></tr>" +
"</pre></table>",
"stringlist",
null,
function(value) { set_pref("wildsort", value); },
function() { return get_pref("wildsort"); },
false,
function(value) { set_pref("wildoptions", value); },
function() { return get_pref("wildoptions"); },
"",
null
]
]/*}}}*/

View File

@@ -578,7 +578,7 @@ function onCommandBarKeypress(evt)/*{{{*/
{
g_completions = command[COMPLETEFUNC].call(this, args);
// Sort the completion list
if (get_pref('wildsort'))
if (get_pref('wildoptions').match(/\bsort\b/))
{
g_completions.sort(function(a, b) {
if (a[0] < b[0])