From 9b3a30973e6a1bbc9dab7f93d9e4abeab0d2a5c4 Mon Sep 17 00:00:00 2001 From: glepnir Date: Fri, 3 May 2024 21:22:43 +0800 Subject: [PATCH] logic optimize --- lua/indentmini/init.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lua/indentmini/init.lua b/lua/indentmini/init.lua index 20d59cb..1afd8c1 100644 --- a/lua/indentmini/init.lua +++ b/lua/indentmini/init.lua @@ -27,11 +27,8 @@ local function find_row(bufnr, row, curindent, direction, render) local target_row = row + direction local count = api.nvim_buf_line_count(bufnr) while true do - local ok, lines = pcall(api.nvim_buf_get_text, bufnr, target_row, 0, target_row, -1, {}) - if not ok or target_row < 0 or target_row > count - 1 then - break - end - local non_empty = #lines[1] ~= 0 + local text = api.nvim_buf_get_text(bufnr, target_row, 0, target_row, -1, {})[1] + local non_empty = #text > 0 local target_indent = indent_fn(target_row + 1) if target_indent == 0 and non_empty and render then break @@ -39,6 +36,9 @@ local function find_row(bufnr, row, curindent, direction, render) return target_row end target_row = target_row + direction + if target_row < 0 or target_row > count - 1 then + return + end end end