@@ -10,6 +10,13 @@ local sprint = require("jira.jira-api.sprint")
1010local common_ui = require (" jira.common.ui" )
1111local board_ui = require (" jira.board.ui" )
1212
13+ local function ensure_window ()
14+ if not state .win or not vim .api .nvim_win_is_valid (state .win ) then
15+ board_ui .create_window ()
16+ util .setup_static_highlights ()
17+ end
18+ end
19+
1320function M .refresh_view ()
1421 local cache_key = helper .get_cache_key (state .project_key , state .current_view )
1522 state .cache [cache_key ] = nil
@@ -105,7 +112,8 @@ function M.setup_keymaps()
105112
106113 -- Clear existing buffer keymaps
107114 local keys_to_clear =
108- { " o" , " S" , " B" , " J" , " H" , " K" , " m" , " gx" , " r" , " q" , " gs" , " ga" , " gw" , " gb" , " go" , " <Esc>" , " s" , " a" , " t" , " co" , " i" , " c" }
115+ { " o" , " S" , " B" , " J" , " H" , " K" , " m" , " gx" , " r" , " q" , " gs" , " ga" , " gw" , " gb" , " go" , " <Esc>" , " s" , " a" , " t" , " co" , " i" ,
116+ " c" }
109117 for _ , k in ipairs (keys_to_clear ) do
110118 pcall (vim .api .nvim_buf_del_keymap , state .buf , " n" , k )
111119 end
@@ -178,36 +186,28 @@ function M.setup_keymaps()
178186end
179187
180188function M .load_view (project_key , view_name )
181- local old_cursor = nil
182- if state .win and api .nvim_win_is_valid (state .win ) and state .current_view == view_name then
183- old_cursor = api .nvim_win_get_cursor (state .win )
184- end
189+ local old_view = helper .save_view_if_same (view_name )
185190
186191 state .project_key = project_key
187192 state .current_view = view_name
188193
194+ -- HELP VIEW
189195 if view_name == " Help" then
190196 vim .schedule (function ()
191- if not state .win or not api .nvim_win_is_valid (state .win ) then
192- board_ui .create_window ()
193- util .setup_static_highlights ()
194- end
197+ ensure_window ()
198+
195199 state .tree = {}
196200 state .line_map = {}
197201 render .clear (state .buf )
198202 render .render_help (view_name )
199- if old_cursor and state .win and api .nvim_win_is_valid (state .win ) then
200- local line_count = api .nvim_buf_line_count (state .buf )
201- if old_cursor [1 ] > line_count then
202- old_cursor [1 ] = line_count
203- end
204- api .nvim_win_set_cursor (state .win , old_cursor )
205- end
203+
204+ helper .restore_view (old_view )
206205 M .setup_keymaps ()
207206 end )
208207 return
209208 end
210209
210+ -- JQL INIT
211211 if view_name == " JQL" and not state .current_query then
212212 local query_names = M .get_query_names ()
213213 if # query_names > 0 then
@@ -225,35 +225,23 @@ function M.load_view(project_key, view_name)
225225 local function process_issues (issues )
226226 vim .schedule (function ()
227227 common_ui .stop_loading ()
228+ ensure_window ()
228229
229- -- Setup UI if not already created
230- if not state .win or not api .nvim_win_is_valid (state .win ) then
231- board_ui .create_window ()
232- util .setup_static_highlights ()
233- end
230+ render .clear (state .buf )
234231
235232 if not issues or # issues == 0 then
236233 state .tree = {}
237- render .clear (state .buf )
238234 render .render_issue_tree (state .tree , state .current_view )
239235 vim .notify (" No issues found in " .. view_name .. " ." , vim .log .levels .WARN )
240236 else
241237 state .tree = util .build_issue_tree (issues )
242- render .clear (state .buf )
243238 render .render_issue_tree (state .tree , state .current_view )
244239 if not cached_issues then
245240 vim .notify (" Loaded " .. view_name .. " for " .. project_key , vim .log .levels .INFO )
246241 end
247242 end
248243
249- if old_cursor and state .win and api .nvim_win_is_valid (state .win ) then
250- local line_count = api .nvim_buf_line_count (state .buf )
251- if old_cursor [1 ] > line_count then
252- old_cursor [1 ] = line_count
253- end
254- api .nvim_win_set_cursor (state .win , old_cursor )
255- end
256-
244+ helper .restore_view (old_view )
257245 M .setup_keymaps ()
258246 end )
259247 end
0 commit comments