-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnavigation.lua
58 lines (53 loc) · 2.22 KB
/
navigation.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
local M = {}
local is_files_found_buffer=function(buf) return buf._type == _L['[Files Found Buffer]'] end
M.is_files_found_buffer=is_files_found_buffer
local is_message_buffer=function(buf) return buf._type == _L['[Message Buffer]'] end
M.is_message_buffer=is_message_buffer
local is_print_buffer=function(buf)
return (is_files_found_buffer(buf) or is_message_buffer(buf))
end
M.is_print_buffer=is_print_buffer
-- For all Views, if the current Buffer is a Print-Buffer (i.e. Find_in_Files_Buffer, Message_Buffer), then switch to the previous Buffer that wasn't a Print-Buffer.
local switch_print_buffers = function(view_buffer_state)
local switched=false
local switch_back_buffer=nil
-- TODO (Maybe): switch only back if inside print-buffer
for i=1,#_VIEWS do
-- check if there is a buffer to switch back:
if is_print_buffer(_VIEWS[i].buffer) then
-- switch if there is a buffer stored for the view and this buffer exists in _BUFFERS:
switch_back_buffer=view_buffer_state[_VIEWS[i]]
if _BUFFERS[switch_back_buffer] then
view.goto_buffer(_VIEWS[i], view_buffer_state[_VIEWS[i]])
switched=true
end
end
end
-- if there was a switch of buffers switch also the view:
if switched==true then
if view_buffer_state.focus_view then ui.goto_view(view_buffer_state.focus_view) end
end
return switched
end
M.switch_print_buffers=switch_print_buffers
-- Updates the view_buffer_state, with current_state:
local prepare_print=function(view_buffer_state)
-- snap ui-state
local buffer_in_view=nil
local focus=nil
for i=1,#_VIEWS do
buffer_in_view=_VIEWS[i].buffer
if not is_print_buffer(buffer_in_view) then
view_buffer_state[_VIEWS[i]]=buffer_in_view
focus = _VIEWS[i] == view
if focus then view_buffer_state.focus_view=_VIEWS[i] end
end
end
--switch to preferred_view where print-out should take place
local preferred_view=_VIEWS[view_buffer_state.preferred_view_idx]
if preferred_view~=nil then ui.goto_view(preferred_view) end
-- return modified view_buffer_state
return view_buffer_state
end
M.prepare_print=prepare_print
return M