mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 14:22:27 +01:00
Turn search keyword completion back on
This commit is contained in:
@@ -709,6 +709,8 @@ function History() //{{{
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
||||||
|
get service() historyService,
|
||||||
|
|
||||||
get: function (filter, maxItems)
|
get: function (filter, maxItems)
|
||||||
{
|
{
|
||||||
let items = [];
|
let items = [];
|
||||||
|
|||||||
@@ -49,14 +49,15 @@ function CompletionContext(editor, name, offset)
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
this.contexts[name] = this;
|
this.contexts[name] = this;
|
||||||
|
this.top = parent.top;
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.editor = parent.editor;
|
this.editor = parent.editor;
|
||||||
this.offset = parent.offset + (offset || 0);
|
this.offset = parent.offset + (offset || 0);
|
||||||
this.__defineGetter__("tabPressed", function () this.parent.tabPressed);
|
this.__defineGetter__("tabPressed", function () this.top.tabPressed);
|
||||||
this.__defineGetter__("onUpdate", function () this.parent.onUpdate);
|
this.__defineGetter__("onUpdate", function () this.top.onUpdate);
|
||||||
this.__defineGetter__("updateAsync", function () this.parent.updateAsync);
|
this.__defineGetter__("updateAsync", function () this.top.updateAsync);
|
||||||
this.__defineGetter__("value", function () this.parent.value);
|
this.__defineGetter__("value", function () this.top.value);
|
||||||
this.__defineGetter__("selectionTypes", function () this.parent.selectionTypes);
|
this.__defineGetter__("selectionTypes", function () this.top.selectionTypes);
|
||||||
this.incomplete = false;
|
this.incomplete = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -65,6 +66,7 @@ function CompletionContext(editor, name, offset)
|
|||||||
this._value = editor;
|
this._value = editor;
|
||||||
else
|
else
|
||||||
this.editor = editor;
|
this.editor = editor;
|
||||||
|
this.top = this;
|
||||||
this.offset = offset || 0;
|
this.offset = offset || 0;
|
||||||
this.tabPressed = false;
|
this.tabPressed = false;
|
||||||
this.onUpdate = function () true;
|
this.onUpdate = function () true;
|
||||||
@@ -116,7 +118,7 @@ CompletionContext.prototype = {
|
|||||||
this.hasItems = items.length > 0;
|
this.hasItems = items.length > 0;
|
||||||
this._items = items;
|
this._items = items;
|
||||||
if (this.updateAsync)
|
if (this.updateAsync)
|
||||||
this.onUpdate.call(this);
|
liberator.callInMainThread(function () { this.onUpdate.call(this) });
|
||||||
},
|
},
|
||||||
|
|
||||||
get title() this._title || ["Completions"], // XXX
|
get title() this._title || ["Completions"], // XXX
|
||||||
@@ -1197,39 +1199,59 @@ function Completion() //{{{
|
|||||||
|
|
||||||
search: function search(context)
|
search: function search(context)
|
||||||
{
|
{
|
||||||
let [, keyword, args] = context.filter.match(/^\s*(\S*)\s*(.*)/);
|
let [, keyword, space, args] = context.filter.match(/^\s*(\S*)(\s*)(.*)$/);
|
||||||
let keywords = bookmarks.getKeywords();
|
let keywords = bookmarks.getKeywords();
|
||||||
let engines = this.filter(keywords.concat(bookmarks.getSearchEngines()), context.filter, false, true);
|
let engines = this.filter(keywords.concat(bookmarks.getSearchEngines()), context.filter, false, true);
|
||||||
|
|
||||||
context.title = ["Search Keywords"];
|
context.title = ["Search Keywords"];
|
||||||
context.items = engines;
|
context.items = engines;
|
||||||
|
|
||||||
// NOTE: While i like the result of the code, due to the History simplification
|
// TODO: Simplify.
|
||||||
// that code is too slow to be here. We might use a direct Places History query instead for better speed
|
for (let [,item] in Iterator(keywords))
|
||||||
// let generate = function () {
|
{
|
||||||
// let hist = history.get();
|
let name = item.keyword;
|
||||||
// let searches = [];
|
if (space && keyword == name && item.url.indexOf("%s") > -1)
|
||||||
// for (let [, k] in Iterator(keywords))
|
context.fork(name, name.length + space.length, function (context) {
|
||||||
// {
|
let [begin, end] = item.url.split("%s");
|
||||||
// if (k.keyword.toLowerCase() != keyword.toLowerCase() || k.url.indexOf("%s") == -1)
|
let history = modules.history.service;
|
||||||
// continue;
|
let query = history.getNewQuery();
|
||||||
// let [begin, end] = k.url.split("%s");
|
let opts = history.getNewQueryOptions();
|
||||||
// for (let [, h] in Iterator(hist))
|
|
||||||
// {
|
query.uri = window.makeURI(begin);
|
||||||
// if (h.url.indexOf(begin) == 0 && (!end.length || h.url.substr(-end.length) == end))
|
query.uriIsPrefix = true;
|
||||||
// {
|
opts.resultType = opts.RESULTS_AS_URI;
|
||||||
// let query = h.url.substring(begin.length, h.url.length - end.length);
|
opts.queryType = opts.QUERY_TYPE_HISTORY;
|
||||||
// searches.push([decodeURIComponent(query.replace("+", "%20")),
|
|
||||||
// <>{begin}<span class="hl-Filter">{query}</span>{end}</>,
|
context.title = [keyword + " Quick Search"];
|
||||||
// k.icon]);
|
function setItems()
|
||||||
// }
|
{
|
||||||
// }
|
context.items = completion.filter(context.cache.items, args, false, true);
|
||||||
// }
|
}
|
||||||
// return searches;
|
|
||||||
// }
|
if (context.cache.items)
|
||||||
// let searches = this.cached("searches-" + keyword, args, generate, "filter", [false, true]);
|
setItems();
|
||||||
// searches = searches.map(function (a) (a = a.concat(), a[0] = keyword + " " + a[0], a));
|
else
|
||||||
// return [0, searches.concat(engines)];
|
{
|
||||||
|
context.incomplete = true;
|
||||||
|
liberator.callFunctionInThread(null, function () {
|
||||||
|
let results = history.executeQuery(query, opts);
|
||||||
|
let root = results.root;
|
||||||
|
root.containerOpen = true;
|
||||||
|
context.cache.items = util.map(util.range(0, root.childCount), function (i) {
|
||||||
|
let child = root.getChild(i);
|
||||||
|
let query = child.uri.substring(begin.length, child.uri.length - end.length);
|
||||||
|
if (end == "" || child.uri.substr(-end.length) == end)
|
||||||
|
return [decodeURIComponent(query.replace("+", "%20")),
|
||||||
|
child.title,
|
||||||
|
child.icon];
|
||||||
|
}).filter(function (k) k);
|
||||||
|
root.containerOpen = false;
|
||||||
|
context.incomplete = false;
|
||||||
|
setItems();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// XXX: Move to bookmarks.js?
|
// XXX: Move to bookmarks.js?
|
||||||
@@ -1367,10 +1389,8 @@ function Completion() //{{{
|
|||||||
return
|
return
|
||||||
context.title = ["Smart Completions"];
|
context.title = ["Smart Completions"];
|
||||||
context.incomplete = true;
|
context.incomplete = true;
|
||||||
if (context.items.length)
|
context.hasItems = context.items.length > 0; // XXX
|
||||||
context.hasItems = true; // XXX
|
let timer = new util.Timer(50, 100, function (result) {
|
||||||
let timer = new util.Timer(50, 100, function () {
|
|
||||||
let result = context.result;
|
|
||||||
context.items = [
|
context.items = [
|
||||||
[result.getValueAt(i), result.getCommentAt(i), result.getImageAt(i)]
|
[result.getValueAt(i), result.getCommentAt(i), result.getImageAt(i)]
|
||||||
for (i in util.range(0, result.matchCount))
|
for (i in util.range(0, result.matchCount))
|
||||||
@@ -1383,7 +1403,7 @@ function Completion() //{{{
|
|||||||
completionService.startSearch(context.filter, "", context.result, {
|
completionService.startSearch(context.filter, "", context.result, {
|
||||||
onSearchResult: function onSearchResult(search, result) {
|
onSearchResult: function onSearchResult(search, result) {
|
||||||
context.result = result;
|
context.result = result;
|
||||||
timer.tell();
|
timer.tell(result);
|
||||||
if (result.searchResult <= result.RESULT_SUCCESS)
|
if (result.searchResult <= result.RESULT_SUCCESS)
|
||||||
timer.flush();
|
timer.flush();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1255,6 +1255,15 @@ const liberator = (function () //{{{
|
|||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
callInMainThread: function (callback)
|
||||||
|
{
|
||||||
|
let mainThread = threadManager.mainThread;
|
||||||
|
if (!threadManager.isMainThread)
|
||||||
|
mainThread.dispatch({ run: callback }, mainThread.DISPATCH_NORMAL);
|
||||||
|
else
|
||||||
|
callback();
|
||||||
|
},
|
||||||
|
|
||||||
threadYield: function (flush)
|
threadYield: function (flush)
|
||||||
{
|
{
|
||||||
let mainThread = threadManager.mainThread;
|
let mainThread = threadManager.mainThread;
|
||||||
|
|||||||
@@ -293,6 +293,8 @@ const config = { //{{{
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
bang: true,
|
bang: true,
|
||||||
|
literal: true,
|
||||||
|
argCount: 0,
|
||||||
completer: function (context) completion.url(context)
|
completer: function (context) completion.url(context)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user