1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-01-06 14:54:11 +01:00

small code beautification for completion, still a lot todo

This commit is contained in:
Martin Stubenschrott
2007-09-30 01:33:25 +00:00
parent f6a7ac8208
commit 2c7839e597
2 changed files with 24 additions and 26 deletions

View File

@@ -1269,7 +1269,10 @@ function Commands() //{{{
// do nothing if the requested sidebar is already open // do nothing if the requested sidebar is already open
if (document.getElementById("sidebar-title").value == args) if (document.getElementById("sidebar-title").value == args)
{
document.getElementById("sidebar-box").contentWindow.focus();
return; return;
}
var menu = document.getElementById("viewSidebarMenu") var menu = document.getElementById("viewSidebarMenu")

View File

@@ -36,8 +36,6 @@ vimperator.completion = (function() // {{{
function build_longest_common_substring(list, filter) //{{{ function build_longest_common_substring(list, filter) //{{{
{ {
var filtered = []; var filtered = [];
//var filter_length = filter.length;
//filter = filter.toLowerCase();
var ignorecase = false; var ignorecase = false;
if (filter == filter.toLowerCase()) if (filter == filter.toLowerCase())
ignorecase = true; ignorecase = true;
@@ -55,7 +53,6 @@ vimperator.completion = (function() // {{{
if (g_substrings.length == 0) if (g_substrings.length == 0)
{ {
//alert('if: ' + item);
var last_index = item.lastIndexOf(filter); var last_index = item.lastIndexOf(filter);
var length = item.length; var length = item.length;
for (var k = item.indexOf(filter); k != -1 && k <= last_index; k = item.indexOf(filter, k + 1)) for (var k = item.indexOf(filter); k != -1 && k <= last_index; k = item.indexOf(filter, k + 1))
@@ -66,7 +63,6 @@ vimperator.completion = (function() // {{{
} }
else else
{ {
//alert('else: ' + item);
g_substrings = g_substrings.filter(function($_) { g_substrings = g_substrings.filter(function($_) {
return list[i][0][j].indexOf($_) >= 0; return list[i][0][j].indexOf($_) >= 0;
}); });
@@ -78,17 +74,17 @@ vimperator.completion = (function() // {{{
return filtered; return filtered;
} //}}} } //}}}
/* this function is case sensitive */ /* this function is case sensitive and should be documented about input and output ;) */
function build_longest_starting_substring(list, filter) //{{{ function build_longest_starting_substring(list, filter) //{{{
{ {
var filtered = []; var filtered = [];
//var filter_length = filter.length;
for (var i = 0; i < list.length; i++) for (var i = 0; i < list.length; i++)
{ {
for (var j = 0; j < list[i][0].length; j++) for (var j = 0; j < list[i][0].length; j++)
{ {
if (list[i][0][j].indexOf(filter) != 0) if (list[i][0][j].indexOf(filter) != 0)
continue; continue;
if (g_substrings.length == 0) if (g_substrings.length == 0)
{ {
var length = list[i][0][j].length; var length = list[i][0][j].length;
@@ -120,7 +116,6 @@ vimperator.completion = (function() // {{{
return [$_[0], $_[1]] return [$_[0], $_[1]]
}); });
//var filter_length = filter.length;
var ignorecase = false; var ignorecase = false;
if (filter == filter.toLowerCase()) if (filter == filter.toLowerCase())
ignorecase = true; ignorecase = true;
@@ -169,23 +164,21 @@ vimperator.completion = (function() // {{{
} //}}} } //}}}
return { return {
/* /*
* returns the longest common substring * returns the longest common substring
* used for the 'longest' setting for wildmode * used for the 'longest' setting for wildmode
*
*/ */
get_longest_substring: function() //{{{ get_longest_substring: function() //{{{
{ {
if (g_substrings.length == 0) if (g_substrings.length == 0)
return ''; return '';
var longest = g_substrings[0]; var longest = g_substrings[0];
for (var i = 1; i < g_substrings.length; i++) for (var i = 1; i < g_substrings.length; i++)
{ {
if (g_substrings[i].length > longest.length) if (g_substrings[i].length > longest.length)
longest = g_substrings[i]; longest = g_substrings[i];
} }
//alert(longest);
return longest; return longest;
}, //}}} }, //}}}
@@ -222,11 +215,11 @@ vimperator.completion = (function() // {{{
{ {
var engines = vimperator.bookmarks.getSearchEngines().concat(vimperator.bookmarks.getKeywords()); var engines = vimperator.bookmarks.getSearchEngines().concat(vimperator.bookmarks.getKeywords());
if (!filter) return engines.map(function($_) { if (!filter) return engines.map(function(engine) {
return [$_[0], $_[1]]; return [engine[0], engine[1]];
}); });
var mapped = engines.map(function($_) { var mapped = engines.map(function($_) {
return [[$_[0]], $_[1]]; return [[engine[0]], engine[1]];
}); });
return build_longest_common_substring(mapped, filter); return build_longest_common_substring(mapped, filter);
}, //}}} }, //}}}
@@ -279,20 +272,21 @@ vimperator.completion = (function() // {{{
var entries = fd.read(); var entries = fd.read();
var separator = fd.path.length == 1 ? "" : /\\/.test(fd.path) ? "\\" : "/"; var separator = fd.path.length == 1 ? "" : /\\/.test(fd.path) ? "\\" : "/";
var new_filter = fd.path + separator + compl; var new_filter = fd.path + separator + compl;
if (!filter) return entries.map(function($_) { if (!filter) return entries.map(function(file) {
var path = $_.path; var path = file.path;
if ($_.isDirectory()) path += separator; if (file.isDirectory())
path += separator;
return [path, ""]; return [path, ""];
}); });
var mapped = entries.map(function($_) { var mapped = entries.map(function(file) {
var path = $_.path; var path = file.path;
if ($_.isDirectory()) path += separator; if (file.isDirectory())
path += separator;
return [[path], ""]; return [[path], ""];
}); });
} }
catch (e) catch (e)
{ {
//vimperator.log(e);
return []; return [];
} }
@@ -333,7 +327,6 @@ vimperator.completion = (function() // {{{
get_command_completions: function(filter) //{{{ get_command_completions: function(filter) //{{{
{ {
//g_completions = [];
g_substrings = []; g_substrings = [];
var completions = [] var completions = []
if (!filter) if (!filter)
@@ -401,10 +394,12 @@ vimperator.completion = (function() // {{{
{ {
if (prefix && option.type != "boolean") if (prefix && option.type != "boolean")
continue; continue;
for (var j = 0; j < option.names.length; j++) for (var j = 0; j < option.names.length; j++)
{ {
if (option.names[j].indexOf(filter) != 0) if (option.names[j].indexOf(filter) != 0)
continue; continue;
if (g_substrings.length == 0) if (g_substrings.length == 0)
{ {
var length = option.names[j].length; var length = option.names[j].length;
@@ -463,6 +458,7 @@ vimperator.completion = (function() // {{{
get_sidebar_completions: function(filter) //{{{ get_sidebar_completions: function(filter) //{{{
{ {
g_substrings = [];
var menu = document.getElementById("viewSidebarMenu") var menu = document.getElementById("viewSidebarMenu")
var nodes = []; var nodes = [];
@@ -472,8 +468,8 @@ vimperator.completion = (function() // {{{
if (!filter) if (!filter)
return nodes; return nodes;
var mapped = nodes.map(function($_) { var mapped = nodes.map(function(node) {
return [[$_[0]], $_[1]]; return [[node[0]], node[1]];
}); });
return build_longest_common_substring(mapped, filter); return build_longest_common_substring(mapped, filter);
@@ -492,7 +488,6 @@ vimperator.completion = (function() // {{{
outer: outer:
for (; start >= 0; start--) for (; start >= 0; start--)
{ {
dump(matches[1].substr(start) + ": " + start + "\n");
switch (matches[1][start]) switch (matches[1][start])
{ {
case ";": case ";":
@@ -550,7 +545,7 @@ vimperator.completion = (function() // {{{
exTabCompletion: function(str) //{{{ exTabCompletion: function(str) //{{{
{ {
var [count, cmd, special, args] = vimperator.commands.parseCommand(str); var [count, cmd, special, args] = vimperator.commands.parseCommand(str);
var completions = new Array; var completions = [];
var start = 0; var start = 0;
// if there is no space between the command name and the cursor // if there is no space between the command name and the cursor
@@ -581,7 +576,7 @@ vimperator.completion = (function() // {{{
} }
else if (command.hasName("echo") || command.hasName("echoerr") || command.hasName("javascript")) else if (command.hasName("echo") || command.hasName("echoerr") || command.hasName("javascript"))
{ {
var skip = args.match(/^(.*?)(\w*)$/); // start after the last ", " var skip = args.match(/^(.*?)(\w*)$/); // start at beginning of the last word
if (skip) if (skip)
start += skip[1].length; start += skip[1].length;
} }