From 480d0be2fa33c262dd1c0bc3fd088ab315b3fd53 Mon Sep 17 00:00:00 2001 From: Eduardo Bray Date: Wed, 12 Jun 2024 01:15:56 -0400 Subject: [PATCH] fix(doom): Correct negative offset when resizing terminal (#462) * refactor(doom): Replace deprecated nvim_buf_get_option * fix(doom): Correct negative offset when resizing terminal --- lua/dashboard/theme/doom.lua | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lua/dashboard/theme/doom.lua b/lua/dashboard/theme/doom.lua index 213d5c2..fef3b03 100644 --- a/lua/dashboard/theme/doom.lua +++ b/lua/dashboard/theme/doom.lua @@ -118,7 +118,7 @@ local function generate_center(config) buffer = config.bufnr, callback = function() local buf = api.nvim_win_get_buf(0) - if vim.api.nvim_buf_get_option(buf, 'filetype') ~= 'dashboard' then + if vim.api.nvim_get_option_value('filetype', { buf = buf }) ~= 'dashboard' then return end @@ -132,11 +132,14 @@ local function generate_center(config) end before = curline - -- FIX: #422: In Lua the length of a string is the numbers of bytes not + -- FIX: #422: In Lua the length of a string is the number of bytes not -- the number of characters. local curline_str = api.nvim_buf_get_lines(config.bufnr, curline - 1, curline, false)[1] - local delta = col_width - api.nvim_strwidth(curline_str:sub(1, col + 1)) - api.nvim_win_set_cursor(config.winid, { curline, col + delta }) + local offset = col_width - api.nvim_strwidth(curline_str:sub(1, col + 1)) + if offset < 0 then + offset = 0 + end + api.nvim_win_set_cursor(config.winid, { curline, col + offset }) end, }) end, 0)