Skip to content

Commit

Permalink
fix: lock cursor to first mutable column
Browse files Browse the repository at this point in the history
Previously we were forcing the cursor to be after the hidden ID at the
start, but that still meant that it would end up on top of the icon.
This made rename operations slightly more annoying than necessary, since
you would need to first move the cursor forward to the file name. Now,
the cursor will be locked to the beginning of the filename unless there
is a mutable column earlier in the row.
  • Loading branch information
stevearc committed Sep 9, 2023
1 parent 879d280 commit d4eb4f3
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions lua/oil/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,22 @@ M.delete_hidden_buffers = function()
cache.clear_everything()
end

---@param adapter oil.Adapter
---@param ranges table<string, integer[]>
---@return integer
local function get_first_mutable_column_col(adapter, ranges)
local min_col = ranges.name[1]
for col_name, start_len in pairs(ranges) do
local start = start_len[1]
local col_spec = columns.get_column(adapter, col_name)
local is_col_mutable = col_spec and col_spec.perform_action ~= nil
if is_col_mutable and start < min_col then
min_col = start
end
end
return min_col
end

---@param bufnr integer
M.initialize = function(bufnr)
if bufnr == 0 then
Expand Down Expand Up @@ -308,8 +324,8 @@ M.initialize = function(bufnr)
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 result and result.ranges then
local min_col = get_first_mutable_column_col(adapter, result.ranges)
if cur[2] < min_col then
vim.api.nvim_win_set_cursor(0, { cur[1], min_col })
end
Expand Down

0 comments on commit d4eb4f3

Please sign in to comment.