Skip to content

Commit 4d74e75

Browse files
committed
fix #506
1 parent 2a406cd commit 4d74e75

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lua/nvim-autopairs/utils.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ M.text_sub_char = function(line, start, num)
161161
else
162162
finish = start + num - 1
163163
end
164+
165+
if start + finish < 0 then
166+
return ""
167+
end
164168
return string.sub(line, start, finish)
165169
end
166170

tests/nvim-autopairs_spec.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ _G.log = log
77
local utils = require('nvim-autopairs.utils')
88
_G.npairs = npairs;
99

10+
-- make test-file FILE=tests/nvim-autopairs_spec.lua
11+
1012
-- use only = true to test 1 case
1113
-- stylua: ignore
1214
local data = {
@@ -833,6 +835,16 @@ local data = {
833835
' test({',
834836
}
835837
},
838+
{
839+
name = "89 <cr> key on markdown",
840+
filetype = "markdown",
841+
key = [[<cr>]],
842+
before = [[|```python ]],
843+
after = {
844+
"",
845+
"|```python"
846+
}
847+
},
836848
}
837849

838850
local run_data = _G.Test_filter(data)

0 commit comments

Comments
 (0)