From e3e105b11a3b34e93bdcee0c895801cf3ed2a835 Mon Sep 17 00:00:00 2001 From: windwp Date: Sat, 24 Jul 2021 07:09:46 +0700 Subject: [PATCH] fix: is_end_line function --- lua/nvim-autopairs/conds.lua | 5 +++-- tests/endwise_spec.lua | 13 +++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lua/nvim-autopairs/conds.lua b/lua/nvim-autopairs/conds.lua index 6889d50..886bde3 100644 --- a/lua/nvim-autopairs/conds.lua +++ b/lua/nvim-autopairs/conds.lua @@ -191,8 +191,9 @@ end cond.is_end_line = function() return function(opts) log.debug('is_end_line') - -- if the next char is blank - if opts.next_char ~= "" and opts.next_char:match("%s+") == nil then + local end_text = opts.line:sub(opts.col + 1) + -- end text is blank + if end_text ~= "" and end_text:match("^%s+$") == nil then return false end end diff --git a/tests/endwise_spec.lua b/tests/endwise_spec.lua index 824693d..cc1773f 100644 --- a/tests/endwise_spec.lua +++ b/tests/endwise_spec.lua @@ -17,8 +17,17 @@ local data = { filetype = "lua", linenr = 5, key = [[]], - before = [[function a()| ]], - after = [[ end ]] + before = [[function a()| ]], + after = [[ end ]] + }, + { + name = "lua function add endwise" , + filepath = './tests/endwise/init.lua', + filetype = "lua", + linenr = 5, + key = [[]], + before = [[function a()|x ab ]], + after = [[]] }, { name = "add if endwise" ,