Skip to content

Commit fb620cd

Browse files
committed
feat(ui): add configurable window position (top_center, center, bottom_center)
Adds `ui.position` option to control where the marks window appears. Defaults to 'center'. Supported values: - top_center: positions the window near the top, centered horizontally - bottom_center: positions it near the bottom - center: keeps the existing centered behavior
1 parent fb75cb9 commit fb620cd

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

lua/marksman/init.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,19 @@ local default_config = {
3636
max_marks = 100,
3737
search_in_ui = true,
3838
silent = false,
39+
-- minimal should be configured via ui opts
3940
minimal = false,
4041
disable_default_keymaps = false,
4142
debounce_ms = 500, -- Debounce save operations
43+
-- UI specific settings
44+
ui = {
45+
-- Position of the marks window.
46+
-- "center" positions the window in the middle of the editor (default).
47+
-- "top_center" aligns the window at the top of the screen, centered horizontally.
48+
-- "bottom_center" aligns the window at the bottom of the screen, centered horizontally.
49+
minimal = false,
50+
position = "center",
51+
},
4252
}
4353

4454
-- Configuration validation schema
@@ -732,3 +742,4 @@ function M.setup(opts)
732742
end
733743

734744
return M
745+

lua/marksman/ui.lua

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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()
701736
end
702737

703738
return M
739+

0 commit comments

Comments
 (0)