diff --git a/lua/kitty-scrollback/autocommands.lua b/lua/kitty-scrollback/autocommands.lua index db8c6c5b..66fdae43 100644 --- a/lua/kitty-scrollback/autocommands.lua +++ b/lua/kitty-scrollback/autocommands.lua @@ -66,7 +66,7 @@ M.set_paste_window_resized_autocmd = function() group = vim.api.nvim_create_augroup('KittyScrollBackNvimPasteWindowResized', { clear = true }), callback = function() if p.paste_winid then - local lnum = (p.pos.cursor_line - p.pos.win_first_line - 1) + ksb_util.tab_offset() + local lnum = (p.pos.cursor_line - p.pos.win_first_line - 1) + ksb_util.line_offset() local col = p.pos.col + 1 local ok, current_winopts = pcall(vim.api.nvim_win_get_config, p.paste_winid) if ok then diff --git a/lua/kitty-scrollback/launch.lua b/lua/kitty-scrollback/launch.lua index 88a7e5ab..e65f5126 100644 --- a/lua/kitty-scrollback/launch.lua +++ b/lua/kitty-scrollback/launch.lua @@ -153,7 +153,7 @@ local function set_options() end local set_cursor_position = vim.schedule_wrap(function(d) - local tab_offset = ksb_util.tab_offset() + local tab_offset = ksb_util.line_offset() local x = d.cursor_x - 1 local y = d.cursor_y - 1 - tab_offset local scrolled_by = d.scrolled_by diff --git a/lua/kitty-scrollback/util.lua b/lua/kitty-scrollback/util.lua index 92efa0d3..56a7689b 100644 --- a/lua/kitty-scrollback/util.lua +++ b/lua/kitty-scrollback/util.lua @@ -63,12 +63,23 @@ end M.tab_offset = function() -- if always displaying a tabline or if displaying a tabline when more than one tab exists - if vim.o.showtabline == 2 or (vim.o.showtabline == 1 and vim.fn.tabpagenr('$') > 1) then + if vim.o.showtabline >= 2 or (vim.o.showtabline == 1 and vim.fn.tabpagenr('$') > 1) then return 1 end return 0 end +M.winbar_offset = function() + if vim.o.winbar ~= '' then + return 1 + end + return 0 +end + +M.line_offset = function() + return M.tab_offset() + M.winbar_offset() +end + M.clear_yank_autocommand_and_get_visual_selection = function() vim.api.nvim_clear_autocmds({ group = vim.api.nvim_create_augroup('KittyScrollBackNvimTextYankPost', { clear = true }), diff --git a/lua/kitty-scrollback/windows.lua b/lua/kitty-scrollback/windows.lua index aa4fc834..0aee2dcd 100644 --- a/lua/kitty-scrollback/windows.lua +++ b/lua/kitty-scrollback/windows.lua @@ -108,7 +108,7 @@ M.open_paste_window = function(start_insert) ksb_keymaps.set_buffer_local_keymaps(p.paste_bufid) end if not p.paste_winid or vim.fn.win_id2win(p.paste_winid) == 0 then - local winopts = M.paste_winopts(lnum + ksb_util.tab_offset(), col) + local winopts = M.paste_winopts(lnum + ksb_util.line_offset(), col) p.paste_winid = vim.api.nvim_open_win(p.paste_bufid, true, winopts) vim.api.nvim_set_option_value('scrolloff', 2, { win = p.paste_winid, diff --git a/tests/kitty-scrollback/kitty_scrollback_tabline_spec.lua b/tests/kitty-scrollback/kitty_scrollback_line_offset_spec.lua similarity index 64% rename from tests/kitty-scrollback/kitty_scrollback_tabline_spec.lua rename to tests/kitty-scrollback/kitty_scrollback_line_offset_spec.lua index f5a0a3b7..f87293ff 100644 --- a/tests/kitty-scrollback/kitty_scrollback_tabline_spec.lua +++ b/tests/kitty-scrollback/kitty_scrollback_line_offset_spec.lua @@ -46,14 +46,16 @@ describe('kitty-scrollback.nvim', function() it('should position paste window at prompt when showtabline=0', function() h.assert_screen_equals( h.feed_kitty({ + h.enter(), h.open_kitty_scrollback_nvim(), + [[:set tabline=tabline\ header]], [[:set showtabline=0]], h.send_without_newline([[a]]), }), { - stdout = [[ + stdout = h.with_status_win([[$ $🭽▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔🭾 - ▏ ▕ +$▏ ▕ ▏ ▕ ▏ ▕ ▏ ▕ @@ -67,25 +69,26 @@ $🭽▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ ▏ ▕ ▏ \y Yank Execute Paste :w Paste g? Toggle Mappings ▕ 🭼▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁🭿 -]], - cursor_y = 2, +]]), + cursor_y = 3, cursor_x = 3, - }, - 'kitty-scrollback.nvim content did not match the terminal screen' + } ) end) it('should position paste window at prompt when showtabline=1 and one tab', function() h.assert_screen_equals( h.feed_kitty({ + h.enter(), h.open_kitty_scrollback_nvim(), + [[:set tabline=tabline\ header]], [[:set showtabline=1]], h.send_without_newline([[a]]), }), { - stdout = [[ + stdout = h.with_status_win([[$ $🭽▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔🭾 - ▏ ▕ +$▏ ▕ ▏ ▕ ▏ ▕ ▏ ▕ @@ -99,25 +102,28 @@ $🭽▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ ▏ ▕ ▏ \y Yank Execute Paste :w Paste g? Toggle Mappings ▕ 🭼▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁🭿 -]], - cursor_y = 2, + +]]), + cursor_y = 3, cursor_x = 3, - }, - 'kitty-scrollback.nvim content did not match the terminal screen' + } ) end) it('should position paste window at prompt when showtabline=1 and two tabs', function() h.assert_screen_equals( h.feed_kitty({ + h.send_without_newline(h.enter()), h.open_kitty_scrollback_nvim(), + [[:set tabline=tabline\ header]], [[:set showtabline=1]], [[:tab new]], h.send_without_newline([[gta]]), }), { - stdout = [[ - 🭽▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔🭾 + stdout = h.with_status_win([[ +tabline header +$🭽▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔🭾 $▏ ▕ ▏ ▕ ▏ ▕ @@ -132,24 +138,95 @@ $▏ ▏ ▕ ▏ \y Yank Execute Paste :w Paste g? Toggle Mappings ▕ 🭼▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁🭿 -]], - cursor_y = 2, +]]), + cursor_y = 3, cursor_x = 3, - }, - 'kitty-scrollback.nvim content did not match the terminal screen' + } ) end) it('should position paste window at prompt when showtabline=2', function() h.assert_screen_equals( h.feed_kitty({ + h.send_without_newline(h.enter()), + h.open_kitty_scrollback_nvim(), + [[:set tabline=tabline\ header]], + [[:set showtabline=2]], + h.send_without_newline([[a]]), + }), + { + stdout = h.with_status_win([[ +tabline header +$🭽▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔🭾 +$▏ ▕ + ▏ ▕ + ▏ ▕ + ▏ ▕ + ▏ ▕ + ▏ ▕ + ▏ ▕ + ▏ ▕ + ▏ ▕ + ▏ ▕ + 🭼▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁🭿 + ▏ ▕ + ▏ \y Yank Execute Paste :w Paste g? Toggle Mappings ▕ + 🭼▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁🭿 +]]), + cursor_y = 3, + cursor_x = 3, + } + ) + end) + + it('should position paste window at prompt when winbar is set', function() + h.assert_screen_equals( + h.feed_kitty({ + h.send_without_newline(h.enter()), h.open_kitty_scrollback_nvim(), + [[:set winbar=winbar\ header]], + h.send_without_newline([[a]]), + }), + { + stdout = h.with_status_win([[ +winbar header +$🭽▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔🭾 +$▏ ▕ + ▏ ▕ + ▏ ▕ + ▏ ▕ + ▏ ▕ + ▏ ▕ + ▏ ▕ + ▏ ▕ + ▏ ▕ + ▏ ▕ + 🭼▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁🭿 + ▏ ▕ + ▏ \y Yank Execute Paste :w Paste g? Toggle Mappings ▕ + 🭼▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁🭿 +]]), + cursor_y = 3, + cursor_x = 3, + } + ) + end) + + it('should position paste window at prompt when showtabline=2 and winbar is set', function() + h.assert_screen_equals( + h.feed_kitty({ + h.send_without_newline(h.enter()), + h.open_kitty_scrollback_nvim(), + [[:set tabline=tabline\ header]], [[:set showtabline=2]], + [[:set winbar=winbar\ header]], h.send_without_newline([[a]]), }), { - stdout = [[ - 🭽▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔🭾 + stdout = h.with_status_win([[ +tabline header +winbar header +$🭽▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔🭾 $▏ ▕ ▏ ▕ ▏ ▕ @@ -164,11 +241,10 @@ $▏ ▏ ▕ ▏ \y Yank Execute Paste :w Paste g? Toggle Mappings ▕ 🭼▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁🭿 -]], - cursor_y = 2, +]]), + cursor_y = 4, cursor_x = 3, - }, - 'kitty-scrollback.nvim content did not match the terminal screen' + } ) end) end)