diff --git a/lua/fzfx/cfg/_lsp_locations.lua b/lua/fzfx/cfg/_lsp_locations.lua index 96f2c814b..45e43c593 100644 --- a/lua/fzfx/cfg/_lsp_locations.lua +++ b/lua/fzfx/cfg/_lsp_locations.lua @@ -3,6 +3,7 @@ local path = require("fzfx.commons.path") local fileio = require("fzfx.commons.fileio") local term_color = require("fzfx.commons.color.term") +local switches = require("fzfx.lib.switches") local log = require("fzfx.lib.log") local LogLevels = require("fzfx.lib.log").LogLevels @@ -521,9 +522,24 @@ M._lsp_position_context_maker = function() return context end +-- if you want to use fzf-builtin previewer with bat, please use below configs: +-- +-- previewer = previewers_helper.preview_files_grep +-- previewer_type = PreviewerTypeEnum.COMMAND_LIST + +-- if you want to use nvim buffer previewer, please use below configs: +-- +-- previewer = previewers_helper.buffer_preview_files_grep +-- previewer_type = PreviewerTypeEnum.BUFFER_FILE + +local previewer = switches.buffer_previewer_disabled() and previewers_helper.preview_files_grep + or previewers_helper.buffer_preview_files_grep +local previewer_type = switches.buffer_previewer_disabled() and PreviewerTypeEnum.COMMAND_LIST + or PreviewerTypeEnum.BUFFER_FILE + M.previewers = { - previewer = previewers_helper.preview_files_grep, - previewer_type = PreviewerTypeEnum.COMMAND_LIST, + previewer = previewer, + previewer_type = previewer_type, previewer_label = labels_helper.label_rg, } diff --git a/lua/fzfx/detail/popup/buffer_popup_window.lua b/lua/fzfx/detail/popup/buffer_popup_window.lua index 6f304b814..4468d7be6 100644 --- a/lua/fzfx/detail/popup/buffer_popup_window.lua +++ b/lua/fzfx/detail/popup/buffer_popup_window.lua @@ -10,19 +10,20 @@ local popup_helpers = require("fzfx.detail.popup.popup_helpers") local M = {} -local FLOAT_WIN_DEFAULT_ZINDEX = 60 -local FLOAT_WIN_DEFAULT_STYLE = "minimal" - --- @alias fzfx.BufferFilePreviewerOpts {fzf_preview_window_opts:fzfx.FzfPreviewWindowOpts,fzf_border_opts:string} --- @param win_opts fzfx.WindowOpts --- @param buffer_previewer_opts fzfx.BufferFilePreviewerOpts ---- @param relative_winnr integer? +--- @param relative_winnr integer --- @return {provider:fzfx.NvimFloatWinOpts,previewer:fzfx.NvimFloatWinOpts} M._make_cursor_opts = function(win_opts, buffer_previewer_opts, relative_winnr) + local opts = vim.deepcopy(win_opts) + local relative = "win" local layout = - popup_helpers.make_center_layout(win_opts, buffer_previewer_opts.fzf_preview_window_opts) - local relative = win_opts.relative - local border = fzf_helpers.FZF_BORDER_OPTS_MAP[buffer_previewer_opts.fzf_border_opts] + popup_helpers.make_cursor_layout(opts, buffer_previewer_opts.fzf_preview_window_opts) + log.debug("|_make_cursor_opts| layout:" .. vim.inspect(layout)) + local provider_border = fzf_helpers.FZF_BORDER_OPTS_MAP[buffer_previewer_opts.fzf_border_opts] + or fzf_helpers.FZF_DEFAULT_BORDER_OPTS + local previewer_border = fzf_helpers.FZF_BORDER_OPTS_MAP[buffer_previewer_opts.fzf_preview_window_opts.border] or fzf_helpers.FZF_DEFAULT_BORDER_OPTS local result = { @@ -32,9 +33,9 @@ M._make_cursor_opts = function(win_opts, buffer_previewer_opts, relative_winnr) height = layout.height, row = layout.start_row, col = layout.start_col, - style = FLOAT_WIN_DEFAULT_STYLE, - border = border, - zindex = FLOAT_WIN_DEFAULT_ZINDEX, + style = popup_helpers.FLOAT_WIN_STYLE, + border = provider_border, + zindex = popup_helpers.FLOAT_WIN_ZINDEX, } result.provider = { anchor = "NW", @@ -43,9 +44,9 @@ M._make_cursor_opts = function(win_opts, buffer_previewer_opts, relative_winnr) height = layout.provider.height, row = layout.provider.start_row, col = layout.provider.start_col, - style = FLOAT_WIN_DEFAULT_STYLE, - border = border, - zindex = FLOAT_WIN_DEFAULT_ZINDEX, + style = popup_helpers.FLOAT_WIN_STYLE, + border = provider_border, + zindex = popup_helpers.FLOAT_WIN_ZINDEX, } result.previewer = { anchor = "NW", @@ -54,65 +55,68 @@ M._make_cursor_opts = function(win_opts, buffer_previewer_opts, relative_winnr) height = layout.previewer.height, row = layout.previewer.start_row, col = layout.previewer.start_col, - style = FLOAT_WIN_DEFAULT_STYLE, - border = border, - zindex = FLOAT_WIN_DEFAULT_ZINDEX, + style = popup_helpers.FLOAT_WIN_STYLE, + border = previewer_border, + zindex = popup_helpers.FLOAT_WIN_ZINDEX, } - if relative ~= "editor" and type(relative_winnr) == "number" then + if relative == "win" then result.provider.win = relative_winnr result.previewer.win = relative_winnr end - -- log.debug("|make_opts| result:%s", vim.inspect(result)) + log.debug("|_make_cursor_opts| result:" .. vim.inspect(result)) return result end --- @param win_opts fzfx.WindowOpts --- @param buffer_previewer_opts fzfx.BufferFilePreviewerOpts ---- @param relative_winnr integer? +--- @param relative_winnr integer --- @return {provider:fzfx.NvimFloatWinOpts,previewer:fzfx.NvimFloatWinOpts} M._make_center_opts = function(win_opts, buffer_previewer_opts, relative_winnr) + local opts = vim.deepcopy(win_opts) + opts.relative = opts.relative or "editor" local layout = - popup_helpers.make_center_layout(win_opts, buffer_previewer_opts.fzf_preview_window_opts) - local relative = win_opts.relative - local border = fzf_helpers.FZF_BORDER_OPTS_MAP[buffer_previewer_opts.fzf_border_opts] + popup_helpers.make_center_layout(opts, buffer_previewer_opts.fzf_preview_window_opts) + local provider_border = fzf_helpers.FZF_BORDER_OPTS_MAP[buffer_previewer_opts.fzf_border_opts] + or fzf_helpers.FZF_DEFAULT_BORDER_OPTS + local previewer_border = fzf_helpers.FZF_BORDER_OPTS_MAP[buffer_previewer_opts.fzf_preview_window_opts.border] or fzf_helpers.FZF_DEFAULT_BORDER_OPTS local result = { anchor = "NW", - relative = relative, + relative = opts.relative, width = layout.width, height = layout.height, row = layout.start_row, col = layout.start_col, - style = FLOAT_WIN_DEFAULT_STYLE, - border = border, - zindex = FLOAT_WIN_DEFAULT_ZINDEX, + style = popup_helpers.FLOAT_WIN_STYLE, + border = provider_border, + zindex = popup_helpers.FLOAT_WIN_ZINDEX, } result.provider = { anchor = "NW", - relative = relative, + relative = opts.relative, width = layout.provider.width, height = layout.provider.height, row = layout.provider.start_row, col = layout.provider.start_col, - style = FLOAT_WIN_DEFAULT_STYLE, - border = border, - zindex = FLOAT_WIN_DEFAULT_ZINDEX, + style = popup_helpers.FLOAT_WIN_STYLE, + border = provider_border, + zindex = popup_helpers.FLOAT_WIN_ZINDEX, } result.previewer = { anchor = "NW", - relative = relative, + relative = opts.relative, width = layout.previewer.width, height = layout.previewer.height, row = layout.previewer.start_row, col = layout.previewer.start_col, - style = FLOAT_WIN_DEFAULT_STYLE, - border = border, - zindex = FLOAT_WIN_DEFAULT_ZINDEX, + style = popup_helpers.FLOAT_WIN_STYLE, + border = previewer_border, + zindex = popup_helpers.FLOAT_WIN_ZINDEX, } - if relative ~= "editor" and type(relative_winnr) == "number" then + if opts.relative == "win" then result.provider.win = relative_winnr result.previewer.win = relative_winnr end @@ -122,7 +126,7 @@ end --- @param win_opts fzfx.WindowOpts --- @param buffer_previewer_opts fzfx.BufferFilePreviewerOpts ---- @param relative_winnr integer? +--- @param relative_winnr integer --- @return {provider:fzfx.NvimFloatWinOpts,previewer:fzfx.NvimFloatWinOpts} M.make_opts = function(win_opts, buffer_previewer_opts, relative_winnr) local opts = vim.deepcopy(win_opts) @@ -571,15 +575,15 @@ function BufferPopupWindow:preview_file(job_id, previewer_result, previewer_labe local win_height = vim.api.nvim_win_get_height(self.previewer_winnr) local view = center_line and M._make_view_by_center(lines_count, win_height, center_line) or M._make_view_by_top(lines_count, win_height) - log.debug( - string.format( - "|BufferPopupWindow:preview_file| lineno:%s, lines_count:%s, win_height:%s, view:%s", - vim.inspect(center_line), - vim.inspect(lines_count), - vim.inspect(win_height), - vim.inspect(view) - ) - ) + -- log.debug( + -- string.format( + -- "|BufferPopupWindow:preview_file| lineno:%s, lines_count:%s, win_height:%s, view:%s", + -- vim.inspect(center_line), + -- vim.inspect(lines_count), + -- vim.inspect(win_height), + -- vim.inspect(view) + -- ) + -- ) self:preview_file_contents(last_content, view) end, 10) end) @@ -710,15 +714,15 @@ function BufferPopupWindow:render_file_contents(file_content, content_view, on_c if line_step == nil then line_step = LARGE_FILE and math.max(math.ceil(math.sqrt(LINES_COUNT)), 5) or 5 end - log.debug( - string.format( - "|BufferPopupWindow:render_file_contents| LINES_COUNT:%s, FIRST/LAST:%s/%s, view:%s", - vim.inspect(LINES_COUNT), - vim.inspect(FIRST_LINE), - vim.inspect(LAST_LINE), - vim.inspect(content_view) - ) - ) + -- log.debug( + -- string.format( + -- "|BufferPopupWindow:render_file_contents| LINES_COUNT:%s, FIRST/LAST:%s/%s, view:%s", + -- vim.inspect(LINES_COUNT), + -- vim.inspect(FIRST_LINE), + -- vim.inspect(LAST_LINE), + -- vim.inspect(content_view) + -- ) + -- ) local function set_buf_lines() vim.defer_fn(function() @@ -1020,20 +1024,20 @@ function BufferPopupWindow:scroll_by(percent, up) -- vim.inspect(last_line) -- ) local view = M._make_view_by_range(LINES_COUNT, WIN_HEIGHT, first_line, last_line, HIGHLIGHT_LINE) - log.debug( - string.format( - "|BufferPopupWindow:scroll_by|-2 percent:%s, up:%s, LINES/HEIGHT/SHIFT:%s/%s/%s, top/bottom/center:%s/%s/%s, view:%s", - vim.inspect(percent), - vim.inspect(up), - vim.inspect(LINES_COUNT), - vim.inspect(WIN_HEIGHT), - vim.inspect(shift_lines), - vim.inspect(TOP_LINE), - vim.inspect(BOTTOM_LINE), - vim.inspect(CENTER_LINE), - vim.inspect(view) - ) - ) + -- log.debug( + -- string.format( + -- "|BufferPopupWindow:scroll_by|-2 percent:%s, up:%s, LINES/HEIGHT/SHIFT:%s/%s/%s, top/bottom/center:%s/%s/%s, view:%s", + -- vim.inspect(percent), + -- vim.inspect(up), + -- vim.inspect(LINES_COUNT), + -- vim.inspect(WIN_HEIGHT), + -- vim.inspect(shift_lines), + -- vim.inspect(TOP_LINE), + -- vim.inspect(BOTTOM_LINE), + -- vim.inspect(CENTER_LINE), + -- vim.inspect(view) + -- ) + -- ) if TOP_LINE == view.top and BOTTOM_LINE == view.bottom then -- log.debug("|BufferPopupWindow:scroll_by| no change") diff --git a/lua/fzfx/detail/popup/fzf_popup_window.lua b/lua/fzfx/detail/popup/fzf_popup_window.lua index 11974fa7f..fc15e57ef 100644 --- a/lua/fzfx/detail/popup/fzf_popup_window.lua +++ b/lua/fzfx/detail/popup/fzf_popup_window.lua @@ -6,60 +6,76 @@ local popup_helpers = require("fzfx.detail.popup.popup_helpers") local M = {} local FLOAT_WIN_DEFAULT_BORDER = "none" -local FLOAT_WIN_DEFAULT_ZINDEX = 60 --- @param win_opts fzfx.WindowOpts +--- @param relative_winnr integer --- @return fzfx.NvimFloatWinOpts -M._make_cursor_opts = function(win_opts) +M._make_cursor_opts = function(win_opts, relative_winnr) local opts = vim.deepcopy(win_opts) - opts.relative = opts.relative or "cursor" + opts.relative = opts.relative or "win" local layout = popup_helpers.make_cursor_layout(opts) log.debug("|_make_cursor_opts| layout:" .. vim.inspect(layout)) - return { + local result = { anchor = "NW", relative = opts.relative, width = layout.width, height = layout.height, - row = opts.row, - col = opts.col, - style = "minimal", + row = layout.start_row, + col = layout.start_col, + style = popup_helpers.FLOAT_WIN_STYLE, border = FLOAT_WIN_DEFAULT_BORDER, - zindex = FLOAT_WIN_DEFAULT_ZINDEX, + zindex = popup_helpers.FLOAT_WIN_ZINDEX, } + + if opts.relative == "win" then + result.win = relative_winnr + end + + log.debug("|_make_cursor_opts| result:" .. vim.inspect(result)) + return result end --- @param win_opts fzfx.WindowOpts +--- @param relative_winnr integer --- @return fzfx.NvimFloatWinOpts -M._make_center_opts = function(win_opts) +M._make_center_opts = function(win_opts, relative_winnr) local opts = vim.deepcopy(win_opts) opts.relative = opts.relative or "editor" local layout = popup_helpers.make_center_layout(opts) log.debug("|_make_center_opts| layout:%s" .. vim.inspect(layout)) - return { + local result = { anchor = "NW", relative = opts.relative, width = layout.width, height = layout.height, row = layout.start_row, col = layout.start_col, - style = "minimal", + style = popup_helpers.FLOAT_WIN_STYLE, border = FLOAT_WIN_DEFAULT_BORDER, - zindex = FLOAT_WIN_DEFAULT_ZINDEX, + zindex = popup_helpers.FLOAT_WIN_ZINDEX, } + + if opts.relative == "win" then + result.win = relative_winnr + end + + return result end --- @param win_opts fzfx.WindowOpts +--- @param relative_winnr integer --- @return fzfx.NvimFloatWinOpts -M.make_opts = function(win_opts) +M.make_opts = function(win_opts, relative_winnr) local opts = vim.deepcopy(win_opts) opts.relative = opts.relative or "editor" log.ensure( opts.relative == "cursor" or opts.relative == "editor" or opts.relative == "win", - string.format("window relative (%s) must be editor/win/cursor", vim.inspect(opts)) + string.format("popup window relative (%s) must be editor/win/cursor", vim.inspect(opts)) ) - return opts.relative == "cursor" and M._make_cursor_opts(opts) or M._make_center_opts(opts) + return opts.relative == "cursor" and M._make_cursor_opts(opts, relative_winnr) + or M._make_center_opts(opts, relative_winnr) end -- FzfPopupWindow { @@ -68,6 +84,7 @@ end --- @field window_opts_context fzfx.WindowOptsContext? --- @field bufnr integer? --- @field winnr integer? +--- @field _saved_current_winnr integer --- @field _saved_win_opts fzfx.WindowOpts --- @field _resizing boolean local FzfPopupWindow = {} @@ -76,6 +93,8 @@ local FzfPopupWindow = {} --- @param win_opts fzfx.WindowOpts --- @return fzfx.FzfPopupWindow function FzfPopupWindow:new(win_opts) + local current_winnr = vim.api.nvim_get_current_win() + -- save current window context local window_opts_context = popup_helpers.WindowOptsContext:save() @@ -87,7 +106,7 @@ function FzfPopupWindow:new(win_opts) api.set_buf_option(bufnr, "buflisted", false) api.set_buf_option(bufnr, "filetype", "fzf") - local nvim_float_win_opts = M.make_opts(win_opts) + local nvim_float_win_opts = M.make_opts(win_opts, current_winnr) local winnr = vim.api.nvim_open_win(bufnr, true, nvim_float_win_opts) --- setlocal nospell nonumber @@ -103,6 +122,7 @@ function FzfPopupWindow:new(win_opts) window_opts_context = window_opts_context, bufnr = bufnr, winnr = winnr, + _saved_current_winnr = current_winnr, _saved_win_opts = win_opts, _resizing = false, } @@ -143,7 +163,7 @@ function FzfPopupWindow:resize() end self._resizing = true - local nvim_float_win_opts = M.make_opts(self._saved_win_opts) + local nvim_float_win_opts = M.make_opts(self._saved_win_opts, self._saved_current_winnr) vim.api.nvim_win_set_config(self.winnr, nvim_float_win_opts) vim.schedule(function() self._resizing = false diff --git a/lua/fzfx/detail/popup/popup_helpers.lua b/lua/fzfx/detail/popup/popup_helpers.lua index b751ddef8..369eb0c64 100644 --- a/lua/fzfx/detail/popup/popup_helpers.lua +++ b/lua/fzfx/detail/popup/popup_helpers.lua @@ -106,6 +106,63 @@ M.ShellOptsContext = ShellOptsContext -- ShellOptsContext } +-- layout { + +--- @param total_height integer +--- @param total_width integer +--- @param layout {start_row:integer,end_row:integer,start_col:integer,end_col:integer} +--- @return {start_row:integer,end_row:integer,start_col:integer,end_col:integer} +M._adjust_layout_bound = function(total_height, total_width, layout) + --- @param v number + --- @return number + local function bound_row(v) + return num.bound(v, 0, total_height - 1) + end + + --- @param v number + --- @return number + local function bound_col(v) + return num.bound(v, 0, total_width - 1) + end + + local start_row = layout.start_row + local end_row = layout.end_row + local start_col = layout.start_col + local end_col = layout.end_col + + if start_row <= 0 then + -- too up + local diff_row = math.floor(math.abs(start_row)) + start_row = 0 + end_row = end_row + diff_row + elseif end_row >= total_height - 1 then + -- too down + local diff_row = math.floor(math.abs(end_row - total_height + 1)) + end_row = total_height - 1 + start_row = start_row - diff_row + end + + start_row = bound_row(start_row) + end_row = bound_row(end_row) + + if start_col <= 0 then + -- too left + local diff_col = math.floor(math.abs(start_col)) + start_col = 0 + end_col = end_col + diff_col + elseif end_col >= total_width - 1 then + -- too right + local diff_col = math.floor(math.abs(end_col - total_width + 1)) + end_col = total_width - 1 + start_col = start_col - diff_col + end + + start_col = bound_col(start_col) + end_col = bound_col(end_col) + + return { start_row = start_row, end_row = end_row, start_col = start_col, end_col = end_col } +end + --- @param win_opts {relative:"editor"|"win"|"cursor",height:number,width:number,row:number,col:number} --- @param fzf_preview_window_opts fzfx.FzfPreviewWindowOpts? --- @return {height:integer,width:integer,start_row:integer,end_row:integer,start_col:integer,end_col:integer,provider:{height:integer,width:integer,start_row:integer,end_row:integer,start_col:integer,end_col:integer}?,previewer:{height:integer,width:integer,start_row:integer,end_row:integer,start_col:integer,end_col:integer}?} @@ -170,22 +227,21 @@ M.make_center_layout = function(win_opts, fzf_preview_window_opts) -- vim.inspect(center_col + (width / 2)) -- ) - --- @param v number - --- @return number - local function bound_row(v) - return num.bound(v, 0, total_height - 1) - end + local start_row = math.floor(center_row - (height / 2)) + local end_row = math.floor(center_row + (height / 2)) + local start_col = math.floor(center_col - (width / 2)) + local end_col = math.floor(center_col + (width / 2)) - --- @param v number - --- @return number - local function bound_col(v) - return num.bound(v, 0, total_width - 1) - end + local adjust_layout = M._adjust_layout_bound( + total_height, + total_width, + { start_row = start_row, end_row = end_row, start_col = start_col, end_col = end_col } + ) - local start_row = bound_row(math.floor(center_row - (height / 2))) - local end_row = bound_row(math.floor(center_row + (height / 2))) - local start_col = bound_col(math.floor(center_col - (width / 2))) - local end_col = bound_col(math.floor(center_col + (width / 2))) + start_row = adjust_layout.start_row + end_row = adjust_layout.end_row + start_col = adjust_layout.start_col + end_col = adjust_layout.end_col local result = { total_height = total_height, @@ -197,8 +253,8 @@ M.make_center_layout = function(win_opts, fzf_preview_window_opts) start_col = start_col, end_col = end_col, } - -- log.debug("|get_layout| result-1:%s", vim.inspect(result)) + log.debug(string.format("|make_center_layout| base_layout:%s", vim.inspect(result))) local internal_layout = M._make_internal_layout(result, fzf_preview_window_opts) result.provider = tbl.tbl_get(internal_layout, "provider") result.previewer = tbl.tbl_get(internal_layout, "previewer") @@ -212,6 +268,21 @@ end M.make_cursor_layout = function(win_opts, fzf_preview_window_opts) local total_width = vim.api.nvim_win_get_width(0) local total_height = vim.api.nvim_win_get_height(0) + local cursor_pos = vim.api.nvim_win_get_cursor(0) + local win_first_line = vim.fn.line("w0") + local cursor_relative_row = cursor_pos[1] - win_first_line + local cursor_relative_col = cursor_pos[2] + log.debug( + string.format( + "|make_cursor_layout| total height/width:%s/%s, cursor:%s, win first line:%s, cursor relative row/col:%s/%s", + vim.inspect(total_height), + vim.inspect(total_width), + vim.inspect(cursor_pos), + vim.inspect(win_first_line), + vim.inspect(cursor_relative_row), + vim.inspect(cursor_relative_col) + ) + ) local width = num.bound( win_opts.width > 1 and win_opts.width or math.floor(win_opts.width * total_width), @@ -224,37 +295,33 @@ M.make_cursor_layout = function(win_opts, fzf_preview_window_opts) total_height ) - log.ensure( - (win_opts.row >= -0.5 and win_opts.row <= 0.5) or win_opts.row <= -1 or win_opts.row >= 1, - string.format( - "popup window row (%s) opts must in range [-0.5, 0.5] or (-inf, -1] or [1, +inf]", - vim.inspect(win_opts.row) - ) - ) - log.ensure( - (win_opts.col >= -0.5 and win_opts.col <= 0.5) or win_opts.col <= -1 or win_opts.col >= 1, - string.format( - "popup window col (%s) opts must in range [-0.5, 0.5] or (-inf, -1] or [1, +inf]", - vim.inspect(win_opts.col) - ) - ) + local start_row + local start_col - --- @param v number - --- @return number - local function bound_row(v) - return num.bound(v, 0, total_height - 1) + if win_opts.row > -1 and win_opts.row < 1 then + start_row = math.floor(total_height * win_opts.row) + cursor_relative_row + else + start_row = win_opts.row + cursor_relative_row end + local end_row = start_row + height - --- @param v number - --- @return number - local function bound_col(v) - return num.bound(v, 0, total_width - 1) + if win_opts.col > -1 and win_opts.col < 1 then + start_col = math.floor(total_width * win_opts.col) + cursor_relative_col + else + start_col = win_opts.col + cursor_relative_col end + local end_col = start_col + width + + local adjust_layout = M._adjust_layout_bound( + total_height, + total_width, + { start_row = start_row, end_row = end_row, start_col = start_col, end_col = end_col } + ) - local start_row = bound_row(win_opts.row) - local end_row = bound_row(start_row + height) - local start_col = bound_col(win_opts.col) - local end_col = bound_col(start_col + width) + start_row = adjust_layout.start_row + end_row = adjust_layout.end_row + start_col = adjust_layout.start_col + end_col = adjust_layout.end_col local result = { total_height = total_height, @@ -267,6 +334,7 @@ M.make_cursor_layout = function(win_opts, fzf_preview_window_opts) end_col = end_col, } + log.debug(string.format("|make_cursor_layout| base_layout:%s", vim.inspect(result))) local internal_layout = M._make_internal_layout(result, fzf_preview_window_opts) result.provider = tbl.tbl_get(internal_layout, "provider") result.previewer = tbl.tbl_get(internal_layout, "previewer") @@ -326,12 +394,17 @@ M._make_internal_layout = function(base_layout, fzf_preview_window_opts) -- | | | if fzf_preview_window_opts.position == "left" then + -- | | | + -- | previewer | provider | + -- | | | previewer_layout.start_col = base_layout.start_col previewer_layout.end_col = bound_col(base_layout.start_col + previewer_layout.width) provider_layout.start_col = bound_col(base_layout.end_col - provider_layout.width) provider_layout.end_col = base_layout.end_col else + -- | | | -- | provider | previewer | + -- | | | provider_layout.start_col = base_layout.start_col provider_layout.end_col = bound_col(base_layout.start_col + provider_layout.width) previewer_layout.start_col = bound_col(base_layout.end_col - previewer_layout.width) @@ -364,11 +437,21 @@ M._make_internal_layout = function(base_layout, fzf_preview_window_opts) -- --------- if fzf_preview_window_opts.position == "up" then + -- ------------- + -- previewer + -- ------------- + -- provider + -- ------------- previewer_layout.start_row = base_layout.start_row previewer_layout.end_row = bound_row(base_layout.start_row + previewer_layout.height) provider_layout.start_row = bound_row(base_layout.end_row - provider_layout.height) provider_layout.end_row = base_layout.end_row else + -- ------------- + -- provider + -- ------------- + -- previewer + -- ------------- provider_layout.start_row = base_layout.start_row provider_layout.end_row = bound_row(base_layout.start_row + provider_layout.height) previewer_layout.start_row = bound_row(base_layout.end_row - previewer_layout.height) @@ -386,4 +469,13 @@ M._make_internal_layout = function(base_layout, fzf_preview_window_opts) return nil end +-- layout } + +-- constants { + +M.FLOAT_WIN_STYLE = "minimal" +M.FLOAT_WIN_ZINDEX = 60 + +-- constants } + return M diff --git a/spec/detail/popup/fzf_popup_window_spec.lua b/spec/detail/popup/fzf_popup_window_spec.lua index feb52e873..eadc6e1a2 100644 --- a/spec/detail/popup/fzf_popup_window_spec.lua +++ b/spec/detail/popup/fzf_popup_window_spec.lua @@ -31,7 +31,8 @@ describe("detail.popup.fzf_popup_window", function() describe("[_make_cursor_opts]", function() it("test", function() local actual = fzf_popup_window._make_cursor_opts( - vim.tbl_deep_extend("force", vim.deepcopy(WIN_OPTS), { relative = "cursor" }) + vim.tbl_deep_extend("force", vim.deepcopy(WIN_OPTS), { relative = "cursor" }), + 0 ) print(string.format("fzf_popup_window._make_cursor_opts:%s\n", vim.inspect(actual))) local win_width = vim.api.nvim_win_get_width(0) @@ -44,15 +45,14 @@ describe("detail.popup.fzf_popup_window", function() assert_eq(type(actual.width), "number") assert_true(num.eq(actual.width, expect_width, 0.1, 0.1)) assert_eq(type(actual.row), "number") - assert_eq(actual.row, 0) assert_eq(type(actual.col), "number") - assert_eq(actual.col, 0) end) end) describe("[_make_center_opts]", function() it("test", function() local actual = fzf_popup_window._make_center_opts( - vim.tbl_deep_extend("force", vim.deepcopy(WIN_OPTS), { relative = "win" }) + vim.tbl_deep_extend("force", vim.deepcopy(WIN_OPTS), { relative = "win" }), + 0 ) print(string.format("fzf_popup_window._make_center_opts:%s\n", vim.inspect(actual))) local total_width = vim.api.nvim_win_get_width(0) @@ -87,8 +87,8 @@ describe("detail.popup.fzf_popup_window", function() end) describe("[make_opts]", function() it("test", function() - local actual1 = fzf_popup_window.make_opts(WIN_OPTS) - local actual2 = fzf_popup_window._make_center_opts(WIN_OPTS) + local actual1 = fzf_popup_window.make_opts(WIN_OPTS, 0) + local actual2 = fzf_popup_window._make_center_opts(WIN_OPTS, 0) print( string.format( "fzf_popup_window.make_opts:%s, _make_center_opts:%s\n",