diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2024-03-10 23:53:04 -0600 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2024-03-10 23:53:04 -0600 |
commit | 2aff69b0bb55f398d199db687617ed35d0335d5b (patch) | |
tree | 135b46b6a689b1cb59a49fbbebb8c4a095429ba1 /lua/warp/strategy/default.lua | |
parent | 64fb2114f35889eff0a082200471ce3ca33e43bf (diff) | |
download | nvim-warp-2aff69b0bb55f398d199db687617ed35d0335d5b.tar.gz nvim-warp-2aff69b0bb55f398d199db687617ed35d0335d5b.tar.bz2 nvim-warp-2aff69b0bb55f398d199db687617ed35d0335d5b.zip |
Added multiple strategies for deteriming the column.
Doing a full grid select can be intimidating. A word-wise strat is
probably a good thing to have.
Diffstat (limited to 'lua/warp/strategy/default.lua')
-rw-r--r-- | lua/warp/strategy/default.lua | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/lua/warp/strategy/default.lua b/lua/warp/strategy/default.lua new file mode 100644 index 0000000..55019d8 --- /dev/null +++ b/lua/warp/strategy/default.lua @@ -0,0 +1,92 @@ +local vim = assert(vim) + +local M = {} + +local hsel1 = "tnshrdlcumwfgypkbvjxqz" -- 21 +local hsel2 = "aeiou" -- 5 + +local function char_at(s, i) + local m = (i % #s) + 1 + return string.sub(s, m, m) +end + +local function make_big_line() + local col = 0 + local line = '' + + local v = '' + local c = nil + local i = 0 + local col_map = {} + while true do + v = char_at(hsel1, i) + if c then + if col_map[v .. c] then break end + col_map[c .. v] = col + end + c = char_at(hsel2, i) + if col_map[c .. v] then break end + line = line .. v + col = col + 1 + line = line .. c + col_map[v .. c] = col + col = col + 1 + i = i + 1 + end + + return line, col_map +end + +local big_line, col_map = make_big_line() + +M.default_strategy = function () + local filter + + return { + display = function () + local curpos = vim.api.nvim_win_get_cursor(0) + local line_at = vim.fn.getline(curpos[1]) + local unfiltered = big_line:sub(1, #line_at + 1) + local line = unfiltered + + if filter then + line = "" + local i = 1 + while i <= #unfiltered do + local curch = char_at(unfiltered, i - 1) + if curch == filter then + line = line .. char_at(unfiltered, i) + else + line = line .. ' ' + end + i = i + 1 + end + end + + return line + end, + + on_char = function (ch) + if not filter then + if ch == '$' or ch == '^' then + vim.cmd("normal! " .. ch) + return false + elseif not ch:match('[a-z]') then + vim.cmd("normal! f" .. ch) + return false + else + filter = ch + return true + end + else + if col_map[filter .. ch] then + vim.cmd("normal! " .. col_map[filter .. ch] .. "|") + end + end + + return false + end + } +end + +return M |