vis: fast-jump: up uses unused down keys and down uses unused up keys

This commit is contained in:
2025-10-01 20:49:14 +02:00
parent 4866eb3f9c
commit 836267b80e

View File

@@ -10,7 +10,7 @@ local function search(p)
return Ct(((1 - p)^0 * Cp() * p)^0) return Ct(((1 - p)^0 * Cp() * p)^0)
end end
local up = { local up_keys = {
'a', 's', 'd', 'f' , 'a', 's', 'd', 'f' ,
'q', 'w', 'e', 'r', 't', 'g', 'q', 'w', 'e', 'r', 't', 'g',
'z', 'x', 'c', 'v', 'b', 'z', 'x', 'c', 'v', 'b',
@@ -22,7 +22,7 @@ local up = {
'`', '~', '`', '~',
} }
local down = { local down_keys = {
'j', 'k', 'l', ';', 'j', 'k', 'l', ';',
'y', 'u', 'i', 'o', 'p', 'y', 'u', 'i', 'o', 'p',
'n', 'm', ',', '.', '/', 'n', 'm', ',', '.', '/',
@@ -34,6 +34,22 @@ local down = {
"'", '"', '\\', '|', "'", '"', '\\', '|',
} }
local function merge(a, b)
local c = {}
for i = 1, #a do
c[i] = a[i]
end
for i = 1, #b do
c[#a + i] = b[i]
end
return c
end
local mu = #up_keys
local md = #down_keys
local up = merge(up_keys, down_keys)
local down = merge(down_keys, up_keys)
local jumps = {} local jumps = {}
local function jump(keys) local function jump(keys)
@@ -78,8 +94,13 @@ local function jump(keys)
break break
end end
end end
local nu = prev
local nd = #lst - next
local j = 1 local j = 1
for i = prev, 1, -1 do for i = prev, 1, -1 do
if j == mu + 1 then
j = j + nd
end
if not up[j] then if not up[j] then
break break
end end
@@ -89,6 +110,9 @@ local function jump(keys)
end end
j = 1 j = 1
for i = next, #lst do for i = next, #lst do
if j == md + 1 then
j = j + nu
end
if not down[j] then if not down[j] then
break break
end end