@@ -624,8 +624,43 @@ function M.show_marks_window(marks, project_name, search_query)
624624 pcall (vim .api .nvim_buf_add_highlight , buf , - 1 , hl .hl_group , hl .line , hl .col , hl .end_col )
625625 end
626626
627- -- Calculate window position (centered)
628- local row = math.floor ((vim .o .lines - WINDOW_HEIGHT ) / 2 )
627+ -- Calculate window position based on user configuration. By default the
628+ -- marks window is centered in the editor, but users can override
629+ -- this by specifying ui.position in their plugin configuration. A
630+ -- value of "top_center" positions the window near the top of the
631+ -- screen, while "bottom_center" aligns it near the bottom. Any
632+ -- unrecognised value falls back to the centered position. We also
633+ -- clamp the row so the window never renders outside the visible
634+ -- editor lines. Note: vim.o.lines returns the total number of
635+ -- lines in the UI (not just the buffer), so subtracting the window
636+ -- height ensures the window is fully on screen.
637+ local pos = nil
638+ if config and type (config .ui ) == " table" then
639+ pos = config .ui .position
640+ end
641+ local row
642+ if pos == " top_center" then
643+ -- Place the window a couple of lines down to avoid
644+ -- overlapping the very top of the UI. A value of 1 gives
645+ -- a small margin but still keeps the window anchored near
646+ -- the top.
647+ row = 1
648+ elseif pos == " bottom_center" then
649+ -- Place the window a couple of lines above the bottom to
650+ -- leave room for command line and status line. We subtract
651+ -- 2 to account for the border and padding.
652+ row = vim .o .lines - WINDOW_HEIGHT - 2
653+ else
654+ -- Default to center positioning
655+ row = math.floor ((vim .o .lines - WINDOW_HEIGHT ) / 2 )
656+ end
657+ -- Ensure row stays within valid bounds
658+ if row < 0 then
659+ row = 0
660+ elseif row > vim .o .lines - WINDOW_HEIGHT then
661+ row = math.max (vim .o .lines - WINDOW_HEIGHT , 0 )
662+ end
663+ -- Always center horizontally
629664 local col = math.floor ((vim .o .columns - WINDOW_WIDTH ) / 2 )
630665
631666 -- Window title
@@ -701,3 +736,4 @@ function M.cleanup()
701736end
702737
703738return M
739+
0 commit comments