fix: terminal snapping back to bottom on tabenter
This commit is contained in:
parent
2538e9b246
commit
a56377c11e
2 changed files with 40 additions and 12 deletions
|
|
@ -116,15 +116,3 @@ vim.keymap.set("n", "<A-'>", "<CMD>tab split<CR>", { desc = "Clone window in new
|
|||
|
||||
vim.keymap.set("n", "<C-w><CR>", "<CMD>term<CR>i", { desc = "Terminal" })
|
||||
|
||||
vim.api.nvim_create_autocmd("TabEnter", {
|
||||
callback = function()
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
local buftype = vim.api.nvim_buf_get_option(bufnr, "buftype")
|
||||
|
||||
if buftype == "terminal" then
|
||||
-- Enter Terminal-Job mode
|
||||
vim.api.nvim_feedkeys("i", "n", false)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -61,3 +61,43 @@ endfunction
|
|||
autocmd TermOpen * call TerminalSettings()
|
||||
]])
|
||||
|
||||
-- Terminal window scroll positions by default are not saved when switching tabs
|
||||
local termview = {}
|
||||
|
||||
vim.api.nvim_create_autocmd({ "BufLeave", "WinLeave" }, {
|
||||
pattern = "term://*",
|
||||
callback = function()
|
||||
termview[vim.api.nvim_get_current_buf()] = vim.fn.winsaveview()
|
||||
end,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd({ "BufEnter", "WinEnter" }, {
|
||||
pattern = "term://*",
|
||||
callback = function()
|
||||
local view = termview[vim.api.nvim_get_current_buf()]
|
||||
if view then
|
||||
vim.fn.winrestview(view)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd("TabEnter", {
|
||||
callback = function()
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
local buftype = vim.api.nvim_buf_get_option(bufnr, "buftype")
|
||||
if buftype ~= "terminal" then
|
||||
return
|
||||
end
|
||||
local view = termview[bufnr]
|
||||
if view then
|
||||
vim.fn.winrestview(view)
|
||||
-- only auto-insert if they were at the bottom (i.e. not deliberately scrolled up)
|
||||
local last_line = vim.api.nvim_buf_line_count(bufnr)
|
||||
if view.lnum >= last_line then
|
||||
vim.api.nvim_feedkeys("i", "n", false)
|
||||
end
|
||||
else
|
||||
vim.api.nvim_feedkeys("i", "n", false)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue