diff --git a/doc/nvim-autopairs.txt b/doc/nvim-autopairs.txt index 7e9e5df5..087ba0d9 100644 --- a/doc/nvim-autopairs.txt +++ b/doc/nvim-autopairs.txt @@ -436,6 +436,7 @@ FASTWRAP ~ before_key = 'h', after_key = 'l', cursor_pos_before = true, + avoid_move_to_end = true, -- stay for direct end_key use keys = 'qwertyuiopzxcvbnmasdfghjkl', manual_position = true, highlight = 'Search', diff --git a/lua/nvim-autopairs/completion/cmp.lua b/lua/nvim-autopairs/completion/cmp.lua index 81c7024e..790585df 100644 --- a/lua/nvim-autopairs/completion/cmp.lua +++ b/lua/nvim-autopairs/completion/cmp.lua @@ -51,7 +51,8 @@ M.filetypes = { purescript = false, sh = false, bash = false, - nix = false + nix = false, + helm = false } M.on_confirm_done = function(opts) diff --git a/lua/nvim-autopairs/fastwrap.lua b/lua/nvim-autopairs/fastwrap.lua index 332c3fcc..3989bf9b 100644 --- a/lua/nvim-autopairs/fastwrap.lua +++ b/lua/nvim-autopairs/fastwrap.lua @@ -8,6 +8,7 @@ local default_config = { chars = { '{', '[', '(', '"', "'" }, pattern = [=[[%'%"%>%]%)%}%,%`]]=], end_key = '$', + avoid_move_to_end = true, -- choose your move behaviour for non-alphabetical end_keys' before_key = 'h', after_key = 'l', cursor_pos_before = true, @@ -57,7 +58,7 @@ M.show = function(line) if end_pair == '' then return end - local list_pos = {} + local list_pos = {} --holds target locations local index = 1 local str_length = #line local offset = -1 @@ -90,6 +91,7 @@ M.show = function(line) ) end end + log.debug(list_pos) local end_col, end_pos if config.manual_position then @@ -118,7 +120,16 @@ M.show = function(line) -- get the first char local char = #list_pos == 1 and config.end_key or M.getchar_handler() vim.api.nvim_buf_clear_namespace(0, M.ns_fast_wrap, row, row + 1) + for _, pos in pairs(list_pos) do + -- handle end_key specially + if char == config.end_key and char == pos.key then + vim.print("Run to end!") + -- M.highlight_wrap({pos = pos.pos, key = config.end_key}, row, col, #line, whitespace_line) + local move_end_key = (not config.avoid_move_to_end and char == string.upper(config.end_key)) + M.move_bracket(line, pos.col+1, end_pair, move_end_key) + break + end local hl_mark = { { pos = pos.pos - 1, key = config.before_key }, { pos = pos.pos + 1, key = config.after_key }, @@ -189,6 +200,10 @@ M.highlight_wrap = function(tbl_pos, row, col, end_col, whitespace_line) if config.use_virt_lines then local virt_lines = {} local start = 0 + local left_col = vim.fn.winsaveview().leftcol + if left_col > 0 then + vim.fn.winrestview({ leftcol = 0 }) + end for _, pos in ipairs(tbl_pos) do virt_lines[#virt_lines + 1] = { whitespace_line:sub(start + 1, pos.pos - 1), 'Normal' } virt_lines[#virt_lines + 1] = { pos.key, config.highlight }