Skip to content

Commit 06d9daf

Browse files
committed
Use state status to store depth toggle
1 parent af0ec40 commit 06d9daf

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

lua/telescope/_extensions/orgmode/refile_heading.lua

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local conf = require("telescope.config").values
44
local action_set = require("telescope.actions.set")
55
local actions = require("telescope.actions")
66
local action_state = require("telescope.actions.state")
7+
local state = require("telescope.state")
78

89
local utils = require('orgmode-telescope.utils')
910

@@ -49,27 +50,30 @@ return function(opts)
4950
end
5051
end
5152

52-
local current_depth = opts.max_depth
53-
local next_depth = nil
54-
if current_depth ~= 0 then
55-
next_depth = 0
56-
end
53+
local function gen_depth_toggle(opts, prompt_bufnr)
5754

58-
local function depth_toggle(prompt_bufnr)
59-
local current_picker = action_state.get_current_picker(prompt_bufnr)
55+
local status = state.get_status(prompt_bufnr)
56+
status._ot_current_depth = opts.max_depth
57+
status._ot_next_depth = nil
58+
if status._ot_current_depth ~= 0 then
59+
status._ot_next_depth = 0
60+
end
6061

61-
-- TODO: use action_state to store these to allow easy rebinding by users
62-
local aux = current_depth
63-
current_depth = next_depth
64-
next_depth = aux
62+
return function()
63+
local current_picker = action_state.get_current_picker(prompt_bufnr)
6564

66-
opts.max_depth = current_depth
67-
local new_finder = finders.new_table {
68-
results = utils.get_entries(opts),
69-
entry_maker = opts.entry_maker or utils.make_entry(opts),
70-
}
65+
local aux = status._ot_current_depth
66+
status._ot_current_depth = status._ot_next_depth
67+
status._ot_next_depth = aux
68+
69+
opts.max_depth = status._ot_current_depth
70+
local new_finder = finders.new_table {
71+
results = utils.get_entries(opts),
72+
entry_maker = opts.entry_maker or utils.make_entry(opts),
73+
}
7174

72-
current_picker:refresh(new_finder, opts)
75+
current_picker:refresh(new_finder, opts)
76+
end
7377
end
7478

7579
pickers.new(opts, {
@@ -82,9 +86,9 @@ return function(opts)
8286
},
8387
sorter = conf.generic_sorter(opts),
8488
previewer = conf.grep_previewer(opts),
85-
attach_mappings = function(_, map)
89+
attach_mappings = function(prompt_bufnr, map)
8690
action_set.select:replace(refile)
87-
map("i", "<c-space>", depth_toggle)
91+
map("i", "<c-space>", gen_depth_toggle(opts, prompt_bufnr))
8892
return true
8993
end,
9094
}):find()

0 commit comments

Comments
 (0)