1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-20 06:07:59 +01:00

Add :history -sort.

This commit is contained in:
Kris Maglione
2010-12-22 22:15:24 -05:00
parent 69581c1428
commit 2b016d2e6a
4 changed files with 56 additions and 13 deletions

View File

@@ -902,7 +902,6 @@ const Events = Module("events", {
input.postExecute = mode.params.postExecute; input.postExecute = mode.params.postExecute;
if (mode.params.onEvent) if (mode.params.onEvent)
input.fallthrough = function (event) { input.fallthrough = function (event) {
util.dump("fallthrough", String(mode), events.toString(event));
// Bloody hell. // Bloody hell.
if (events.toString(event) === "<C-h>") if (events.toString(event) === "<C-h>")
event.dactylString = "<BS>"; event.dactylString = "<BS>";

View File

@@ -11,7 +11,7 @@ const History = Module("history", {
get service() services.history, get service() services.history,
get: function get(filter, maxItems) { get: function get(filter, maxItems, order) {
// no query parameters will get all history // no query parameters will get all history
let query = services.history.getNewQuery(); let query = services.history.getNewQuery();
let options = services.history.getNewQueryOptions(); let options = services.history.getNewQueryOptions();
@@ -20,7 +20,15 @@ const History = Module("history", {
filter = { searchTerms: filter }; filter = { searchTerms: filter };
for (let [k, v] in Iterator(filter)) for (let [k, v] in Iterator(filter))
query[k] = v; query[k] = v;
options.sortingMode = options.SORT_BY_DATE_DESCENDING;
order = order || "+date";
dactyl.assert((order = /^([+-])(.+)/.exec(order)) &&
(order = "SORT_BY_" + order[2].toUpperCase() + "_" +
(order[1] == "+" ? "ASCENDING" : "DESCENDING")) &&
order in options,
"Invalid sort order");
options.sortingMode = options[order];
options.resultType = options.RESULTS_AS_URI; options.resultType = options.RESULTS_AS_URI;
if (maxItems > 0) if (maxItems > 0)
options.maxResults = maxItems; options.maxResults = maxItems;
@@ -93,13 +101,13 @@ const History = Module("history", {
}, },
// if openItems is true, open the matching history items in tabs rather than display // if openItems is true, open the matching history items in tabs rather than display
list: function list(filter, openItems, maxItems) { list: function list(filter, openItems, maxItems, sort) {
// FIXME: returning here doesn't make sense // FIXME: returning here doesn't make sense
// Why the hell doesn't it make sense? --Kris // Why the hell doesn't it make sense? --Kris
// See comment at bookmarks.list --djk // See comment at bookmarks.list --djk
if (!openItems) if (!openItems)
return completion.listCompleter("history", filter, maxItems); return completion.listCompleter("history", filter, maxItems, maxItems, sort);
let items = completion.runCompleter("history", filter, maxItems); let items = completion.runCompleter("history", filter, maxItems, maxItems, sort);
if (items.length) if (items.length)
return dactyl.open(items.map(function (i) i.url), dactyl.NEW_TAB); return dactyl.open(items.map(function (i) i.url), dactyl.NEW_TAB);
@@ -195,11 +203,39 @@ const History = Module("history", {
commands.add(["hist[ory]", "hs"], commands.add(["hist[ory]", "hs"],
"Show recently visited URLs", "Show recently visited URLs",
function (args) { history.list(args.join(" "), args.bang, args["-max"]); }, { function (args) { history.list(args.join(" "), args.bang, args["-max"], args["-sort"]); }, {
bang: true, bang: true,
completer: function (context) { context.quote = null; completion.history(context); }, completer: function (context) completion.history(context, args["-max"], args["-sort"]),
// completer: function (filter) completion.history(filter) options: [
options: [{ names: ["-max", "-m"], description: "The maximum number of items to list", default: 1000, type: CommandOption.INT }], {
names: ["-max", "-m"],
description: "The maximum number of items to list",
default: 1000,
type: CommandOption.INT
},
{
names: ["-sort", "-s"],
type: CommandOption.STRING,
description: "The sort order of the results",
completer: function (context, args) {
context.compare = CompletionContext.Sort.unsorted;
return array.flatten([
"annotation",
"date",
"date added",
"keyword",
"last modified",
"tags",
"title",
"uri",
"visitcount"
].map(function (order) [
["+" + order.replace(" ", ""), "Sort by " + order + " ascending"],
["-" + order.replace(" ", ""), "Sort by " + order + " descending"],
]))
}
}
],
privateData: true privateData: true
}); });
}, },
@@ -218,15 +254,17 @@ const History = Module("history", {
].slice(2); ].slice(2);
}; };
completion.history = function _history(context, maxItems) { completion.history = function _history(context, maxItems, sort) {
context.format = history.format; context.format = history.format;
context.title = ["History"]; context.title = ["History"];
context.compare = CompletionContext.Sort.unsorted; context.compare = CompletionContext.Sort.unsorted;
//context.background = true; //context.background = true;
if (context.maxItems == null) if (maxItems == null)
context.maxItems = maxItems;
if (maxItems && context.maxItems == null)
context.maxItems = 100; context.maxItems = 100;
context.regenerate = true; context.regenerate = true;
context.generate = function () history.get(context.filter, this.maxItems); context.generate = function () history.get(context.filter, this.maxItems, sort);
}; };
completion.addUrlCompleter("h", "History", completion.history); completion.addUrlCompleter("h", "History", completion.history);

View File

@@ -280,6 +280,11 @@
The maximum number of items to list or open The maximum number of items to list or open
(short name <em>-m</em>). (short name <em>-m</em>).
</dd> </dd>
<dt>-sort</dt>
<dd>
The sort order of the results
(short name <em>-s</em>).
</dd>
</dl> </dl>
</description> </description>
</item> </item>

View File

@@ -61,6 +61,7 @@
- Added -keyword, -tags, -title to :delbmarks. - Added -keyword, -tags, -title to :delbmarks.
- Added :extupdate command. - Added :extupdate command.
- Added :feedkeys command. - Added :feedkeys command.
- Added -sort option to :history
- Added several new options, including -javascript, to :abbrev and :map. - Added several new options, including -javascript, to :abbrev and :map.
- Added :mksyntax command. - Added :mksyntax command.
- :open now only opens files beginning with /, ./, ../, or ~/ - :open now only opens files beginning with /, ./, ../, or ~/