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
199 lines
7.1 KiB
Lua
199 lines
7.1 KiB
Lua
local TmpDir = require('spec.tmpdir')
|
|
local actions = require('oil.actions')
|
|
local oil = require('oil')
|
|
local test_util = require('spec.test_util')
|
|
local view = require('oil.view')
|
|
|
|
describe('regression tests', function()
|
|
local tmpdir
|
|
before_each(function()
|
|
tmpdir = TmpDir.new()
|
|
end)
|
|
after_each(function()
|
|
if tmpdir then
|
|
tmpdir:dispose()
|
|
tmpdir = nil
|
|
end
|
|
test_util.reset_editor()
|
|
end)
|
|
|
|
it('can edit dirs that will be renamed to an existing buffer', function()
|
|
vim.cmd.edit({ args = { 'README.md' } })
|
|
vim.cmd.vsplit()
|
|
vim.cmd.edit({ args = { '%:p:h' } })
|
|
assert.equals('oil', vim.bo.filetype)
|
|
vim.cmd.wincmd({ args = { 'p' } })
|
|
assert.equals('markdown', vim.bo.filetype)
|
|
vim.cmd.edit({ args = { '%:p:h' } })
|
|
test_util.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
|
|
assert.equals('oil', vim.bo.filetype)
|
|
end)
|
|
|
|
it('places the cursor on correct entry when opening on file', function()
|
|
vim.cmd.edit({ args = { '.' } })
|
|
test_util.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
|
|
local entry = oil.get_cursor_entry()
|
|
assert.not_nil(entry)
|
|
assert.not_equals('README.md', entry and entry.name)
|
|
vim.cmd.edit({ args = { 'README.md' } })
|
|
view.delete_hidden_buffers()
|
|
oil.open()
|
|
test_util.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
|
|
entry = oil.get_cursor_entry()
|
|
assert.equals('README.md', entry and entry.name)
|
|
end)
|
|
|
|
it("doesn't close floating windows oil didn't open itself", function()
|
|
local winid = vim.api.nvim_open_win(vim.fn.bufadd('README.md'), true, {
|
|
relative = 'editor',
|
|
row = 1,
|
|
col = 1,
|
|
width = 100,
|
|
height = 100,
|
|
})
|
|
oil.open()
|
|
vim.wait(10)
|
|
oil.close()
|
|
vim.wait(10)
|
|
assert.equals(winid, vim.api.nvim_get_current_win())
|
|
end)
|
|
|
|
it("doesn't close splits on oil.close", function()
|
|
vim.cmd.edit({ args = { 'README.md' } })
|
|
vim.cmd.vsplit()
|
|
local winid = vim.api.nvim_get_current_win()
|
|
local bufnr = vim.api.nvim_get_current_buf()
|
|
oil.open()
|
|
vim.wait(10)
|
|
oil.close()
|
|
vim.wait(10)
|
|
assert.equals(2, #vim.api.nvim_tabpage_list_wins(0))
|
|
assert.equals(winid, vim.api.nvim_get_current_win())
|
|
assert.equals(bufnr, vim.api.nvim_get_current_buf())
|
|
end)
|
|
|
|
it('Returns to empty buffer on close', function()
|
|
oil.open()
|
|
test_util.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
|
|
oil.close()
|
|
assert.not_equals('oil', vim.bo.filetype)
|
|
assert.equals('', vim.api.nvim_buf_get_name(0))
|
|
end)
|
|
|
|
it('All buffers set nomodified after save', function()
|
|
tmpdir:create({ 'a.txt' })
|
|
vim.cmd.edit({ args = { 'oil://' .. vim.fn.fnamemodify(tmpdir.path, ':p') } })
|
|
local first_dir = vim.api.nvim_get_current_buf()
|
|
test_util.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
|
|
test_util.feedkeys({ 'dd', 'itest/<esc>', '<CR>' }, 10)
|
|
vim.wait(1000, function()
|
|
return vim.bo.modifiable
|
|
end, 10)
|
|
test_util.feedkeys({ 'p' }, 10)
|
|
oil.save({ confirm = false })
|
|
vim.wait(1000, function()
|
|
return vim.bo.modifiable
|
|
end, 10)
|
|
tmpdir:assert_fs({
|
|
['test/a.txt'] = 'a.txt',
|
|
})
|
|
assert.falsy(vim.bo[first_dir].modified)
|
|
end)
|
|
|
|
it("refreshing buffer doesn't lose track of it", function()
|
|
vim.cmd.edit({ args = { '.' } })
|
|
test_util.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
|
|
local bufnr = vim.api.nvim_get_current_buf()
|
|
vim.cmd.edit({ bang = true })
|
|
test_util.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
|
|
assert.are.same({ bufnr }, require('oil.view').get_all_buffers())
|
|
end)
|
|
|
|
it('can copy a file multiple times', function()
|
|
test_util.actions.open({ tmpdir.path })
|
|
vim.api.nvim_feedkeys('ifoo.txt', 'x', true)
|
|
test_util.actions.save()
|
|
vim.api.nvim_feedkeys('yyp$ciWbar.txt', 'x', true)
|
|
vim.api.nvim_feedkeys('yyp$ciWbaz.txt', 'x', true)
|
|
test_util.actions.save()
|
|
assert.are.same({ 'bar.txt', 'baz.txt', 'foo.txt' }, test_util.parse_entries(0))
|
|
tmpdir:assert_fs({
|
|
['foo.txt'] = '',
|
|
['bar.txt'] = '',
|
|
['baz.txt'] = '',
|
|
})
|
|
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)
|
|
test_util.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
|
|
actions.select.callback()
|
|
vim.wait(1000, function()
|
|
return vim.fn.expand('%:t') == 'a.txt'
|
|
end, 10)
|
|
assert.equals('a.txt', vim.fn.expand('%:t'))
|
|
end)
|
|
end)
|