From e85687784a5549c59f5f90f2d2c324a8ce7f8d8b Mon Sep 17 00:00:00 2001 From: jakewvincent Date: Wed, 10 Jul 2024 08:27:11 -0700 Subject: [PATCH] fix: Prevent infinite loop by using custom gmatch iterator (#237) --- lua/mkdnflow/links.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lua/mkdnflow/links.lua b/lua/mkdnflow/links.lua index d6804d1..9934cef 100644 --- a/lua/mkdnflow/links.lua +++ b/lua/mkdnflow/links.lua @@ -865,8 +865,12 @@ M.createLink = function(args) -- is, perform the search until a match is found whose right edge follows -- the cursor position if cursor_word ~= '' then - while right < col do - left, right = string.find(line, cursor_word, right, true) + for _left, _right in utils.betterGmatch(line, cursor_word) do + if _right >= col then + left = _left + right = _right + break + end end else left, right = col + 1, col