Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix terminal going offscreen in neovide in top/bottom/fullscreen #17

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions lua/neoterm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ local function normalize_position(position)
return position
end

local NEOVIDE_PADDING = 2
local DEFAULT_PADDING = 0

local function is_neovide()
return vim.g.neovide ~= nil
end

-- Opens the terminal window. If it was opened previously, the same terminal buffer will be used
-- Options:
-- position - override the global config position
Expand Down Expand Up @@ -154,33 +161,35 @@ function neoterm.open(opts)
border = "single",
}

local width_padding = is_neovide() and NEOVIDE_PADDING or DEFAULT_PADDING

if position == 0 then -- fullscreen
winopts.width = ui.width
winopts.width = ui.width - width_padding
winopts.height = ui.height - vim.o.cmdheight - 3
winopts.row = 0
winopts.col = 0
elseif position == 1 then -- top
winopts.width = ui.width
winopts.width = ui.width - width_padding
winopts.height = math.floor(ui.height * height) - vim.o.cmdheight - 3
winopts.row = 0
winopts.col = 0
elseif position == 2 then -- right
winopts.width = math.floor(ui.width * width)
winopts.width = math.floor(ui.width * width) - width_padding
winopts.height = ui.height - vim.o.cmdheight - 3
winopts.row = 0
winopts.col = ui.width - winopts.width
elseif position == 3 then -- bottom
winopts.width = ui.width
winopts.width = ui.width - width_padding
winopts.height = math.floor(ui.height * height) - vim.o.cmdheight - 3
winopts.row = ui.height - winopts.height - vim.o.cmdheight - 3
winopts.col = 0
elseif position == 4 then -- left
winopts.width = math.floor(ui.width * width)
winopts.width = math.floor(ui.width * width) - width_padding
winopts.height = ui.height - vim.o.cmdheight - 3
winopts.row = 0
winopts.col = 0
elseif position == 5 then -- center
winopts.width = math.floor(ui.width * width)
winopts.width = math.floor(ui.width * width) - width_padding
winopts.height = math.floor(ui.height * height) - vim.o.cmdheight - 3
winopts.row = math.floor((ui.height - winopts.height) / 2)
winopts.col = math.floor((ui.width - winopts.width) / 2)
Expand Down