summaryrefslogtreecommitdiff
path: root/lua/warp.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/warp.lua')
-rw-r--r--lua/warp.lua74
1 files changed, 18 insertions, 56 deletions
diff --git a/lua/warp.lua b/lua/warp.lua
index d3b6337..a2332f4 100644
--- a/lua/warp.lua
+++ b/lua/warp.lua
@@ -19,7 +19,7 @@ local function new_panel(buf, row, col, width, height)
col = col,
width = width,
height = height,
- focusable = false,
+ focusable = true,
style = 'minimal'
})
vim.api.nvim_win_set_option(w, "winhighlight", "Normal:WarpNormal")
@@ -57,35 +57,8 @@ M.open_horiz = function()
local width = vim.api.nvim_win_get_width(current_win) - width_of_garbage
M.horiz_bufnr = vim.api.nvim_create_buf(0, 1)
- local col = 0
- local line = ''
-
- local v = ''
- local c = nil
- local i = 0
local line_at = vim.fn.getline(curpos[1])
- M.col_map = {}
local max_width = math.min(width, #line_at + 1)
- while col < max_width do
- v = char_at(hsel1, i)
- if c then
- if M.col_map[v .. c] then break end
- M.col_map[c .. v] = col - 1
- end
- c = char_at(hsel2, i)
- if M.col_map[c .. v] then break end
- line = line .. v
- col = col + 1
- if col < max_width then
- line = line .. c
- M.col_map[v .. c] = col - 1
- col = col + 1
- i = i + 1
- end
- end
-
- vim.api.nvim_buf_set_lines(M.horiz_bufnr, 0, -1, 0, {' ' .. line})
- M.horiz_line = line
return new_panel(M.horiz_bufnr, curpos[1] - topline + 1, width_of_garbage - 1,
max_width + 2, 1)
@@ -127,7 +100,11 @@ local function next_char()
return vim.fn.nr2char(vim.fn.getchar())
end
-M.run = function()
+M.run = function(strat_fn)
+ if not strat_fn then
+ strat_fn = require('warp.strategy.default').default_col_strategy
+ end
+
local current_pos = vim.api.nvim_win_get_cursor(0)
local old_scroll = vim.o.scrolloff
vim.o.scrolloff = 0
@@ -164,36 +141,21 @@ M.run = function()
vim.api.nvim_win_set_cursor(0, {r, current_pos[2]})
- local read_col = function()
- w = M.open_horiz()
- local hch1 = next_char()
-
- if hch1 == '\x1b' then
- return nil
- elseif hch1 == '.' then
- return current_pos[2]
- elseif not hch1:match('[a-z]') then
- return hch1
- else
- M.filter_horiz_string(hch1)
-
- local hch2 = next_char()
- if hch2 == '\x1b' then return end
- return M.col_map[hch1 .. hch2]
+ local strat = strat_fn()
+ w = M.open_horiz()
+ local disp = strat.display()
+ if disp then
+ vim.api
+ .nvim_buf_set_lines(M.horiz_bufnr, 0, -1, 0, {' ' .. disp})
+ local ch = next_char()
+ while ch ~= '\x1b' and strat.on_char(ch) do
+ vim.api.nvim_buf_set_lines(M.horiz_bufnr, 0, -1, 0,
+ {' ' .. strat.display()})
+ ch = next_char()
end
end
- local c = read_col()
- if w then cleanup(w) end
- if not c then return end
-
- if c == '$' or c == '^' then
- vim.cmd("normal! " .. c)
- elseif type(c) == 'string' then
- vim.cmd("normal! f" .. c)
- else
- vim.cmd("normal! " .. (c + 1) .. "|") -- handle multibyte characters
- end
+ cleanup(w)
end)()
vim.o.scrolloff = old_scroll