mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-01-02 21:24:10 +01:00
Changed 'complete' option default to "sfl", meaning we have awesomebar completions by default now.
In constrast removed history cache, which should make startup faster and use less memory. As we only need it for :history anyway, there is no real performance penalty as Places does search quite fast.
This commit is contained in:
@@ -550,47 +550,6 @@ function History() //{{{
|
||||
const historyService = Components.classes["@mozilla.org/browser/nav-history-service;1"]
|
||||
.getService(Components.interfaces.nsINavHistoryService);
|
||||
|
||||
// const History = new Struct("url", "title", "icon");
|
||||
// History.defaultValue("title", function () "[No Title]");
|
||||
// History.defaultValue("icon", function () bookmarks.getFavicon(this.url));
|
||||
|
||||
var placesHistory;
|
||||
var cachedHistory = []; // add pages here after loading the initial Places history
|
||||
|
||||
function load()
|
||||
{
|
||||
placesHistory = [];
|
||||
|
||||
// no query parameters will get all history
|
||||
// XXX default sorting is... ?
|
||||
var options = historyService.getNewQueryOptions();
|
||||
var query = historyService.getNewQuery();
|
||||
|
||||
// execute the query
|
||||
var result = historyService.executeQuery(query, options);
|
||||
var rootNode = result.root;
|
||||
rootNode.containerOpen = true;
|
||||
// iterate over the immediate children of this folder
|
||||
for (let i = 0; i < rootNode.childCount; i++)
|
||||
{
|
||||
var node = rootNode.getChild(i);
|
||||
// liberator.dump("History child " + node.itemId + ": " + node.title + " - " + node.type);
|
||||
if (node.type == node.RESULT_TYPE_URI) // just make sure it's a bookmark
|
||||
placesHistory.push({ url: node.uri, title: node.title, get icon() function() bookmarks.getFavicon(this.url) });
|
||||
}
|
||||
|
||||
// close a container after using it!
|
||||
rootNode.containerOpen = false;
|
||||
}
|
||||
|
||||
liberator.registerObserver("enter", function () {
|
||||
if (options["preload"])
|
||||
{
|
||||
// Forces a load, if not already loaded but wait 15sec
|
||||
// so that we don't load it at the same time as bookmarks
|
||||
setTimeout(function() { liberator.callFunctionInThread(null, load); }, 15000);
|
||||
}
|
||||
});
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////}}}
|
||||
////////////////////// MAPPINGS ////////////////////////////////////////////////
|
||||
@@ -736,77 +695,57 @@ function History() //{{{
|
||||
|
||||
return {
|
||||
|
||||
load: function() { load(); }, // temporary only, for performance testing
|
||||
get: function (filter)
|
||||
get: function (filter, maxItems)
|
||||
{
|
||||
if (!placesHistory)
|
||||
load();
|
||||
let items = [];
|
||||
|
||||
if (!filter)
|
||||
return cachedHistory.concat(placesHistory);
|
||||
return completion.cached("history", filter, function () cachedHistory.concat(placesHistory),
|
||||
"filterURLArray");
|
||||
},
|
||||
// no query parameters will get all history
|
||||
let query = historyService.getNewQuery();
|
||||
query.searchTerms = filter;
|
||||
|
||||
// the history is automatically added to the Places global history
|
||||
// so just update our cached history here
|
||||
add: function (url, title)
|
||||
{
|
||||
let filter = function (h) h[0] != url;
|
||||
let options = historyService.getNewQueryOptions();
|
||||
options.sortingMode = options.SORT_BY_DATE_DESCENDING;
|
||||
if (maxItems > 0)
|
||||
options.maxResults = maxItems;
|
||||
|
||||
// don't let cachedHistory grow too large
|
||||
if (placesHistory && cachedHistory.length > 1000)
|
||||
// execute the query
|
||||
let root = historyService.executeQuery(query, options).root;
|
||||
root.containerOpen = true;
|
||||
for (let i = 0; i < root.childCount; i++)
|
||||
{
|
||||
placesHistory = cachedHistory.concat(placesHistory);
|
||||
placesHistory = placesHistory.filter(filter);
|
||||
cachedHistory = [];
|
||||
let node = root.getChild(i);
|
||||
if (node.type == node.RESULT_TYPE_URI) // just make sure it's a bookmark
|
||||
items.push({ url: node.uri, title: node.title, get icon() function() bookmarks.getFavicon(node.uri) });
|
||||
}
|
||||
else
|
||||
cachedHistory = cachedHistory.filter(filter);
|
||||
root.containerOpen = false; // close a container after using it!
|
||||
|
||||
cachedHistory.unshift({ url: url, title: title, get icon() function() bookmarks.getFavicon(this.url) });
|
||||
return true;
|
||||
return items;
|
||||
},
|
||||
|
||||
// TODO: better names?
|
||||
// and move to buffer.?
|
||||
// TODO: better names and move to buffer.?
|
||||
stepTo: function (steps)
|
||||
{
|
||||
var index = getWebNavigation().sessionHistory.index + steps;
|
||||
|
||||
let index = getWebNavigation().sessionHistory.index + steps;
|
||||
if (index >= 0 && index < getWebNavigation().sessionHistory.count)
|
||||
{
|
||||
getWebNavigation().gotoIndex(index);
|
||||
}
|
||||
else
|
||||
{
|
||||
liberator.beep();
|
||||
}
|
||||
},
|
||||
|
||||
goToStart: function ()
|
||||
{
|
||||
var index = getWebNavigation().sessionHistory.index;
|
||||
|
||||
let index = getWebNavigation().sessionHistory.index;
|
||||
if (index == 0)
|
||||
{
|
||||
liberator.beep();
|
||||
return;
|
||||
}
|
||||
return liberator.beep(); // really wanted?
|
||||
|
||||
getWebNavigation().gotoIndex(0);
|
||||
},
|
||||
|
||||
goToEnd: function ()
|
||||
{
|
||||
var index = getWebNavigation().sessionHistory.index;
|
||||
var max = getWebNavigation().sessionHistory.count - 1;
|
||||
|
||||
if (index == max)
|
||||
{
|
||||
liberator.beep();
|
||||
return;
|
||||
}
|
||||
let index = getWebNavigation().sessionHistory.index;
|
||||
if (index == getWebNavigation().sessionHistory.count - 1)
|
||||
return liberator.beep();
|
||||
|
||||
getWebNavigation().gotoIndex(max);
|
||||
},
|
||||
@@ -814,7 +753,7 @@ function History() //{{{
|
||||
// if openItems is true, open the matching history items in tabs rather than display
|
||||
list: function (filter, openItems)
|
||||
{
|
||||
var items = this.get(filter);
|
||||
var items = this.get(filter, 1000);
|
||||
if (items.length == 0)
|
||||
{
|
||||
if (filter.length > 0)
|
||||
@@ -828,7 +767,6 @@ function History() //{{{
|
||||
if (openItems)
|
||||
return liberator.open([i[0] for each (i in items)], liberator.NEW_TAB);
|
||||
|
||||
// TODO: is there a faster way to limit to max. 1000 items?
|
||||
let list = template.bookmarks("title", items);
|
||||
commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE);
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ function Completion() //{{{
|
||||
let orig = obj;
|
||||
if (obj.wrappedJSObject)
|
||||
obj = obj.wrappedJSObject;
|
||||
compl.push([v for (v in this.iter(obj)) if (v[0] in orig || orig[v[0]])])
|
||||
compl.push([v for (v in this.iter(obj)) if (v[0] in orig)])
|
||||
// And if wrappedJSObject happens to be available,
|
||||
// return that, too.
|
||||
if (orig.wrappedJSObject)
|
||||
@@ -1063,30 +1063,33 @@ function Completion() //{{{
|
||||
let keywords = bookmarks.getKeywords();
|
||||
let engines = this.filter(keywords.concat(bookmarks.getSearchEngines()), filter, false, true);
|
||||
|
||||
let generate = function () {
|
||||
let hist = history.get();
|
||||
let searches = [];
|
||||
for (let [, k] in Iterator(keywords))
|
||||
{
|
||||
if (k.keyword.toLowerCase() != keyword.toLowerCase() || k.url.indexOf("%s") == -1)
|
||||
continue;
|
||||
let [begin, end] = k.url.split("%s");
|
||||
for (let [, h] in Iterator(hist))
|
||||
{
|
||||
if (h.url.indexOf(begin) == 0 && (!end.length || h.url.substr(-end.length) == end))
|
||||
{
|
||||
let query = h.url.substring(begin.length, h.url.length - end.length);
|
||||
searches.push([decodeURIComponent(query.replace("+", "%20")),
|
||||
<>{begin}<span class="hl-Filter">{query}</span>{end}</>,
|
||||
k.icon]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return searches;
|
||||
}
|
||||
let searches = this.cached("searches-" + keyword, args, generate, "filter", [false, true]);
|
||||
searches = searches.map(function (a) (a = a.concat(), a[0] = keyword + " " + a[0], a));
|
||||
return [0, searches.concat(engines)];
|
||||
// NOTE: While i like the result of the code, due to the History simplification
|
||||
// that code is too slow to be here. We might use a direct Places History query instead for better speed
|
||||
// let generate = function () {
|
||||
// let hist = history.get();
|
||||
// let searches = [];
|
||||
// for (let [, k] in Iterator(keywords))
|
||||
// {
|
||||
// if (k.keyword.toLowerCase() != keyword.toLowerCase() || k.url.indexOf("%s") == -1)
|
||||
// continue;
|
||||
// let [begin, end] = k.url.split("%s");
|
||||
// for (let [, h] in Iterator(hist))
|
||||
// {
|
||||
// if (h.url.indexOf(begin) == 0 && (!end.length || h.url.substr(-end.length) == end))
|
||||
// {
|
||||
// let query = h.url.substring(begin.length, h.url.length - end.length);
|
||||
// searches.push([decodeURIComponent(query.replace("+", "%20")),
|
||||
// <>{begin}<span class="hl-Filter">{query}</span>{end}</>,
|
||||
// k.icon]);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return searches;
|
||||
// }
|
||||
// let searches = this.cached("searches-" + keyword, args, generate, "filter", [false, true]);
|
||||
// searches = searches.map(function (a) (a = a.concat(), a[0] = keyword + " " + a[0], a));
|
||||
// return [0, searches.concat(engines)];
|
||||
return [0, engines];
|
||||
},
|
||||
|
||||
// XXX: Move to bookmarks.js?
|
||||
@@ -1260,8 +1263,6 @@ function Completion() //{{{
|
||||
completions = completions.concat(this.searchEngineSuggest(filter, suggestEngineAlias)[1]);
|
||||
else if (c == "b")
|
||||
completions = completions.concat(bookmarks.get(filter));
|
||||
else if (c == "h")
|
||||
completions = completions.concat(history.get(filter));
|
||||
else if (c == "l" && completionService) // add completions like Firefox's smart location bar
|
||||
{
|
||||
historyCache = [];
|
||||
|
||||
@@ -517,10 +517,6 @@ function Events() //{{{
|
||||
let url = doc.location.href;
|
||||
let title = doc.title;
|
||||
|
||||
// update history
|
||||
if (url && liberator.has("history"))
|
||||
history.add(url, title);
|
||||
|
||||
// mark the buffer as loaded, we can't use buffer.loaded
|
||||
// since that always refers to the current buffer, while doc can be
|
||||
// any buffer, even in a background tab
|
||||
|
||||
Reference in New Issue
Block a user