From ffc139f2a96640ca6c4d3dff9b95b7b9eace87ae Mon Sep 17 00:00:00 2001 From: Oliver Harley Date: Sun, 15 Sep 2024 16:21:25 +0200 Subject: [PATCH] feat(fast_wrap): add options for direct end_key use (#475) * feat(fast_wrap): add options for direct end_key use Barely tested. * fix: remove end_is_end config key * fixup! chore: fix misalignment in docs --- doc/nvim-autopairs.txt | 1 + lua/nvim-autopairs/fastwrap.lua | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/doc/nvim-autopairs.txt b/doc/nvim-autopairs.txt index ccc9bcdf..f9904305 100644 --- a/doc/nvim-autopairs.txt +++ b/doc/nvim-autopairs.txt @@ -412,6 +412,7 @@ FASTWRAP ~ chars = { '{', '[', '(', '"', "'" }, pattern = [=[[%'%"%>%]%)%}%,]]=], end_key = '$', + avoid_move_to_end = true, -- stay for direct end_key use keys = 'qwertyuiopzxcvbnmasdfghjkl', check_comma = true, highlight = 'Search', diff --git a/lua/nvim-autopairs/fastwrap.lua b/lua/nvim-autopairs/fastwrap.lua index b63b9a7e..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 },