diff --git a/common/content/bookmarks.js b/common/content/bookmarks.js index 8c60020e..d1ffacfb 100644 --- a/common/content/bookmarks.js +++ b/common/content/bookmarks.js @@ -37,7 +37,7 @@ var Bookmarks = Module("bookmarks", { anchored: false, title: ["URL", "Info"], keys: { text: "url", description: "title", icon: "icon", extra: "extra", tags: "tags", isURI: function () true }, - process: [template.icon, template.bookmarkDescription] + process: [template_.icon, template_.bookmarkDescription] }), // TODO: why is this a filter? --djk diff --git a/common/content/history.js b/common/content/history.js index bf2534d1..7ffd0973 100644 --- a/common/content/history.js +++ b/common/content/history.js @@ -316,7 +316,7 @@ var History = Module("history", { .concat(jumps) .concat(sh.slice(sh.index + 1)); - commandline.commandOutput(template.jumps(index, list)); + commandline.commandOutput(template_.jumps(index, list)); }, { argCount: "0" }); diff --git a/common/content/tabs.js b/common/content/tabs.js index a377678e..8089cebc 100644 --- a/common/content/tabs.js +++ b/common/content/tabs.js @@ -1039,11 +1039,12 @@ var Tabs = Module("tabs", { group[1].push([i, tab.linkedBrowser]); }); - context.pushProcessor(0, function (item, text, next) <> - {item.indicator} - { next.call(this, item, text) } - ); - context.process[1] = function (item, text) template.bookmarkDescription(item, template.highlightFilter(text, this.filter)); + context.pushProcessor(0, function (item, text, next) [ + ["span", { highlight: "Indicator", style: "display: inline-block;" }, + item.indicator], + next.call(this, item, text) + ]); + context.process[1] = function (item, text) template_.bookmarkDescription(item, template_.highlightFilter(text, this.filter)); context.anchored = false; context.keys = { diff --git a/common/modules/buffer.jsm b/common/modules/buffer.jsm index 348c4fea..eabb2ed7 100644 --- a/common/modules/buffer.jsm +++ b/common/modules/buffer.jsm @@ -2429,7 +2429,7 @@ Buffer.addPageInfoSection("f", "Feeds", function (verbose) { nFeed++; let type = feedTypes[feed.type] || "RSS"; if (verbose) - yield [feed.title, [template.highlightURL(feed.href, true), + yield [feed.title, [template_.highlightURL(feed.href, true), ["span", { class: "extra-info" }, " (" + type + ")"]]]; } } diff --git a/common/modules/commands.jsm b/common/modules/commands.jsm index 8fd8534f..e8a2dbb5 100644 --- a/common/modules/commands.jsm +++ b/common/modules/commands.jsm @@ -15,7 +15,7 @@ defineModule("commands", { lazyRequire("help", ["help"]); lazyRequire("options", ["Option"]); -lazyRequire("template", ["template"]); +lazyRequire("template", ["template", "template_"]); /** * A structure representing the options available for a command. @@ -1712,7 +1712,7 @@ var Commands = Module("commands", { this.iterate(args).filter(function (cmd) cmd.hive === commands.builtin || Set.has(tags, cmd.helpTag)), format: { headings: ["Command", "Group", "Description"], - description: function (cmd) template.linkifyHelp(cmd.description + (cmd.replacementText ? ": " + cmd.action : "")), + description: function (cmd) template_.linkifyHelp(cmd.description + (cmd.replacementText ? ": " + cmd.action : "")), help: function (cmd) ":" + cmd.name } }); diff --git a/common/modules/completion.jsm b/common/modules/completion.jsm index 9780f289..ccd5ae40 100644 --- a/common/modules/completion.jsm +++ b/common/modules/completion.jsm @@ -321,7 +321,7 @@ var CompletionContext = Class("CompletionContext", { util.trapErrors("onUpdate", this); }, - get createRow() this._createRow || template.completionRow, // XXX + get createRow() this._createRow || template_.completionRow, // XXX set createRow(createRow) this._createRow = createRow, get filterFunc() this._filterFunc || util.identity, @@ -494,7 +494,7 @@ var CompletionContext = Class("CompletionContext", { this.processor = Array.slice(this.process); if (!this.anchored) this.processor[0] = function (item, text) self.process[0].call(self, item, - template.highlightFilter(item.text, self.filter, null, item.isURI)); + template_.highlightFilter(item.text, self.filter, null, item.isURI)); try { // Item prototypes @@ -823,7 +823,7 @@ var CompletionContext = Class("CompletionContext", { throw Error(); this.offset = 0; - this.process = [template.icon, function (item, k) k]; + this.process = [template_.icon, function (item, k) k]; this.filters = [CompletionContext.Filter.text]; this.tabPressed = false; this.title = ["Completions"]; @@ -937,7 +937,7 @@ var Completion = Module("completion", { modules.commandline.commandOutput( ["div", { highlight: "Completions" }, template_.map(contexts, function (context) - [template.completionRow(context.title, "CompTitle"), + [template_.completionRow(context.title, "CompTitle"), template_.map(context.items, function (item) context.createRow(item), null, 100)])]); }, }), @@ -1089,7 +1089,7 @@ var Completion = Module("completion", { contains(item.title, tok))); let re = RegExp(tokens.filter(util.identity).map(util.regexp.escape).join("|"), "g"); - function highlight(item, text, i) process[i].call(this, item, template.highlightRegexp(text, re)); + function highlight(item, text, i) process[i].call(this, item, template_.highlightRegexp(text, re)); let process = context.process; context.process = [ function (item, text) highlight.call(this, item, item.text, 0), @@ -1120,9 +1120,9 @@ var Completion = Module("completion", { function (args) { modules.commandline.commandOutput( ["div", { highlight: "Completions" }, - template.completionRow(["Context", "Title"], "CompTitle"), + template_.completionRow(["Context", "Title"], "CompTitle"), template_.map(completion.contextList || [], - function (item) template.completionRow(item, "CompItem"))]); + function (item) template_.completionRow(item, "CompItem"))]); }, { argCount: "*", diff --git a/common/modules/javascript.jsm b/common/modules/javascript.jsm index bf0d9fe3..10b3cfbe 100644 --- a/common/modules/javascript.jsm +++ b/common/modules/javascript.jsm @@ -353,7 +353,7 @@ var JavaScript = Module("javascript", { if (!compl) { base.process[1] = function highlight(item, v) - template.highlight(typeof v == "xml" ? new String(v.toXMLString()) : v, true, 200); + template_.highlight(typeof v == "xml" ? new String(v.toXMLString()) : v, true, 200); // Sort in a logical fashion for object keys: // Numbers are sorted as numbers, rather than strings, and appear first. diff --git a/common/modules/template.jsm b/common/modules/template.jsm index 3e350167..982327e7 100644 --- a/common/modules/template.jsm +++ b/common/modules/template.jsm @@ -572,6 +572,47 @@ var Template_ = Module("Template_", { }, + bookmarkDescription: function (item, text) [ + !(item.extra && item.extra.length) ? [] : + ["span", { highlight: "URLExtra" }, + " (", + this.map(item.extra, function (e) + ["", e[0], ": ", + ["span", { highlight: e[2] }, e[1]]], + "\u00a0"), + ")\u00a0"], + ["a", { identifier: item.id == null ? "" : item.id, + "dactyl:command": item.command || "", + href: item.item.url, highlight: "URL" }, + text || ""] + ], + + filter: function (str) ["span", { highlight: "Filter" }, str], + + completionRow: function completionRow(item, highlightGroup) { + if (typeof icon == "function") + icon = icon(); + + if (highlightGroup) { + var text = item[0] || ""; + var desc = item[1] || ""; + } + else { + var text = this.processor[0].call(this, item, item.result); + var desc = this.processor[1].call(this, item, item.description); + } + + return ["div", { highlight: highlightGroup || "CompItem", style: "white-space: nowrap" }, + /* The non-breaking spaces prevent empty elements + * from pushing the baseline down and enlarging + * the row. + */ + ["li", { highlight: "CompResult " + item.highlight }, + text, "\u00a0"], + ["li", { highlight: "CompDesc" }, + desc, "\u00a0"]]; + }, + helpLink: function (token, text, type) { if (!help.initialized) util.dactyl.initHelp();