Skip to content

Commit

Permalink
Merge pull request #373 from funemy/main
Browse files Browse the repository at this point in the history
fix goto_last_window
  • Loading branch information
Julian authored Jan 9, 2025
2 parents 7c1f0d6 + e890efe commit dbb4196
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 13 deletions.
23 changes: 11 additions & 12 deletions lua/lean/infoview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -589,24 +589,23 @@ end

---@return Info
function Info:new(opts)
local pins_element = Element:new {
name = 'info',
events = {
goto_last_window = function()
if not self.last_window then
return
end
vim.api.nvim_set_current_win(self.last_window)
end,
},
}
local new_info = setmetatable({
pins = {},
__infoview = opts.infoview,
__pins_element = pins_element,
__pins_element = Element:new { name = 'info' },
__diff_pin_element = Element:new { name = 'diff' },
__win_event_disable = false, -- FIXME: This too is really confusing
}, self)

new_info.__pins_element.events = {
goto_last_window = function()
if not new_info.last_window then
return
end
vim.api.nvim_set_current_win(new_info.last_window)
end,
}

new_info.pin = Pin:new {
id = '1',
paused = options.autopause,
Expand Down
2 changes: 1 addition & 1 deletion lua/lean/tui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ local util = require 'lean._util'
---keys trigger it (or theoretically mouse events, though we don't do so in
---practice at the moment).
---
---In gneeral, resist the temptation to add new event types here, as this
---In general, resist the temptation to add new event types here, as this
---entire concept feels slightly like "misdirection" that could be redesigned
---at least because it mixes abstraction layers between general events and ones
---that are very specific to a particular context (like "going to the last
Expand Down
33 changes: 33 additions & 0 deletions spec/infoview/jump_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---@brief [[
--- Tests for jumping from Lean file to infoview and back
---@brief ]]

local fixtures = require 'spec.fixtures'
local helpers = require 'spec.helpers'
local infoview = require 'lean.infoview'

require('lean').setup {}

describe('infoview jumping', function()
local lean_window

it('jumps from Lean file to infoview', function()
assert.is.equal(1, #vim.api.nvim_tabpage_list_wins(0))
lean_window = vim.api.nvim_get_current_win()

vim.cmd('edit! ' .. fixtures.project.some_existing_file)
local current_infoview = infoview.get_current_infoview()

current_infoview:open()
-- Both Lean and infoview windows exist
assert.windows.are(lean_window, current_infoview.window)

vim.cmd.LeanGotoInfoview()
assert.current_window.is(current_infoview.window)
end)

it('jumps back from infoview to the associated Lean file', function()
helpers.feed '<LocalLeader><Tab>'
assert.current_window.is(lean_window)
end)
end)

0 comments on commit dbb4196

Please sign in to comment.