@@ -98,21 +98,24 @@ utils.make_entry = function(opts)
9898 end
9999end
100100
101- utils .gen_depth_toggle = function (opts , prompt_bufnr )
102- local status = state .get_status (prompt_bufnr )
103- status ._ot_current_depth = opts .max_depth
104- status ._ot_next_depth = nil
105- if status ._ot_current_depth ~= 0 then
106- status ._ot_next_depth = 0
107- end
108-
109- return function ()
101+ utils .gen_depth_toggle = function (opts )
102+ return function (prompt_bufnr )
110103 local current_picker = action_state .get_current_picker (prompt_bufnr )
104+ local status = state .get_status (prompt_bufnr )
105+
106+ if status ._ot_current_depth == nil and status ._ot_next_depth == nil then
107+ -- uninitialized state - initialize with "show files only"
108+ -- Because when this function is called the first time, it is triggered
109+ -- by the users and we search over headings by default, we set the state
110+ -- for the first toggle already here.
111+ status ._ot_current_depth = 0
112+ status ._ot_next_depth = opts .max_depth
113+ else
114+ -- initalized state - swap to next state
115+ status ._ot_current_depth , status ._ot_next_depth = status ._ot_next_depth , status ._ot_current_depth
116+ end
111117
112- local aux = status ._ot_current_depth
113- status ._ot_current_depth = status ._ot_next_depth
114- status ._ot_next_depth = aux
115-
118+ -- opts is used as a channel to communicate the depth state to the get_entries function
116119 opts .max_depth = status ._ot_current_depth
117120 local new_finder = finders .new_table ({
118121 results = utils .get_entries (opts ),
0 commit comments