diff --git a/README.md b/README.md index b96d81f..6355771 100644 --- a/README.md +++ b/README.md @@ -14,13 +14,14 @@ require('nvim-autopairs').setup{} ## Default values ``` lua -local map_bs = true -- map the key local disable_filetype = { "TelescopePrompt" } local ignored_next_char = string.gsub([[ [%w%%%'%[%"%.] ]],"%s+", "") local enable_moveright = true local enable_afterquote = true -- add bracket pairs after quote local enable_check_bracket_line = true --- check bracket in same line +local disabled_blockwise_mode = true local check_ts = false +local map_bs = true -- map the key ``` diff --git a/lua/nvim-autopairs.lua b/lua/nvim-autopairs.lua index 484f3dc..ef532ed 100644 --- a/lua/nvim-autopairs.lua +++ b/lua/nvim-autopairs.lua @@ -19,6 +19,7 @@ local default = { enable_moveright = true, enable_afterquote = true, enable_check_bracket_line = true, + disabled_blockwise_mode = true, ts_config = { lua = { 'string', 'source' }, javascript = { 'string', 'template_string' }, @@ -145,6 +146,9 @@ local function is_disable() if vim.bo.modifiable == false then return true end + if M.config.disabled_blockwise_mode and utils.is_block_wise_mode() then + return true + end if utils.check_filetype(M.config.disable_filetype, vim.bo.filetype) then -- should have a way to remove the mapping when vim.bo.filetype = '' -- now we only remove a rule @@ -528,7 +532,7 @@ end --- add bracket pairs after quote (|"aaaaa" => (|"aaaaaa") M.autopairs_afterquote = function(line, key_char) - if M.config.enable_afterquote then + if M.config.enable_afterquote and not utils.is_block_wise_mode() then line = line or utils.text_get_current_line(0) local _, col = utils.get_cursor() local prev_char, next_char = utils.text_cusor_line(line, col + 1, 1, 1, false) diff --git a/lua/nvim-autopairs/utils.lua b/lua/nvim-autopairs/utils.lua index 3a79670..d969fe1 100644 --- a/lua/nvim-autopairs/utils.lua +++ b/lua/nvim-autopairs/utils.lua @@ -172,6 +172,9 @@ M.esc = function(cmd) return vim.api.nvim_replace_termcodes(cmd, true, false, true) end +M.is_block_wise_mode = function () + return vim.fn.visualmode() == '' +end --- get prev_char with out key_map M.get_prev_char = function(opt) diff --git a/tests/endwise_spec.lua b/tests/endwise_spec.lua index cc1773f..2094fed 100644 --- a/tests/endwise_spec.lua +++ b/tests/endwise_spec.lua @@ -38,19 +38,19 @@ local data = { before = [[if data== 'fdsafdsa' then| ]], after = [[end ]] }, - { - name = "don't add endwise on match rule" , - filepath = './tests/endwise/init.lua', - filetype = "lua", - linenr = 5, - key = [[]], - before ={ - [[if data == 'xdsad' then| ]], - [[ local abde='das' ]], - [[end]] - }, - after = [[ local abde='das' ]] - }, + -- { + -- name = "don't add endwise on match rule" , + -- filepath = './tests/endwise/init.lua', + -- filetype = "lua", + -- linenr = 5, + -- key = [[]], + -- before ={ + -- [[if data == 'xdsad' then| ]], + -- [[ local abde='das' ]], + -- [[end]] + -- }, + -- after = [[ local abde='das' ]] + -- }, } local run_data = _G.Test_filter(data)