Skip to content

Commit

Permalink
improve float layout
Browse files Browse the repository at this point in the history
  • Loading branch information
glepnir committed Oct 6, 2023
1 parent f3ae7a9 commit 38afc03
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
4 changes: 0 additions & 4 deletions lua/lspsaga/finder/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ local ns = api.nvim_create_namespace('SagaFinder')
function fd:init_layout()
self.callerwinid = api.nvim_get_current_win()
local win_width = api.nvim_win_get_width(0)
if config.finder.right_width > 0.6 then
vim.notify('[lspsaga] finder right width must be less than 0.7')
config.finder.right_width = 0.5
end
if self.layout == 'dropdown' then
self.lbufnr, self.lwinid, _, self.rwinid =
ly:new(self.layout):dropdown(math.floor(vim.o.lines * config.finder.max_height)):done()
Expand Down
2 changes: 1 addition & 1 deletion lua/lspsaga/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ local default_config = {
finder = {
max_height = 0.5,
left_width = 0.3,
right_width = 0.5,
right_width = 0.7,
methods = {},
default = 'ref+imp',
layout = 'float',
Expand Down
41 changes: 28 additions & 13 deletions lua/lspsaga/layout/float.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ function M.left(height, width, bufnr, title)
fn.winrestview({ topline = topline + (height + 4 - room) })
end

local spaces = vim.o.columns - api.nvim_win_get_width(curwin)
if spaces > 0 then
float_opt.width = float_opt.width + math.floor(spaces * 0.4)
end

return win
:new_float(float_opt, true)
:bufopt({
Expand All @@ -50,27 +55,37 @@ function M.right(left_winid, opt)
opt = opt or {}
local win_conf = api.nvim_win_get_config(left_winid)
local original = vim.deepcopy(win_conf)
local row = win_conf.row[false]
local wincol = fn.win_screenpos(win_conf.win)[2]
local spaces = vim.o.columns - wincol - api.nvim_win_get_width(win_conf.win)
local percent = opt.width or 0.7

if spaces <= 0 then
win_conf.col = win_conf.col[false] - win_conf.width - 1
win_conf.width = math.floor((vim.o.columns - wincol) * percent)
else
win_conf.col = win_conf.col[false] + win_conf.width + 2
win_conf.width = math.floor(spaces * percent)
end

if original.border then
local map = border_map()
original.border[5] = map[ui.border][1]
original.border[3] = map[ui.border][2]
if spaces <= 0 then
original.border[1] = map[ui.border][2]
original.border[7] = map[ui.border][1]
win_conf.border[4] = ''
else
original.border[5] = map[ui.border][1]
original.border[3] = map[ui.border][2]
win_conf.border[8] = ''
win_conf.border[7] = ''
end
api.nvim_win_set_config(left_winid, original)
end

local col = win_conf.col[false] + win_conf.width + 2
local row = win_conf.row[false]
local spaces = vim.o.columns - fn.win_screenpos(win_conf.win)[2] - win_conf.width
local percent = opt.width or 0.5
win_conf.width = math.floor(spaces * percent)

win_conf.row = row
win_conf.col = col
win_conf.title = nil
win_conf.title_pos = nil
if win_conf.border then
win_conf.border[8] = ''
win_conf.border[7] = ''
end

if opt.title then
win_conf.title = opt.title
Expand Down

0 comments on commit 38afc03

Please sign in to comment.