1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-22 04:27:58 +01:00

add filename completion for Windows

This commit is contained in:
Doug Kearns
2007-08-26 11:57:32 +00:00
parent 6547499323
commit 581980a2b0

View File

@@ -243,46 +243,58 @@ vimperator.completion = (function() // {{{
return filter_url_array(bookmarks, filter); return filter_url_array(bookmarks, filter);
}, //}}} }, //}}}
// TODO: support file:// and \ or / path separators on both platforms
get_file_completions: function(filter) //{{{ get_file_completions: function(filter) //{{{
{ {
//var completions = []; //var completions = [];
/* This is now also used as part of the url completion, so the substrings shouldn't be cleared for that case */
// this is now also used as part of the url completion, so the
// substrings shouldn't be cleared for that case
if (!arguments[1]) if (!arguments[1])
g_substrings = []; g_substrings = [];
var match = filter.match(/^(.*[\/\\])(.*?)$/); var matches = filter.match(/^(.*[\/\\])(.*?)$/);
var dir; var dir;
if (!match || !(dir = match[1])) if (!matches || !(dir = matches[1]))
return []; return [];
var compl = match[2] || ''; var compl = matches[2] || "";
try try
{ {
var fd = vimperator.fopen(dir, "<"); var fd = vimperator.fopen(dir);
} }
catch(e) catch (e)
{ {
// thrown if file does not exist // thrown if file does not exist
return [ ]; return [];
} }
if (!fd) if (!fd)
return []; return [];
var entries = fd.read(); try
var delim = fd.path.length == 1 ? '' : (fd.path.search(/\\/) != -1) ? "\\" : "/"; {
var new_filter = fd.path + delim + compl; var entries = fd.read();
if (!filter) return entries.map(function($_) { var separator = fd.path.length == 1 ? "" : /\\/.test(fd.path) ? "\\" : "/";
var path = $_.path; var new_filter = fd.path + separator + compl;
if ($_.isDirectory()) path += '/'; if (!filter) return entries.map(function($_) {
return [path, '']; var path = $_.path;
}); if ($_.isDirectory()) path += separator;
var mapped = entries.map(function($_) { return [path, ""];
var path = $_.path; });
if ($_.isDirectory()) path += '/'; var mapped = entries.map(function($_) {
return [[path], '']; var path = $_.path;
}); if ($_.isDirectory()) path += separator;
return [[path], ""];
});
}
catch (e)
{
//vimperator.log(e);
return [];
}
return build_longest_starting_substring(mapped, new_filter); return build_longest_starting_substring(mapped, new_filter);
}, //}}} }, //}}}