mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-02-15 06:15:48 +01:00
more work towards a working :Help
This commit is contained in:
@@ -1033,10 +1033,10 @@ vimperator.Commands = function () //{{{
|
||||
}
|
||||
));
|
||||
commandManager.add(new vimperator.Command(["H[elp]"],
|
||||
function (args, special, count, modifiers) { vimperator.open("chrome://vimperator/locale/" + (args || "introduction") + ".html"); },
|
||||
function (args, special, count, modifiers) { vimperator.Help((args || "introduction")); },
|
||||
{
|
||||
shortHelp: "Temporary function, will replace :help at some time",
|
||||
completer: function (filter) { return [["introduction", ""], ["options", ""]]; }
|
||||
completer: function (filter) { return vimperator.completion.Help(filter); }
|
||||
}
|
||||
));
|
||||
commandManager.add(new vimperator.Command(["hist[ory]", "hs"],
|
||||
|
||||
@@ -296,6 +296,39 @@ vimperator.Completion = function () //{{{
|
||||
return [0, buildLongestCommonSubstring(helpArray, filter)];
|
||||
},
|
||||
|
||||
// TODO: add cache?
|
||||
Help: function (filter)
|
||||
{
|
||||
var res = [];
|
||||
var files = ["introduction.xhtml", "options.xhtml"];
|
||||
for (var file in files)
|
||||
{
|
||||
try
|
||||
{
|
||||
var xmlhttp = new XMLHttpRequest();
|
||||
xmlhttp.open("GET", "chrome://vimperator/locale/" + files[file], false);
|
||||
xmlhttp.send(null);
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
vimperator.log("Error opening chrome://vimperator/locale/" + files[file], 1);
|
||||
continue;
|
||||
}
|
||||
var doc = xmlhttp.responseXML;
|
||||
var elems = doc.getElementsByClassName("tag");
|
||||
for (var i = 0; i < elems.length; i++)
|
||||
res.push([elems[i].textContent, files[file]]);
|
||||
}
|
||||
|
||||
if (!filter)
|
||||
return [0, res];
|
||||
|
||||
var mapped = res.map(function (node) {
|
||||
return [[node[0]], node[1]];
|
||||
});
|
||||
return [0, buildLongestCommonSubstring(mapped, filter)];
|
||||
},
|
||||
|
||||
command: function (filter)
|
||||
{
|
||||
substrings = [];
|
||||
|
||||
@@ -293,4 +293,39 @@ vimperator.help = function (section, easter) //{{{
|
||||
}, 0);
|
||||
}; //}}}
|
||||
|
||||
|
||||
// New style help
|
||||
vimperator.Help = function(section)
|
||||
{
|
||||
function jumpToTag(file, tag)
|
||||
{
|
||||
vimperator.open("chrome://vimperator/locale/" + file);
|
||||
setTimeout(function() {
|
||||
var elem = vimperator.buffer.element('@class="tag" and text()="' + tag + '"');
|
||||
if (elem)
|
||||
window.content.scrollTo(0, elem.getBoundingClientRect().top - 10); // 10px context
|
||||
}, 100);
|
||||
}
|
||||
|
||||
var [, items] = vimperator.completion.Help();
|
||||
var partialMatch = -1;
|
||||
for (var i = 0; i < items.length; i++)
|
||||
{
|
||||
if (items[i][0] == section)
|
||||
{
|
||||
jumpToTag(items[i][1], items[i][0]);
|
||||
return;
|
||||
}
|
||||
else if (partialMatch == -1 && items[i][0].indexOf(section) > -1)
|
||||
{
|
||||
partialMatch = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (partialMatch > -1)
|
||||
jumpToTag(items[partialMatch][1], items[partialMatch][0]);
|
||||
else
|
||||
vimperator.echoerr("E149: Sorry, no help for " + section);
|
||||
};
|
||||
|
||||
// vim: set fdm=marker sw=4 ts=4 et:
|
||||
|
||||
Reference in New Issue
Block a user