Skip to content

Commit

Permalink
Replace some instances of vim.cmd('set ...')
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian committed Oct 22, 2023
1 parent 6d1f376 commit 186a664
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
10 changes: 4 additions & 6 deletions lua/lean/infoview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -261,16 +261,14 @@ function Infoview:__refresh()
local valid_windows = {}

self.info.__win_event_disable = true
for _, win in pairs({self.window, self.__diff_win}) do
for _, win in pairs{ self.window, self.__diff_win } do
if win and vim.api.nvim_win_is_valid(win) then
table.insert(valid_windows, win)
end
end

for _, win in pairs(valid_windows) do
vim.api.nvim_win_call(win, function()
vim.cmd('set winfixwidth')
end)
vim.wo[win].winfixwidth = true
end

for _, win in pairs(valid_windows) do
Expand Down Expand Up @@ -311,8 +309,8 @@ function Infoview:__refresh_diff()
for _, win in pairs({self.__diff_win, self.window}) do
vim.api.nvim_win_call(win, function()
vim.cmd.diffthis()
vim.cmd("set foldmethod=manual")
vim.cmd("setlocal wrap")
vim.wo.foldmethod = 'manual'
vim.wo.wrap = true
end)
end

Expand Down
9 changes: 8 additions & 1 deletion lua/tests/infoview/open_close_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('infoview open/close', function()

it('remains open on splitting the current window', function(_)
local windows = vim.api.nvim_tabpage_list_wins(0)
assert.is.equal(2, #windows) -- +1 above
assert.is.equal(2, #windows)
assert.is.truthy(
vim.tbl_contains(windows, infoview.get_current_infoview().window)
)
Expand All @@ -64,6 +64,13 @@ describe('infoview open/close', function()
assert.windows.are(windows)
end)

it('is fixed width', function(_)
local windows = vim.api.nvim_tabpage_list_wins(0)
assert.is.equal(#windows, 2)
assert.is.truthy(vim.wo[infoview.get_current_infoview().window].winfixwidth)
assert.is.falsy(vim.wo[lean_window].winfixwidth)
end)

it('closes via its Lua API and stays closed', function(_)
infoview.get_current_infoview():close()
assert.windows.are(lean_window)
Expand Down

0 comments on commit 186a664

Please sign in to comment.