From 7827458568ed28b7e8adbcd3a48aafec54681faf Mon Sep 17 00:00:00 2001 From: NicolasGB Date: Wed, 11 Feb 2026 13:52:19 +0100 Subject: [PATCH] fix(terminal): clamp tooltip dimensions to available screen space Prevent tooltip from overflowing when the cursor is near the bottom or right edge of the screen by clamping width and height to the remaining space. --- lua/jj/ui/terminal.lua | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lua/jj/ui/terminal.lua b/lua/jj/ui/terminal.lua index 8722bb9..04974cc 100644 --- a/lua/jj/ui/terminal.lua +++ b/lua/jj/ui/terminal.lua @@ -325,6 +325,7 @@ function M.run_floating(cmd, keymaps) { modes = { "n", "v" }, lhs = "i", rhs = function() end }, { modes = { "n", "v" }, lhs = "c", rhs = function() end }, { modes = { "n", "v" }, lhs = "a", rhs = function() end }, + { modes = { "n", "v" }, lhs = "", rhs = function() end }, { modes = { "n", "v" }, lhs = "u", rhs = function() end }, } @@ -577,6 +578,20 @@ function M.run_tooltip(cmd, tool_opts) state.tooltip_buf = nil end + local height = tool_opts.height + if height then + local cursor_screen_row = vim.fn.screenrow() + local available = vim.o.lines - cursor_screen_row - 2 + height = math.min(height, math.max(available, 1)) + end + + local width = tool_opts.width + if width then + local cursor_screen_col = vim.fn.screencol() + local available = vim.o.columns - cursor_screen_col - 2 + width = math.min(width, math.max(available, 1)) + end + state.tooltip_buf, state.tooltip_win = buffer.create_float({ title = tool_opts.title or " JJ ", title_pos = "center", @@ -585,8 +600,8 @@ function M.run_tooltip(cmd, tool_opts) relative = "cursor", row = 1, col = 0, - width = tool_opts.width, - height = tool_opts.height, + width = width, + height = height, win_options = { wrap = true, number = false,