feat: API to automatically open preview window after opening oil (#339)
This commit is contained in:
parent
52f1683c76
commit
57528bf9c5
6 changed files with 135 additions and 31 deletions
42
tests/preview_spec.lua
Normal file
42
tests/preview_spec.lua
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
require("plenary.async").tests.add_to_env()
|
||||
local TmpDir = require("tests.tmpdir")
|
||||
local oil = require("oil")
|
||||
local test_util = require("tests.test_util")
|
||||
local util = require("oil.util")
|
||||
|
||||
a.describe("oil preview", function()
|
||||
local tmpdir
|
||||
a.before_each(function()
|
||||
tmpdir = TmpDir.new()
|
||||
end)
|
||||
a.after_each(function()
|
||||
if tmpdir then
|
||||
tmpdir:dispose()
|
||||
end
|
||||
test_util.reset_editor()
|
||||
end)
|
||||
|
||||
a.it("opens preview window", function()
|
||||
tmpdir:create({ "a.txt" })
|
||||
oil.open(tmpdir.path)
|
||||
test_util.wait_oil_ready()
|
||||
a.wrap(oil.open_preview, 2)()
|
||||
local preview_win = util.get_preview_win()
|
||||
assert.not_nil(preview_win)
|
||||
assert(preview_win)
|
||||
local bufnr = vim.api.nvim_win_get_buf(preview_win)
|
||||
local preview_lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
|
||||
assert.are.same({ "a.txt" }, preview_lines)
|
||||
end)
|
||||
|
||||
a.it("opens preview window when open(preview={})", function()
|
||||
tmpdir:create({ "a.txt" })
|
||||
a.wrap(oil.open, 3)(tmpdir.path, { preview = {} })
|
||||
local preview_win = util.get_preview_win()
|
||||
assert.not_nil(preview_win)
|
||||
assert(preview_win)
|
||||
local bufnr = vim.api.nvim_win_get_buf(preview_win)
|
||||
local preview_lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
|
||||
assert.are.same({ "a.txt" }, preview_lines)
|
||||
end)
|
||||
end)
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
require("plenary.async").tests.add_to_env()
|
||||
local cache = require("oil.cache")
|
||||
local test_adapter = require("oil.adapters.test")
|
||||
local util = require("oil.util")
|
||||
local M = {}
|
||||
|
||||
M.reset_editor = function()
|
||||
|
|
@ -53,6 +54,10 @@ M.wait_for_autocmd = a.wrap(function(autocmd, cb)
|
|||
vim.api.nvim_create_autocmd(autocmd, opts)
|
||||
end, 2)
|
||||
|
||||
M.wait_oil_ready = a.wrap(function(cb)
|
||||
util.run_after_load(0, vim.schedule_wrap(cb))
|
||||
end, 1)
|
||||
|
||||
---@param actions string[]
|
||||
---@param timestep integer
|
||||
M.feedkeys = function(actions, timestep)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue