From 18a9d044fff4bbecede9e8c69435aacfc7fa9b98 Mon Sep 17 00:00:00 2001 From: milksys Date: Sat, 12 Aug 2023 12:13:07 +0900 Subject: [PATCH 1/2] Fix: byte text, cursormoved error --- lua/smartcolumn.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lua/smartcolumn.lua b/lua/smartcolumn.lua index 3b55c7e..29cddd7 100644 --- a/lua/smartcolumn.lua +++ b/lua/smartcolumn.lua @@ -28,8 +28,15 @@ local function exceed(buf, win, min_colorcolumn) end local max_column = 0 + for _, line in pairs(lines) do - max_column = math.max(max_column, vim.fn.strdisplaywidth(line)) + local err, column_number = pcall(vim.fn.strdisplaywidth, line) + + if err == false then + return false + end + + max_column = math.max(max_column, column_number) end return not is_disabled() and max_column > min_colorcolumn From 7bd83ff0661ee988e5d2ce29964c6cd3e61bbc99 Mon Sep 17 00:00:00 2001 From: Max Shen Date: Sat, 2 Sep 2023 23:44:13 +0800 Subject: [PATCH 2/2] refactor: refine variable naming for pcall --- lua/smartcolumn.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/smartcolumn.lua b/lua/smartcolumn.lua index 29cddd7..7fc8417 100644 --- a/lua/smartcolumn.lua +++ b/lua/smartcolumn.lua @@ -30,9 +30,9 @@ local function exceed(buf, win, min_colorcolumn) local max_column = 0 for _, line in pairs(lines) do - local err, column_number = pcall(vim.fn.strdisplaywidth, line) + local success, column_number = pcall(vim.fn.strdisplaywidth, line) - if err == false then + if not success then return false end