diff --git a/content/commands.js b/content/commands.js index 81067006..c6fb2843 100644 --- a/content/commands.js +++ b/content/commands.js @@ -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"], diff --git a/content/completion.js b/content/completion.js index 045eadb5..988b1c4f 100644 --- a/content/completion.js +++ b/content/completion.js @@ -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 = []; diff --git a/content/help.js b/content/help.js index 19cc7f9e..c546aa53 100644 --- a/content/help.js +++ b/content/help.js @@ -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: diff --git a/locale/en-US/initialization.html b/locale/en-US/initialization.xhtml similarity index 86% rename from locale/en-US/initialization.html rename to locale/en-US/initialization.xhtml index c06f74c1..702dde77 100644 --- a/locale/en-US/initialization.html +++ b/locale/en-US/initialization.xhtml @@ -1,3 +1,5 @@ + + Vimperator Help: Introduction @@ -22,3 +24,4 @@ determined as follows: