@@ -14,6 +14,7 @@ local log = require("leetcode.logger")
1414--- @field testcase lc.ui.Console.TestcasePopup
1515--- @field result lc.ui.Console.ResultPopup
1616--- @field popups lc.ui.Console.Popup[]
17+ --- @field prev_winid integer
1718local ConsoleLayout = Layout :extend (" LeetConsoleLayout" )
1819
1920function ConsoleLayout :unmount () --
@@ -24,15 +25,19 @@ function ConsoleLayout:unmount() --
2425 self .popups = { self .testcase , self .result }
2526end
2627
28+ function ConsoleLayout :show ()
29+ self .prev_winid = vim .api .nvim_get_current_win ()
30+
31+ ConsoleLayout .super .show (self )
32+ end
33+
2734function ConsoleLayout :hide ()
2835 ConsoleLayout .super .hide (self )
2936
30- pcall (function ()
31- local winid = vim .api .nvim_get_current_win ()
32- if winid == self .question .description .winid then
33- vim .api .nvim_set_current_win (self .question .winid )
34- end
35- end )
37+ if self .prev_winid and vim .api .nvim_win_is_valid (self .prev_winid ) then
38+ vim .api .nvim_set_current_win (self .prev_winid )
39+ self .prev_winid = nil
40+ end
3641end
3742
3843function ConsoleLayout :mount ()
@@ -90,6 +95,7 @@ function ConsoleLayout:init(parent)
9095 self .testcase = Testcase (self )
9196 self .result = Result (self )
9297 self .popups = { self .testcase , self .result }
98+ self .prev_winid = nil
9399
94100 ConsoleLayout .super .init (
95101 self ,
0 commit comments