fix(view): prevent backspace from deleting into prefix area
Problem: in insert mode, `<BS>`, `<C-h>`, `<C-w>`, and `<C-u>` could delete backwards past the name column boundary into the icon/permissions/ID prefix, corrupting the line and breaking the parser. Solution: add buffer-local insert-mode expr keymaps that compute the name column boundary (cached per line) and return no-op when the cursor is already at or before it. `<C-u>` emits exactly enough `<BS>` keys to delete back to the boundary, never past it. Closes #133
This commit is contained in:
parent
7234be3f5c
commit
2d505bfb62
2 changed files with 141 additions and 0 deletions
|
|
@ -124,6 +124,68 @@ describe('regression tests', function()
|
|||
})
|
||||
end)
|
||||
|
||||
it('BS at constraint boundary is a no-op', function()
|
||||
tmpdir:create({ 'a.txt' })
|
||||
oil.setup({ constrain_cursor = 'name', columns = {} })
|
||||
vim.cmd.edit({ args = { 'oil://' .. vim.fn.fnamemodify(tmpdir.path, ':p') } })
|
||||
test_util.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
|
||||
test_util.actions.focus('a.txt')
|
||||
local line_before = vim.api.nvim_get_current_line()
|
||||
local cur = vim.api.nvim_win_get_cursor(0)
|
||||
local parser = require('oil.mutator.parser')
|
||||
local adapter = require('oil.util').get_adapter(0, true)
|
||||
local columns_mod = require('oil.columns')
|
||||
local column_defs = columns_mod.get_supported_columns(adapter)
|
||||
local result = parser.parse_line(adapter, line_before, column_defs)
|
||||
local name_col = result.ranges.name[1]
|
||||
vim.api.nvim_win_set_cursor(0, { cur[1], name_col })
|
||||
vim.cmd.startinsert()
|
||||
vim.wait(20)
|
||||
test_util.feedkeys({ '<BS>' }, 10)
|
||||
vim.cmd.stopinsert()
|
||||
vim.wait(10)
|
||||
local line_after = vim.api.nvim_get_current_line()
|
||||
assert.equals(line_before, line_after)
|
||||
end)
|
||||
|
||||
it('BS within name works normally', function()
|
||||
tmpdir:create({ 'a.txt' })
|
||||
oil.setup({ constrain_cursor = 'name', columns = {} })
|
||||
vim.cmd.edit({ args = { 'oil://' .. vim.fn.fnamemodify(tmpdir.path, ':p') } })
|
||||
test_util.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
|
||||
test_util.actions.focus('a.txt')
|
||||
local line_before = vim.api.nvim_get_current_line()
|
||||
test_util.feedkeys({ 'A', 'x', '<BS>' }, 10)
|
||||
vim.cmd.stopinsert()
|
||||
vim.wait(10)
|
||||
local line_after = vim.api.nvim_get_current_line()
|
||||
assert.equals(line_before, line_after)
|
||||
end)
|
||||
|
||||
it('BS does not cross into prefix area', function()
|
||||
tmpdir:create({ 'a.txt' })
|
||||
oil.setup({ constrain_cursor = 'name', columns = {} })
|
||||
vim.cmd.edit({ args = { 'oil://' .. vim.fn.fnamemodify(tmpdir.path, ':p') } })
|
||||
test_util.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
|
||||
test_util.actions.focus('a.txt')
|
||||
local line_before = vim.api.nvim_get_current_line()
|
||||
local parser = require('oil.mutator.parser')
|
||||
local adapter = require('oil.util').get_adapter(0, true)
|
||||
local columns_mod = require('oil.columns')
|
||||
local column_defs = columns_mod.get_supported_columns(adapter)
|
||||
local result = parser.parse_line(adapter, line_before, column_defs)
|
||||
local name_col = result.ranges.name[1]
|
||||
vim.api.nvim_win_set_cursor(0, { vim.api.nvim_win_get_cursor(0)[1], name_col + 1 })
|
||||
vim.cmd.startinsert()
|
||||
vim.wait(20)
|
||||
test_util.feedkeys({ '<BS>', '<BS>', '<BS>' }, 10)
|
||||
vim.cmd.stopinsert()
|
||||
vim.wait(10)
|
||||
local line_after = vim.api.nvim_get_current_line()
|
||||
local id_prefix = line_before:match('^(/%d+ )')
|
||||
assert.truthy(line_after:find(id_prefix, 1, true))
|
||||
end)
|
||||
|
||||
it('can open files from floating window', function()
|
||||
tmpdir:create({ 'a.txt' })
|
||||
oil.open_float(tmpdir.path)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue