feat: constrain_cursor option (closes #257)
This commit is contained in:
parent
a60c6d10fd
commit
71b1ef5edf
4 changed files with 22 additions and 1 deletions
|
|
@ -165,6 +165,9 @@ require("oil").setup({
|
||||||
-- Set to true to autosave buffers that are updated with LSP willRenameFiles
|
-- Set to true to autosave buffers that are updated with LSP willRenameFiles
|
||||||
-- Set to "unmodified" to only save unmodified buffers
|
-- Set to "unmodified" to only save unmodified buffers
|
||||||
lsp_rename_autosave = false,
|
lsp_rename_autosave = false,
|
||||||
|
-- Constrain the cursor to the editable parts of the oil buffer
|
||||||
|
-- Set to `false` to disable, or "name" to keep it on the file names
|
||||||
|
constrain_cursor = "editable",
|
||||||
-- Keymaps in oil buffer. Can be any value that `vim.keymap.set` accepts OR a table of keymap
|
-- Keymaps in oil buffer. Can be any value that `vim.keymap.set` accepts OR a table of keymap
|
||||||
-- options with a `callback` (e.g. { callback = function() ... end, desc = "", mode = "n" })
|
-- options with a `callback` (e.g. { callback = function() ... end, desc = "", mode = "n" })
|
||||||
-- Additionally, if it is a string that matches "actions.<name>",
|
-- Additionally, if it is a string that matches "actions.<name>",
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,9 @@ OPTIONS *oil-option
|
||||||
-- Set to true to autosave buffers that are updated with LSP willRenameFiles
|
-- Set to true to autosave buffers that are updated with LSP willRenameFiles
|
||||||
-- Set to "unmodified" to only save unmodified buffers
|
-- Set to "unmodified" to only save unmodified buffers
|
||||||
lsp_rename_autosave = false,
|
lsp_rename_autosave = false,
|
||||||
|
-- Constrain the cursor to the editable parts of the oil buffer
|
||||||
|
-- Set to `false` to disable, or "name" to keep it on the file names
|
||||||
|
constrain_cursor = "editable",
|
||||||
-- Keymaps in oil buffer. Can be any value that `vim.keymap.set` accepts OR a table of keymap
|
-- Keymaps in oil buffer. Can be any value that `vim.keymap.set` accepts OR a table of keymap
|
||||||
-- options with a `callback` (e.g. { callback = function() ... end, desc = "", mode = "n" })
|
-- options with a `callback` (e.g. { callback = function() ... end, desc = "", mode = "n" })
|
||||||
-- Additionally, if it is a string that matches "actions.<name>",
|
-- Additionally, if it is a string that matches "actions.<name>",
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,9 @@ local default_config = {
|
||||||
-- Set to true to autosave buffers that are updated with LSP willRenameFiles
|
-- Set to true to autosave buffers that are updated with LSP willRenameFiles
|
||||||
-- Set to "unmodified" to only save unmodified buffers
|
-- Set to "unmodified" to only save unmodified buffers
|
||||||
lsp_rename_autosave = false,
|
lsp_rename_autosave = false,
|
||||||
|
-- Constrain the cursor to the editable parts of the oil buffer
|
||||||
|
-- Set to `false` to disable, or "name" to keep it on the file names
|
||||||
|
constrain_cursor = "editable",
|
||||||
-- Keymaps in oil buffer. Can be any value that `vim.keymap.set` accepts OR a table of keymap
|
-- Keymaps in oil buffer. Can be any value that `vim.keymap.set` accepts OR a table of keymap
|
||||||
-- options with a `callback` (e.g. { callback = function() ... end, desc = "", mode = "n" })
|
-- options with a `callback` (e.g. { callback = function() ... end, desc = "", mode = "n" })
|
||||||
-- Additionally, if it is a string that matches "actions.<name>",
|
-- Additionally, if it is a string that matches "actions.<name>",
|
||||||
|
|
|
||||||
|
|
@ -235,6 +235,9 @@ end
|
||||||
|
|
||||||
---Force cursor to be after hidden/immutable columns
|
---Force cursor to be after hidden/immutable columns
|
||||||
local function constrain_cursor()
|
local function constrain_cursor()
|
||||||
|
if not config.constrain_cursor then
|
||||||
|
return
|
||||||
|
end
|
||||||
local parser = require("oil.mutator.parser")
|
local parser = require("oil.mutator.parser")
|
||||||
|
|
||||||
local adapter = util.get_adapter(0)
|
local adapter = util.get_adapter(0)
|
||||||
|
|
@ -247,7 +250,16 @@ local function constrain_cursor()
|
||||||
local column_defs = columns.get_supported_columns(adapter)
|
local column_defs = columns.get_supported_columns(adapter)
|
||||||
local result = parser.parse_line(adapter, line, column_defs)
|
local result = parser.parse_line(adapter, line, column_defs)
|
||||||
if result and result.ranges then
|
if result and result.ranges then
|
||||||
local min_col = get_first_mutable_column_col(adapter, result.ranges)
|
local min_col
|
||||||
|
if config.constrain_cursor == "editable" then
|
||||||
|
min_col = get_first_mutable_column_col(adapter, result.ranges)
|
||||||
|
elseif config.constrain_cursor == "name" then
|
||||||
|
min_col = result.ranges.name[1]
|
||||||
|
else
|
||||||
|
error(
|
||||||
|
string.format('Unexpected value "%s" for option constrain_cursor', config.constrain_cursor)
|
||||||
|
)
|
||||||
|
end
|
||||||
if cur[2] < min_col then
|
if cur[2] < min_col then
|
||||||
vim.api.nvim_win_set_cursor(0, { cur[1], min_col })
|
vim.api.nvim_win_set_cursor(0, { cur[1], min_col })
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue