aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorgi Kirilov <in.the@repo>2020-06-27 02:38:03 +0300
committerGeorgi Kirilov <in.the@repo>2020-06-27 03:29:11 +0300
commit67c978b75b551f25ac01022e979d67589f8ae4d0 (patch)
treeb364a697ad7886c1dfef7f3edebbb95900b298b9
parent65533462ed4018d4c14e6c919bcdb8209b755ad2 (diff)
downloadvis-toggler-67c978b75b551f25ac01022e979d67589f8ae4d0.tar.gz
fix wrong words order in pattern
Since + is _ordered_ choice in LPeg, if two words start with the same string, and the shorter one comes first in the pattern, the longer one will never match. Fix this by sorting all the words before making a pattern out of them.
-rw-r--r--init.lua10
1 files changed, 9 insertions, 1 deletions
diff --git a/init.lua b/init.lua
index 817279c..4bac6b0 100644
--- a/init.lua
+++ b/init.lua
@@ -102,12 +102,20 @@ end
local function preprocess(tbl)
local cfg, ord = {}, P(false)
+ local longer_first = {}
for _, options in ipairs(tbl) do
for i, key in ipairs(options) do
cfg[key] = {i, options}
- ord = ord + key
+ table.insert(longer_first, key)
end
end
+ table.sort(longer_first, function(f, s)
+ local flen, slen = #f, #s
+ return flen > slen or flen == slen and f < s
+ end)
+ for _, key in ipairs(longer_first) do
+ ord = ord + key
+ end
return cfg, ord
end