mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 21:42:27 +01:00
Fix substrings, even though they werent ostensibly broken except in corner cases.
This commit is contained in:
@@ -124,28 +124,23 @@ CompletionContext.prototype = {
|
|||||||
// Temporary
|
// Temporary
|
||||||
get allSubstrings()
|
get allSubstrings()
|
||||||
{
|
{
|
||||||
let lists = [c.substrings for ([i, c] in Iterator(this.contextList)) if (c.hasItems && c.items.length)];
|
let contexts = this.contextList.filter(function (c) c.hasItems && c.items.length);
|
||||||
let minStart = Math.min.apply(Math, [c.offset for ([k, c] in Iterator(this.contextList)) if (c.hasItems && c.items.length)]);
|
let minStart = Math.min.apply(Math, contexts.map(function (c) c.offset));
|
||||||
let self = this;
|
let lists = contexts.map(function (context) {
|
||||||
let items = this.contextList.map(function (context) {
|
let prefix = context.value.substring(minStart, context.offset);
|
||||||
if (!context.hasItems)
|
return context.substrings.map(function (s) prefix + s);
|
||||||
return [];
|
|
||||||
let prefix = self.value.substring(minStart, context.offset);
|
|
||||||
return context.substrings.map(function (str) prefix + str);
|
|
||||||
});
|
});
|
||||||
return util.Array.uniq(util.Array.flatten(items), true);
|
|
||||||
|
let substrings = lists.reduce(
|
||||||
|
function (res, str) res.filter(
|
||||||
|
function (s) s.substr(0, Math.min(s.length, str.length))),
|
||||||
|
lists.pop());
|
||||||
|
return util.Array.uniq(substrings);
|
||||||
},
|
},
|
||||||
// Temporary
|
// Temporary
|
||||||
get longestAllSubstring()
|
get longestAllSubstring()
|
||||||
{
|
{
|
||||||
let substrings = this.allSubstrings;
|
let substrings = this.allSubstrings;
|
||||||
// Filter out any matches that don't match for all contexts
|
|
||||||
substrings = substrings.reduce(
|
|
||||||
function (res, str) res.filter(function (s) {
|
|
||||||
let len = Math.min(s.length, str.length);
|
|
||||||
return str.substr(0, len) == s.substr(0, len)
|
|
||||||
}),
|
|
||||||
substrings);
|
|
||||||
// Find the longest match
|
// Find the longest match
|
||||||
return substrings.reduce(function (a, b) a.length > b.length ? a : b, "");
|
return substrings.reduce(function (a, b) a.length > b.length ? a : b, "");
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user