Merge branch 'stevearc:master' into feat-setup-view-options-add-is_excluded

This commit is contained in:
NWang 2023-03-19 07:09:48 +08:00 committed by GitHub
commit c1ed4fad14
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 295 additions and 78 deletions

View file

@ -54,8 +54,7 @@ M.get_last_cursor = function(bufname)
end
local function are_any_modified()
local view = require("oil.view")
local buffers = view.get_all_buffers()
local buffers = M.get_all_buffers()
for _, bufnr in ipairs(buffers) do
if vim.bo[bufnr].modified then
return true
@ -65,25 +64,34 @@ local function are_any_modified()
end
M.toggle_hidden = function()
local view = require("oil.view")
local any_modified = are_any_modified()
if any_modified then
vim.notify("Cannot toggle hidden files when you have unsaved changes", vim.log.levels.WARN)
else
config.view_options.show_hidden = not config.view_options.show_hidden
view.rerender_all_oil_buffers({ refetch = false })
M.rerender_all_oil_buffers({ refetch = false })
end
end
---@param is_hidden_file fun(filename: string, bufnr: nil|integer): boolean
M.set_is_hidden_file = function(is_hidden_file)
local any_modified = are_any_modified()
if any_modified then
vim.notify("Cannot change is_hidden_file when you have unsaved changes", vim.log.levels.WARN)
else
config.view_options.is_hidden_file = is_hidden_file
M.rerender_all_oil_buffers({ refetch = false })
end
end
M.set_columns = function(cols)
local view = require("oil.view")
local any_modified = are_any_modified()
if any_modified then
vim.notify("Cannot change columns when you have unsaved changes", vim.log.levels.WARN)
else
config.columns = cols
-- TODO only refetch if we don't have all the necessary data for the columns
view.rerender_all_oil_buffers({ refetch = true })
M.rerender_all_oil_buffers({ refetch = true })
end
end
@ -245,11 +253,36 @@ M.initialize = function(bufnr)
group = "Oil",
buffer = bufnr,
callback = function()
local oil = require("oil")
local parser = require("oil.mutator.parser")
if vim.wo.previewwindow then
return
end
-- Force the cursor to be after the (concealed) ID at the beginning of the line
local adapter = util.get_adapter(bufnr)
if adapter then
local cur = vim.api.nvim_win_get_cursor(0)
local line = vim.api.nvim_buf_get_lines(bufnr, cur[1] - 1, cur[1], true)[1]
local column_defs = columns.get_supported_columns(adapter)
local result = parser.parse_line(adapter, line, column_defs)
if result and result.data then
local min_col = result.ranges.id[2] + 1
if cur[2] < min_col then
vim.api.nvim_win_set_cursor(0, { cur[1], min_col })
end
end
end
-- Debounce and update the preview window
if timer then
timer:again()
return
end
timer = vim.loop.new_timer()
if not timer then
return
end
timer:start(10, 100, function()
timer:stop()
timer:close()
@ -258,7 +291,6 @@ M.initialize = function(bufnr)
if vim.api.nvim_get_current_buf() ~= bufnr then
return
end
local oil = require("oil")
local entry = oil.get_cursor_entry()
if entry then
local winid = util.get_preview_win()
@ -398,7 +430,6 @@ local function render_buffer(bufnr, opts)
end
---@private
---@param adapter oil.Adapter
---@param entry oil.InternalEntry
---@param column_defs table[]
---@param col_width integer[]