@@ -3,38 +3,20 @@ local org = require('telescope-orgmode.org')
33
44local actions = require (' telescope.actions' )
55local action_state = require (' telescope.actions.state' )
6- local state = require (' telescope.state' )
76
87local M = {}
98
109function M .toggle_headlines_orgfiles (opts )
1110 return function (prompt_bufnr )
12- local status = state .get_status (prompt_bufnr )
13-
14- -- _ot_ is used as our plugin-specific namespace in the action status
15- -- (ot - orgmode telescope)
16- --
17- -- FIXME: the state get's sometimes nil when the initalization has already been run
18- -- In this case, a toggle is "dropped" (keypress does not change the state).
19- -- Can we avoid that by initializing the state in the higher order function?
20- -- Idea: We can try to do it as before, but pass the prompt_bufnr with the opts.
21- if status ._ot_state == nil then
22- -- uninitialized state - initialize with orgfiles
23- -- Because when this function is called the first time, it is triggered
24- -- by the users and we search over headlines by default, we set the state
25- -- for the first toggle already here.
26- status ._ot_state = { current = opts .states [2 ], next = opts .states [1 ] }
27- else
28- status ._ot_state .current , status ._ot_state .next = status ._ot_state .next , status ._ot_state .current
29- end
11+ opts .state .current , opts .state .next = opts .state .next , opts .state .current
3012
31- if status . _ot_state .current == ' headlines' then
13+ if opts . state .current == ' headlines' then
3214 M ._find_headlines (opts , prompt_bufnr )
33- elseif status . _ot_state .current == ' orgfiles' then
15+ elseif opts . state .current == ' orgfiles' then
3416 M ._find_orgfiles (opts , prompt_bufnr )
3517 else
3618 -- this should not happen
37- error (string.format (' Invalid state %s' , status . _ot_state .current ))
19+ error (string.format (' Invalid state %s' , opts . state .current ))
3820 end
3921 end
4022end
0 commit comments