diff --git a/lua/fzfx/detail/general.lua b/lua/fzfx/detail/general.lua index 903f0b165..282168a44 100644 --- a/lua/fzfx/detail/general.lua +++ b/lua/fzfx/detail/general.lua @@ -1063,11 +1063,13 @@ local function general(name, query, bang, pipeline_configs, default_pipeline) {}, function(actions_fsevent_start_complete_err, actions_file, events) -- log.debug( - -- "|general - buffer_previewer_actions_fsevent:start| complete actions fsevent, actions_file:%s, events:%s, actions_file:%s, error:%s", - -- vim.inspect(actions_file), - -- vim.inspect(events), - -- vim.inspect(buffer_previewer_actions_file), - -- vim.inspect(actions_fsevent_start_complete_err) + -- string.format( + -- "|general - buffer_previewer_actions_fsevent:start| complete actions fsevent, actions_file:%s, events:%s, buffer_previewer_actions_file:%s, actions_fsevent_start_complete_err:%s", + -- vim.inspect(actions_file), + -- vim.inspect(events), + -- vim.inspect(buffer_previewer_actions_file), + -- vim.inspect(actions_fsevent_start_complete_err) + -- ) -- ) if actions_fsevent_start_complete_err then log.err( @@ -1082,15 +1084,17 @@ local function general(name, query, bang, pipeline_configs, default_pipeline) if not str.find(buffer_previewer_actions_file, actions_file) then return end - if not popup or not popup:previewer_is_valid() then + if not popup or not popup:provider_is_valid() then return end fileio.asyncreadfile(buffer_previewer_actions_file, function(actions_data) -- log.debug( - -- "|general - buffer_previewer_actions_fsevent:start| complete read actions_file:%s, data:%s", - -- vim.inspect(actions_file), - -- vim.inspect(actions_data) + -- string.format( + -- "|general - buffer_previewer_actions_fsevent:start| complete read actions_file:%s, actions_data:%s", + -- vim.inspect(actions_file), + -- vim.inspect(actions_data) + -- ) -- ) if not popup or not popup:provider_is_valid() then return @@ -1128,7 +1132,7 @@ local function general(name, query, bang, pipeline_configs, default_pipeline) local QUERY_FZF_CURRENT_STATUS_INTERVAL = 150 buffer_previewer_query_fzf_status_start = true - local buffer_previewer_fzf_current_text = nil + local buffer_previewer_focused_line = nil local buffer_previewer_file_job_id = num.auto_incremental_id() if popup and popup.popup_window then popup.popup_window:set_current_previewing_file_job_id(buffer_previewer_file_job_id) @@ -1154,9 +1158,10 @@ local function general(name, query, bang, pipeline_configs, default_pipeline) text = true, }, function(completed) -- log.debug( - -- "|general - use_buffer_previewer - query_fzf_status| completed:%s, payload:%s", - -- vim.inspect(completed), - -- vim.inspect(current_payload) + -- string.format( + -- "|general - use_buffer_previewer - query_fzf_status| completed:%s", + -- vim.inspect(completed) + -- ) -- ) if buffer_previewer_query_fzf_status_start then @@ -1167,50 +1172,51 @@ local function general(name, query, bang, pipeline_configs, default_pipeline) if str.not_empty(tbl.tbl_get(completed, "stdout")) then local parse_ok, parse_status = pcall(json.decode, completed.stdout) --[[@as boolean, table]] if parse_ok and str.not_empty(tbl.tbl_get(parse_status, "current", "text")) then - local current_text = parse_status["current"]["text"] + local focused_line = parse_status["current"]["text"] - if current_text == buffer_previewer_fzf_current_text then + if focused_line == buffer_previewer_focused_line then return end - buffer_previewer_fzf_current_text = current_text + buffer_previewer_focused_line = focused_line - -- trigger buffer previewer { - - if not popup or not popup:previewer_is_valid() then + if not popup or not popup:provider_is_valid() then return end + -- trigger buffer previewer { + buffer_previewer_file_job_id = num.auto_incremental_id() popup.popup_window:set_current_previewing_file_job_id(buffer_previewer_file_job_id) local previewer_config = previewer_switch:current() - local focused_line = current_text - local previewer_ok, previewer_result = + local preview_ok, preview_result = pcall(previewer_config.previewer, focused_line, context) -- log.debug( - -- "|fzfx.general - PreviewerSwitch:preview| pcall command previewer, ok:%s, result:%s", - -- vim.inspect(ok), - -- vim.inspect(result) + -- string.format( + -- "|fzfx.general - use_buffer_previewer - query_fzf_status| pcall previewer, preview_ok:%s, preview_result:%s", + -- vim.inspect(preview_ok), + -- vim.inspect(preview_result) + -- ) -- ) - if not previewer_ok then + if not preview_ok then log.err( string.format( "failed to call buffer previewer %s! line:%s, context:%s, error:%s", vim.inspect(previewer_config.previewer), vim.inspect(focused_line), vim.inspect(context), - vim.inspect(previewer_result) + vim.inspect(preview_result) ) ) else log.ensure( - previewer_result == nil or type(previewer_result) == "table", + preview_result == nil or type(preview_result) == "table", string.format( - "|general - use_buffer_previewer - asyncreadfile| buffer previewer result must be table! previewer_config:%s, result:%s", + "|general - use_buffer_previewer - query_fzf_status| buffer previewer result must be table! previewer_config:%s, result:%s", vim.inspect(previewer_config), - vim.inspect(previewer_result) + vim.inspect(preview_result) ) ) local previewer_label_ok @@ -1237,10 +1243,10 @@ local function general(name, query, bang, pipeline_configs, default_pipeline) previewer_label_result = nil end end - if previewer_result then + if preview_result then popup.popup_window:preview_file( buffer_previewer_file_job_id, - previewer_result --[[@as fzfx.BufferFilePreviewerResult]], + preview_result --[[@as fzfx.BufferFilePreviewerResult]], previewer_label_result --[[@as string?]] ) end diff --git a/lua/fzfx/detail/popup.lua b/lua/fzfx/detail/popup.lua index 7ac83bcde..8fbc533ee 100644 --- a/lua/fzfx/detail/popup.lua +++ b/lua/fzfx/detail/popup.lua @@ -170,10 +170,12 @@ function Popup:new( local function on_fzf_exit(jobid2, exitcode, event) -- log.debug( - -- "|Popup:new| fzf exit, jobid2:%s, exitcode:%s, event:%s", - -- vim.inspect(jobid2), - -- vim.inspect(exitcode), - -- vim.inspect(event) + -- string.format( + -- "|Popup:new - on_fzf_exit| jobid2:%s, exitcode:%s, event:%s", + -- vim.inspect(jobid2), + -- vim.inspect(exitcode), + -- vim.inspect(event) + -- ) -- ) if exitcode > 1 and (exitcode ~= 130 and exitcode ~= 129) then log.err( @@ -205,9 +207,11 @@ function Popup:new( ) local lines = fileio.readlines(result --[[@as string]]) --[[@as table]] -- log.debug( - -- "|Popup:new| fzf exit, result:%s, lines:%s", - -- vim.inspect(result), - -- vim.inspect(lines) + -- string.format( + -- "|Popup:new - on_fzf_exit| result:%s, lines:%s", + -- vim.inspect(result), + -- vim.inspect(lines) + -- ) -- ) if (exitcode == 130 or exitcode == 129) and #lines == 0 then return diff --git a/lua/fzfx/detail/popup/buffer_popup_window.lua b/lua/fzfx/detail/popup/buffer_popup_window.lua index 854cdc8e8..a2bf4b23a 100644 --- a/lua/fzfx/detail/popup/buffer_popup_window.lua +++ b/lua/fzfx/detail/popup/buffer_popup_window.lua @@ -10,6 +10,101 @@ local popup_helpers = require("fzfx.detail.popup.popup_helpers") local M = {} +-- calculate bottom line from top line +--- @param top_line integer top line +--- @param content_lines integer content lines count +--- @param view_height integer window/view height +M._calculate_bottom_by_top = function(top_line, content_lines, view_height) + return num.bound(top_line + view_height - 1, 1, content_lines) +end + +-- calculate top line from bottom line +--- @param bottom_line integer bottom line +--- @param content_lines integer content lines count +--- @param view_height integer window/view height +M._calculate_top_by_bottom = function(bottom_line, content_lines, view_height) + return num.bound(bottom_line - view_height + 1, 1, content_lines) +end + +-- adjust top/bottom line based on content lines count and view height +--- @param top integer top line +--- @param bottom integer bottom line +--- @param content_lines integer content lines count +--- @param view_height integer window/view height +--- @return integer, integer top line and bottom line +M._adjust_top_and_bottom = function(top, bottom, content_lines, view_height) + if top <= 1 then + -- log.debug( + -- "|_adjust_view|-1 top(%s) <= 1, bottom:%s, lines_count:%s, win_height:%s", + -- vim.inspect(top), + -- vim.inspect(bottom), + -- vim.inspect(lines_count), + -- vim.inspect(win_height) + -- ) + bottom = M._calculate_bottom_by_top(top, content_lines, view_height) + -- log.debug( + -- "|_adjust_view|-2 top(%s) <= 1, bottom:%s, lines_count:%s, win_height:%s", + -- vim.inspect(top), + -- vim.inspect(bottom), + -- vim.inspect(lines_count), + -- vim.inspect(win_height) + -- ) + elseif bottom >= content_lines then + -- log.debug( + -- "|_adjust_view|-3 bottom(%s) >= lines_count(%s), top:%s, win_height:%s", + -- vim.inspect(bottom), + -- vim.inspect(lines_count), + -- vim.inspect(top), + -- vim.inspect(win_height) + -- ) + top = M._calculate_top_by_bottom(bottom, content_lines, view_height) + -- log.debug( + -- "|_adjust_view|-4 bottom(%s) >= lines_count(%s), top:%s, win_height:%s", + -- vim.inspect(bottom), + -- vim.inspect(lines_count), + -- vim.inspect(top), + -- vim.inspect(win_height) + -- ) + end + return top, bottom +end + +-- make a view that start from the 1st line of the content +--- @alias fzfx.BufferPopupWindowPreviewFileContentView {top:integer,bottom:integer,center:integer,highlight:integer?} +--- @param content_lines integer +--- @param win_height integer +--- @return fzfx.BufferPopupWindowPreviewFileContentView +M._make_top_view = function(content_lines, win_height) + local top = 1 + local bottom = M._calculate_bottom_by_top(top, content_lines, win_height) + top, bottom = M._adjust_top_and_bottom(top, bottom, content_lines, win_height) + return { top = top, bottom = bottom, center = math.ceil((top + bottom) / 2), highlight = nil } +end + +-- make a view that the focused line is in the middle/center, and it's also the highlighted line. +--- @param content_lines integer +--- @param win_height integer +--- @param center_line integer +--- @return fzfx.BufferPopupWindowPreviewFileContentView +M._make_center_view = function(content_lines, win_height, center_line) + local top = num.bound(center_line - math.ceil(win_height / 2), 1, content_lines) + local bottom = M._calculate_bottom_by_top(top, content_lines, win_height) + top, bottom = M._adjust_top_and_bottom(top, bottom, content_lines, win_height) + return { top = top, bottom = bottom, center = center_line, highlight = center_line } +end + +-- make a view that already know the top/bottom/highlighted line, but needs to be adjusted. +--- @param content_lines integer +--- @param win_height integer +--- @param top_line integer +--- @param bottom_line integer +--- @param highlight_line integer? +M._make_range_view = function(content_lines, win_height, top_line, bottom_line, highlight_line) + top_line, bottom_line = M._adjust_top_and_bottom(top_line, bottom_line, content_lines, win_height) + local center_line = math.ceil((top_line + bottom_line) / 2) + return { top = top_line, bottom = bottom_line, center = center_line, highlight = highlight_line } +end + --- @alias fzfx.BufferFilePreviewerOpts {fzf_preview_window_opts:fzfx.FzfPreviewWindowOpts,fzf_border_opts:string} --- @param win_opts fzfx.WindowOpts --- @param buffer_previewer_opts fzfx.BufferFilePreviewerOpts @@ -206,14 +301,25 @@ function BufferPopupWindow:new(win_opts, buffer_previewer_opts) _set_default_buf_options(provider_bufnr) --- @type integer - local previewer_bufnr = vim.api.nvim_create_buf(false, true) - log.ensure(previewer_bufnr > 0, "failed to create previewer buf") - _set_default_buf_options(previewer_bufnr) + local previewer_bufnr + if not buffer_previewer_opts.fzf_preview_window_opts.hidden then + previewer_bufnr = vim.api.nvim_create_buf(false, true) + log.ensure(previewer_bufnr > 0, "failed to create previewer buf") + _set_default_buf_options(previewer_bufnr) + end local win_confs = M.make_opts(win_opts, buffer_previewer_opts, current_winnr) - local provider_win_confs = win_confs.provider - local previewer_win_confs = win_confs.previewer - previewer_win_confs.focusable = false + local provider_win_confs + local previewer_win_confs + + if not buffer_previewer_opts.fzf_preview_window_opts.hidden then + provider_win_confs = win_confs.provider + previewer_win_confs = win_confs.previewer + else + provider_win_confs = vim.deepcopy(win_confs) + provider_win_confs.provider = nil + provider_win_confs.previewer = nil + end -- log.debug( -- "|BufferPopupWindow:new| win_opts:%s, buffer_previewer_opts:%s, win_confs:%s", @@ -221,10 +327,14 @@ function BufferPopupWindow:new(win_opts, buffer_previewer_opts) -- vim.inspect(buffer_previewer_opts), -- vim.inspect(win_confs) -- ) - local previewer_winnr = vim.api.nvim_open_win(previewer_bufnr, true, previewer_win_confs) - log.ensure(previewer_winnr > 0, "failed to create previewer win") - local wrap = buffer_previewer_opts.fzf_preview_window_opts.wrap - _set_default_previewer_win_options(previewer_winnr, wrap) + + local previewer_winnr + if previewer_bufnr then + previewer_winnr = vim.api.nvim_open_win(previewer_bufnr, true, previewer_win_confs) + log.ensure(previewer_winnr > 0, "failed to create previewer win") + local wrap = buffer_previewer_opts.fzf_preview_window_opts.wrap + _set_default_previewer_win_options(previewer_winnr, wrap) + end local provider_winnr = vim.api.nvim_open_win(provider_bufnr, true, provider_win_confs) log.ensure(provider_winnr > 0, "failed to create provider win") @@ -259,7 +369,7 @@ function BufferPopupWindow:new(win_opts, buffer_previewer_opts) _resizing = false, preview_files_queue = {}, preview_file_contents_queue = {}, - previewer_is_hidden = false, + previewer_is_hidden = buffer_previewer_opts.fzf_preview_window_opts.hidden, } setmetatable(o, self) self.__index = self @@ -268,13 +378,19 @@ function BufferPopupWindow:new(win_opts, buffer_previewer_opts) end function BufferPopupWindow:close() - -- log.debug("|fzfx.popup - Popup:close| self:%s", vim.inspect(self)) + -- log.debug( + -- string.format( + -- "|BufferPopupWindow:close| provider_winnr:%s, previewer_winnr:%s", + -- vim.inspect(self.provider_winnr), + -- vim.inspect(self.previewer_winnr) + -- ) + -- ) - if vim.api.nvim_win_is_valid(self.provider_winnr) then + if type(self.provider_winnr) == "number" and vim.api.nvim_win_is_valid(self.provider_winnr) then vim.api.nvim_win_close(self.provider_winnr, true) self.provider_winnr = nil end - if vim.api.nvim_win_is_valid(self.previewer_winnr) then + if type(self.previewer_winnr) == "number" and vim.api.nvim_win_is_valid(self.previewer_winnr) then vim.api.nvim_win_close(self.previewer_winnr, true) self.previewer_winnr = nil end @@ -395,92 +511,27 @@ function BufferPopupWindow:set_current_previewing_file_job_id(jobid) self._current_previewing_file_job_id = jobid end ---- @param top_line integer ---- @param lines_count integer ---- @param win_height integer -M._make_bottom_by_top = function(top_line, lines_count, win_height) - return num.bound(top_line + win_height - 1, 1, lines_count) -end - ---- @param bottom_line integer ---- @param lines_count integer ---- @param win_height integer -M._make_top_by_bottom = function(bottom_line, lines_count, win_height) - return num.bound(bottom_line - win_height + 1, 1, lines_count) -end - ---- @param top integer ---- @param bottom integer ---- @param lines_count integer ---- @param win_height integer ---- @return integer, integer -M._adjust_view = function(top, bottom, lines_count, win_height) - if top <= 1 then - -- log.debug( - -- "|_adjust_view|-1 top(%s) <= 1, bottom:%s, lines_count:%s, win_height:%s", - -- vim.inspect(top), - -- vim.inspect(bottom), - -- vim.inspect(lines_count), - -- vim.inspect(win_height) - -- ) - bottom = M._make_bottom_by_top(top, lines_count, win_height) - -- log.debug( - -- "|_adjust_view|-2 top(%s) <= 1, bottom:%s, lines_count:%s, win_height:%s", - -- vim.inspect(top), - -- vim.inspect(bottom), - -- vim.inspect(lines_count), - -- vim.inspect(win_height) - -- ) - elseif bottom >= lines_count then - -- log.debug( - -- "|_adjust_view|-3 bottom(%s) >= lines_count(%s), top:%s, win_height:%s", - -- vim.inspect(bottom), - -- vim.inspect(lines_count), - -- vim.inspect(top), - -- vim.inspect(win_height) - -- ) - top = M._make_top_by_bottom(bottom, lines_count, win_height) - -- log.debug( - -- "|_adjust_view|-4 bottom(%s) >= lines_count(%s), top:%s, win_height:%s", - -- vim.inspect(bottom), - -- vim.inspect(lines_count), - -- vim.inspect(top), - -- vim.inspect(win_height) - -- ) - end - return top, bottom -end - ---- @alias fzfx.BufferPopupWindowPreviewFileContentView {top:integer,bottom:integer,center:integer,highlight:integer?} ---- @param lines_count integer ---- @param win_height integer +-- make a view based on preview file content +--- @param preview_file_content fzfx.BufferPopupWindowPreviewFileContentJob --- @return fzfx.BufferPopupWindowPreviewFileContentView -M._make_view_by_top = function(lines_count, win_height) - local top = 1 - local bottom = M._make_bottom_by_top(top, lines_count, win_height) - top, bottom = M._adjust_view(top, bottom, lines_count, win_height) - return { top = top, bottom = bottom, center = math.ceil((top + bottom) / 2), highlight = nil } -end - ---- @param lines_count integer ---- @param win_height integer ---- @param center_line integer -M._make_view_by_center = function(lines_count, win_height, center_line) - local top = num.bound(center_line - math.ceil(win_height / 2), 1, lines_count) - local bottom = M._make_bottom_by_top(top, lines_count, win_height) - top, bottom = M._adjust_view(top, bottom, lines_count, win_height) - return { top = top, bottom = bottom, center = center_line, highlight = center_line } -end - ---- @param lines_count integer ---- @param win_height integer ---- @param top_line integer ---- @param bottom_line integer ---- @param highlight_line integer? -M._make_view_by_range = function(lines_count, win_height, top_line, bottom_line, highlight_line) - top_line, bottom_line = M._adjust_view(top_line, bottom_line, lines_count, win_height) - local center_line = math.ceil((top_line + bottom_line) / 2) - return { top = top_line, bottom = bottom_line, center = center_line, highlight = highlight_line } +function BufferPopupWindow:_make_view(preview_file_content) + log.ensure(preview_file_content ~= nil, "|_make_view| preview_file_content must not be nil") + log.ensure(self:previewer_is_valid(), "|_make_view| previewer must be valid") + local center_line = preview_file_content.previewer_result.lineno + local lines_count = #preview_file_content.contents + local win_height = vim.api.nvim_win_get_height(self.previewer_winnr) + local view = center_line and M._make_center_view(lines_count, win_height, center_line) + or M._make_top_view(lines_count, win_height) + -- log.debug( + -- string.format( + -- "|BufferPopupWindow:_make_view| center_line:%s, lines_count:%s, win_height:%s, view:%s", + -- vim.inspect(center_line), + -- vim.inspect(lines_count), + -- vim.inspect(win_height), + -- vim.inspect(view) + -- ) + -- ) + return view end --- @alias fzfx.BufferPopupWindowPreviewFileJob {job_id:integer,previewer_result:fzfx.BufferFilePreviewerResult,previewer_label_result:string?} @@ -497,9 +548,11 @@ function BufferPopupWindow:preview_file(job_id, previewer_result, previewer_labe end -- log.debug( - -- "|BufferPopupWindow:preview_file| previewer_result:%s, previewer_label_result:%s", - -- vim.inspect(previewer_result), - -- vim.inspect(previewer_label_result) + -- string.format( + -- "|BufferPopupWindow:preview_file| previewer_result:%s, previewer_label_result:%s", + -- vim.inspect(previewer_result), + -- vim.inspect(previewer_label_result) + -- ) -- ) table.insert(self.preview_files_queue, { job_id = job_id, @@ -508,10 +561,6 @@ function BufferPopupWindow:preview_file(job_id, previewer_result, previewer_labe }) vim.defer_fn(function() - if not self:previewer_is_valid() then - -- log.debug("|BufferPopupWindow:preview_file| invalid previewer:%s", vim.inspect(self)) - return - end if #self.preview_files_queue == 0 then -- log.debug( -- "|BufferPopupWindow:preview_file| empty preview files queue:%s", @@ -530,9 +579,6 @@ function BufferPopupWindow:preview_file(job_id, previewer_result, previewer_labe -- read file content fileio.asyncreadfile(last_job.previewer_result.filename, function(contents) - if not self:previewer_is_valid() then - return - end if not self:is_last_previewing_file_job_id(last_job.job_id) then return end @@ -551,37 +597,17 @@ function BufferPopupWindow:preview_file(job_id, previewer_result, previewer_labe -- show file contents by lines vim.defer_fn(function() - if not self:previewer_is_valid() then - -- log.debug( - -- "|BufferPopupWindow:preview_file - asyncreadfile - done content| invalid previewer:%s", - -- vim.inspect(self) - -- ) - return - end - local last_content = self.preview_file_contents_queue[#self.preview_file_contents_queue] self.preview_file_contents_queue = {} + self._saved_previewing_file_content_job = last_content if not self:is_last_previewing_file_job_id(last_content.job_id) then return end - - self._saved_previewing_file_content_job = last_content - - local center_line = last_content.previewer_result.lineno - local lines_count = #last_content.contents - 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) - -- ) - -- ) + if not self:previewer_is_valid() then + return + end + local view = self:_make_view(last_content) self:preview_file_contents(last_content, view) end, 10) end) @@ -714,7 +740,7 @@ function BufferPopupWindow:render_file_contents(file_content, content_view, on_c end -- log.debug( -- string.format( - -- "|BufferPopupWindow:render_file_contents| LINES_COUNT:%s, FIRST/LAST:%s/%s, view:%s", + -- "|BufferPopupWindow:render_file_contents| LINES_COUNT:%s, FIRST/LAST:%s/%s, content_view:%s", -- vim.inspect(LINES_COUNT), -- vim.inspect(FIRST_LINE), -- vim.inspect(LAST_LINE), @@ -899,6 +925,8 @@ function BufferPopupWindow:show_preview() self.previewer_bufnr = vim.api.nvim_create_buf(false, true) _set_default_buf_options(self.previewer_bufnr) self.previewer_winnr = vim.api.nvim_open_win(self.previewer_bufnr, true, win_confs.previewer) + local wrap = self._saved_buffer_previewer_opts.fzf_preview_window_opts.wrap + _set_default_previewer_win_options(self.previewer_winnr, wrap) vim.api.nvim_set_current_win(self.provider_winnr) self:resize() @@ -906,15 +934,13 @@ function BufferPopupWindow:show_preview() -- restore last file preview contents vim.schedule(function() if not self:previewer_is_valid() then - -- log.debug( - -- "|BufferPopupWindow:preview_file - asyncreadfile - done content| invalid previewer:%s", - -- vim.inspect(self) - -- ) return end if tbl.tbl_not_empty(self._saved_previewing_file_content_job) then local last_content = self._saved_previewing_file_content_job - local last_view = self._saved_previewing_file_content_view + local last_view = self._saved_previewing_file_content_view ~= nil + and self._saved_previewing_file_content_view + or self:_make_view(last_content) self:preview_file_contents(last_content, last_view) end end) @@ -944,8 +970,10 @@ end function BufferPopupWindow:toggle_preview() -- log.debug( - -- "|BufferPopupWindow:toggle_preview| previewer_is_hidden:%s", - -- vim.inspect(self.previewer_is_hidden) + -- string.format( + -- "|BufferPopupWindow:toggle_preview| previewer_is_hidden:%s", + -- vim.inspect(self.previewer_is_hidden) + -- ) -- ) -- already hide, show it if self.previewer_is_hidden then @@ -1007,7 +1035,7 @@ function BufferPopupWindow:scroll_by(percent, up) shift_lines = -shift_lines end local first_line = num.bound(TOP_LINE + shift_lines, 1, LINES_COUNT) - local last_line = M._make_bottom_by_top(first_line, LINES_COUNT, WIN_HEIGHT) + local last_line = M._calculate_bottom_by_top(first_line, LINES_COUNT, WIN_HEIGHT) -- log.debug( -- "|BufferPopupWindow:scroll_by|-1 percent:%s, up:%s, LINES/HEIGHT/SHIFT:%s/%s/%s, top/bottom/center:%s/%s/%s, first/last:%s/%s", -- vim.inspect(percent), @@ -1021,7 +1049,7 @@ function BufferPopupWindow:scroll_by(percent, up) -- vim.inspect(first_line), -- vim.inspect(last_line) -- ) - local view = M._make_view_by_range(LINES_COUNT, WIN_HEIGHT, first_line, last_line, HIGHLIGHT_LINE) + local view = M._make_range_view(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", diff --git a/lua/fzfx/detail/popup/popup_helpers.lua b/lua/fzfx/detail/popup/popup_helpers.lua index 024b696e0..d4bf2ce34 100644 --- a/lua/fzfx/detail/popup/popup_helpers.lua +++ b/lua/fzfx/detail/popup/popup_helpers.lua @@ -254,7 +254,7 @@ M.make_center_layout = function(win_opts, fzf_preview_window_opts) end_col = end_col, } - log.debug(string.format("|make_center_layout| base_layout:%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") diff --git a/lua/fzfx/helper/actions.lua b/lua/fzfx/helper/actions.lua index f55cb5704..0468ccc33 100644 --- a/lua/fzfx/helper/actions.lua +++ b/lua/fzfx/helper/actions.lua @@ -35,7 +35,7 @@ M.edit_find = function(lines, context) local edits = M._make_edit_find(lines) prompts.confirm_discard_modified(context.bufnr, function() for i, edit in ipairs(edits) do - -- log.debug("|fzfx.helper.actions - edit_find| [%d]:[%s]", i, edit) + -- log.debug(string.format("|edit_find| [%d]:[%s]", i, edit)) local ok, result = pcall(vim.cmd --[[@as function]], edit) assert(ok, vim.inspect(result)) end diff --git a/spec/detail/popup/buffer_popup_window_spec.lua b/spec/detail/popup/buffer_popup_window_spec.lua index f02fb92c0..aea9345f9 100644 --- a/spec/detail/popup/buffer_popup_window_spec.lua +++ b/spec/detail/popup/buffer_popup_window_spec.lua @@ -298,23 +298,23 @@ describe("detail.popup.buffer_popup_window", function() describe("[_make_view/_adjust_view]", function() it("_adjust_view", function() - local actual11, actual12 = buffer_popup_window._adjust_view(20, 30, 100, 30) + local actual11, actual12 = buffer_popup_window._adjust_top_and_bottom(20, 30, 100, 30) print(string.format("_adjust_view-1:%s,%s\n", vim.inspect(actual11), vim.inspect(actual12))) - local actual21, actual22 = buffer_popup_window._adjust_view(1, 10, 100, 30) + local actual21, actual22 = buffer_popup_window._adjust_top_and_bottom(1, 10, 100, 30) print(string.format("_adjust_view-2:%s,%s\n", vim.inspect(actual21), vim.inspect(actual22))) - local actual31, actual32 = buffer_popup_window._adjust_view(90, 100, 100, 30) + local actual31, actual32 = buffer_popup_window._adjust_top_and_bottom(90, 100, 100, 30) print(string.format("_adjust_view-3:%s,%s\n", vim.inspect(actual31), vim.inspect(actual32))) - local actual41, actual42 = buffer_popup_window._adjust_view(20, 50, 100, 30) + local actual41, actual42 = buffer_popup_window._adjust_top_and_bottom(20, 50, 100, 30) print(string.format("_adjust_view-4:%s,%s\n", vim.inspect(actual41), vim.inspect(actual42))) end) it("_make_view_by_top", function() - local actual1 = buffer_popup_window._make_view_by_top(10, 50) + local actual1 = buffer_popup_window._make_top_view(10, 50) print(string.format("_make_view_by_top-1:%s\n", vim.inspect(actual1))) - local actual2 = buffer_popup_window._make_view_by_top(30, 30) + local actual2 = buffer_popup_window._make_top_view(30, 30) print(string.format("_make_view_by_top-2:%s\n", vim.inspect(actual2))) - local actual3 = buffer_popup_window._make_view_by_top(30, 29) + local actual3 = buffer_popup_window._make_top_view(30, 29) print(string.format("_make_view_by_top-3:%s\n", vim.inspect(actual3))) - local actual4 = buffer_popup_window._make_view_by_top(40, 41) + local actual4 = buffer_popup_window._make_top_view(40, 41) print(string.format("_make_view_by_top-4:%s\n", vim.inspect(actual4))) end) end)