mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-22 12:57:58 +01:00
Default to anchored completion matching.
This commit is contained in:
@@ -95,6 +95,7 @@ function CompletionContext(editor, name, offset)
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}];
|
}];
|
||||||
|
this.anchored = true;
|
||||||
this.contexts = { name: this };
|
this.contexts = { name: this };
|
||||||
this.keys = { text: 0, description: 1, icon: "icon" };
|
this.keys = { text: 0, description: 1, icon: "icon" };
|
||||||
this.offset = offset || 0;
|
this.offset = offset || 0;
|
||||||
@@ -197,12 +198,14 @@ CompletionContext.prototype = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
get format() ({
|
get format() ({
|
||||||
|
anchored: this.anchored,
|
||||||
title: this.title,
|
title: this.title,
|
||||||
keys: this.keys,
|
keys: this.keys,
|
||||||
process: this.process
|
process: this.process
|
||||||
}),
|
}),
|
||||||
set format(format)
|
set format(format)
|
||||||
{
|
{
|
||||||
|
this.anchored = format.anchored,
|
||||||
this.title = format.title || this.title;
|
this.title = format.title || this.title;
|
||||||
this.keys = format.keys || this.keys;
|
this.keys = format.keys || this.keys;
|
||||||
this.process = format.process || this.process;
|
this.process = format.process || this.process;
|
||||||
@@ -478,14 +481,16 @@ CompletionContext.prototype = {
|
|||||||
// Not ideal.
|
// Not ideal.
|
||||||
for (let type in this.selectionTypes)
|
for (let type in this.selectionTypes)
|
||||||
this.highlight(0, 0, type);
|
this.highlight(0, 0, type);
|
||||||
|
|
||||||
this.contextList = [];
|
this.contextList = [];
|
||||||
this.offset = 0;
|
this.offset = 0;
|
||||||
this.process = [];
|
this.process = [];
|
||||||
this.selectionTypes = {};
|
this.selectionTypes = {};
|
||||||
this.tabPressed = false;
|
this.tabPressed = false;
|
||||||
this.title = ["Completions"];
|
this.title = ["Completions"];
|
||||||
this.waitingForTab = false;
|
|
||||||
this.updateAsync = false;
|
this.updateAsync = false;
|
||||||
|
this.waitingForTab = false;
|
||||||
|
|
||||||
if (this.editor)
|
if (this.editor)
|
||||||
{
|
{
|
||||||
this.value = this.editor.selection.focusNode.textContent;
|
this.value = this.editor.selection.focusNode.textContent;
|
||||||
@@ -1128,30 +1133,6 @@ function Completion() //{{{
|
|||||||
.items.map(function (i) i.item);
|
.items.map(function (i) i.item);
|
||||||
},
|
},
|
||||||
|
|
||||||
// cancel any ongoing search
|
|
||||||
cancel: function cancel()
|
|
||||||
{
|
|
||||||
if (completionService)
|
|
||||||
completionService.stopSearch();
|
|
||||||
},
|
|
||||||
|
|
||||||
// generic helper function which checks if the given "items" array pass "filter"
|
|
||||||
// items must be an array of strings
|
|
||||||
match: function match(items, filter, caseSensitive)
|
|
||||||
{
|
|
||||||
if (typeof filter != "string" || !items)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
var itemsStr = items.join(" ");
|
|
||||||
if (!caseSensitive)
|
|
||||||
{
|
|
||||||
filter = filter.toLowerCase();
|
|
||||||
itemsStr = itemsStr.toLowerCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
return filter.split(/\s+/).every(function strIndex(str) itemsStr.indexOf(str) > -1);
|
|
||||||
},
|
|
||||||
|
|
||||||
listCompleter: function listCompleter(name, filter, maxItems)
|
listCompleter: function listCompleter(name, filter, maxItems)
|
||||||
{
|
{
|
||||||
let context = CompletionContext(filter || "");
|
let context = CompletionContext(filter || "");
|
||||||
@@ -1241,7 +1222,6 @@ function Completion() //{{{
|
|||||||
command: function command(context)
|
command: function command(context)
|
||||||
{
|
{
|
||||||
context.title = ["Command"];
|
context.title = ["Command"];
|
||||||
context.anchored = true;
|
|
||||||
context.keys = { text: "longNames", description: "description" };
|
context.keys = { text: "longNames", description: "description" };
|
||||||
context.completions = [k for (k in commands)];
|
context.completions = [k for (k in commands)];
|
||||||
},
|
},
|
||||||
@@ -1325,7 +1305,6 @@ function Completion() //{{{
|
|||||||
if (tail)
|
if (tail)
|
||||||
context.advance(dir.length);
|
context.advance(dir.length);
|
||||||
context.keys = { text: 0, description: 1, icon: 2 };
|
context.keys = { text: 0, description: 1, icon: 2 };
|
||||||
context.anchored = true;
|
|
||||||
context.background = true;
|
context.background = true;
|
||||||
context.key = dir;
|
context.key = dir;
|
||||||
context.generate = function generate_file()
|
context.generate = function generate_file()
|
||||||
@@ -1391,6 +1370,7 @@ function Completion() //{{{
|
|||||||
{
|
{
|
||||||
if (!completionService)
|
if (!completionService)
|
||||||
return
|
return
|
||||||
|
context.anchored = false;
|
||||||
context.title = ["Smart Completions"];
|
context.title = ["Smart Completions"];
|
||||||
context.keys.icon = 2;
|
context.keys.icon = 2;
|
||||||
context.incomplete = true;
|
context.incomplete = true;
|
||||||
@@ -1426,7 +1406,6 @@ function Completion() //{{{
|
|||||||
option: function option(context, scope)
|
option: function option(context, scope)
|
||||||
{
|
{
|
||||||
context.title = ["Option"];
|
context.title = ["Option"];
|
||||||
context.anchored = true;
|
|
||||||
context.keys = { text: "names", description: "description" };
|
context.keys = { text: "names", description: "description" };
|
||||||
context.completions = options;
|
context.completions = options;
|
||||||
if (scope)
|
if (scope)
|
||||||
@@ -1487,6 +1466,7 @@ function Completion() //{{{
|
|||||||
{
|
{
|
||||||
let prefs = Components.classes["@mozilla.org/preferences-service;1"]
|
let prefs = Components.classes["@mozilla.org/preferences-service;1"]
|
||||||
.getService(Components.interfaces.nsIPrefBranch);
|
.getService(Components.interfaces.nsIPrefBranch);
|
||||||
|
context.anchored = false;
|
||||||
context.title = ["Firefox Preference", "Value"];
|
context.title = ["Firefox Preference", "Value"];
|
||||||
context.keys = { text: function (item) item, description: function (item) options.getPref(item) };
|
context.keys = { text: function (item) item, description: function (item) options.getPref(item) };
|
||||||
context.completions = prefs.getChildList("", { value: 0 });
|
context.completions = prefs.getChildList("", { value: 0 });
|
||||||
@@ -1499,7 +1479,6 @@ function Completion() //{{{
|
|||||||
let engines = bookmarks.getSearchEngines();
|
let engines = bookmarks.getSearchEngines();
|
||||||
|
|
||||||
context.title = ["Search Keywords"];
|
context.title = ["Search Keywords"];
|
||||||
context.anchored = true;
|
|
||||||
context.completions = keywords.concat(engines);
|
context.completions = keywords.concat(engines);
|
||||||
context.keys = { text: 0, description: 1, icon: 2 };
|
context.keys = { text: 0, description: 1, icon: 2 };
|
||||||
|
|
||||||
@@ -1514,7 +1493,6 @@ function Completion() //{{{
|
|||||||
context.fork("keyword/" + keyword, keyword.length + space.length, null, function (context) {
|
context.fork("keyword/" + keyword, keyword.length + space.length, null, function (context) {
|
||||||
context.format = history.format;
|
context.format = history.format;
|
||||||
context.title = [keyword + " Quick Search"];
|
context.title = [keyword + " Quick Search"];
|
||||||
context.anchored = true;
|
|
||||||
context.background = true;
|
context.background = true;
|
||||||
context.compare = null;
|
context.compare = null;
|
||||||
context.generate = function () {
|
context.generate = function () {
|
||||||
@@ -1655,6 +1633,7 @@ function Completion() //{{{
|
|||||||
every(function (tag) (context.getKey(item, "tags") || []).
|
every(function (tag) (context.getKey(item, "tags") || []).
|
||||||
some(function (t) !compare(tag, t))));
|
some(function (t) !compare(tag, t))));
|
||||||
|
|
||||||
|
context.anchored = false;
|
||||||
if (!context.title)
|
if (!context.title)
|
||||||
context.title = ["URL", "Title"];
|
context.title = ["URL", "Title"];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user