From 48c0bc7e731b2da1cd8a82dcfacfe9bfc8d4f0c5 Mon Sep 17 00:00:00 2001 From: fengwk <759543714@qq.com> Date: Sat, 10 Jun 2023 23:13:36 +0800 Subject: [PATCH] fix: huge single line performance (#1433) (#1615) --- lua/cmp/core.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lua/cmp/core.lua b/lua/cmp/core.lua index 891b008..d7a40b2 100644 --- a/lua/cmp/core.lua +++ b/lua/cmp/core.lua @@ -190,6 +190,18 @@ core.on_moved = function(self) self:filter() end +-- Find the suffix for the specified line +local function find_line_suffix(line) + local i = #line + while i > 0 do + if line:sub(i, i):find('%s') then + return line:sub(i + 1) + end + i = i - 1 + end + return line +end + ---Check autoindent ---@param trigger_event cmp.TriggerEvent ---@param callback function @@ -203,7 +215,7 @@ core.autoindent = function(self, trigger_event, callback) -- Check prefix local cursor_before_line = api.get_cursor_before_line() - local prefix = pattern.matchstr('[^[:blank:]]\\+$', cursor_before_line) or '' + local prefix = find_line_suffix(cursor_before_line) or '' if #prefix == 0 then return callback() end