Skip to content

Commit

Permalink
fix: adjust pastewin position when winbar is set (#232)
Browse files Browse the repository at this point in the history
closes #119
  • Loading branch information
mikesmithgh authored Apr 18, 2024
1 parent 9976b22 commit e291b9e
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 28 deletions.
2 changes: 1 addition & 1 deletion lua/kitty-scrollback/autocommands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lua/kitty-scrollback/launch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion lua/kitty-scrollback/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
Expand Down
2 changes: 1 addition & 1 deletion lua/kitty-scrollback/windows.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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([[$
$🭽▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔🭾
▏ ▕
$▏ ▕
▏ ▕
▏ ▕
▏ ▕
Expand All @@ -67,25 +69,26 @@ $🭽▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
▏ ▕
▏ \y Yank <C-CR> Execute <S-CR> 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([[$
$🭽▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔🭾
▏ ▕
$▏ ▕
▏ ▕
▏ ▕
▏ ▕
Expand All @@ -99,25 +102,28 @@ $🭽▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
▏ ▕
▏ \y Yank <C-CR> Execute <S-CR> 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
$🭽▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔🭾
$▏ ▕
▏ ▕
▏ ▕
Expand All @@ -132,24 +138,95 @@ $▏
▏ ▕
▏ \y Yank <C-CR> Execute <S-CR> 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 <C-CR> Execute <S-CR> 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 <C-CR> Execute <S-CR> 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
$🭽▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔🭾
$▏ ▕
▏ ▕
▏ ▕
Expand All @@ -164,11 +241,10 @@ $▏
▏ ▕
▏ \y Yank <C-CR> Execute <S-CR> 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)

0 comments on commit e291b9e

Please sign in to comment.