Skip to content

Commit f9c6478

Browse files
committed
fix(undotree): reverse when --layout=default
Closes #2464
1 parent ff0c88a commit f9c6478

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lua/fzf-lua/providers/undotree.lua

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,10 @@ end
112112
--- @param cb function
113113
--- @param tree vim.undotree.tree
114114
--- @param nodes integer[]?
115+
--- @param reverse boolean
115116
--- @param parents integer[]?
116117
--- @param prefix string?
117-
local function draw_tree(opts, cb, tree, nodes, parents, prefix)
118+
local function draw_tree(opts, cb, tree, nodes, reverse, parents, prefix)
118119
if not nodes or #nodes == 0 then return end
119120
local is_root = nodes[1] == 0
120121
prefix = prefix or ""
@@ -128,13 +129,14 @@ local function draw_tree(opts, cb, tree, nodes, parents, prefix)
128129
-- TODO: IMHO the latter (flattened single) is nicer
129130
-- local is_single = #parents == 1 and #nodes == 1
130131
local is_single = #nodes == 1
132+
local leaf = reverse and "" or ""
131133
local node = utils.ansi_codes[opts.hls.dir_part](
132-
prefix .. ((is_root or is_single) and "" or is_last and "── " or "├── "))
134+
prefix .. ((is_root or is_single) and "" or is_last and leaf .. "── " or "├── "))
133135
.. utils.ansi_codes[opts.hls.buf_name](tostring(n))
134136
-- local w = 64 + string.len(node) - vim.fn.strwidth(node)
135137
cb(n, string.format("%s\t\t%s", node,
136138
utils.ansi_codes[opts.hls.path_linenr](reltime(v.time))))
137-
draw_tree(opts, cb, tree, v.child, nodes,
139+
draw_tree(opts, cb, tree, v.child, reverse, nodes,
138140
prefix .. ((is_root or is_single) and "" or is_last and " " or ""))
139141
end
140142
end
@@ -165,7 +167,8 @@ M.undotree = function(opts)
165167
coroutine.yield()
166168
end
167169

168-
draw_tree(opts, add_entry, tree, { 0 })
170+
local reverse = utils.map_get(opts, "fzf_opts.--layout") == "default"
171+
draw_tree(opts, add_entry, tree, { 0 }, reverse)
169172

170173
cb(nil) -- EOF
171174
end)()

0 commit comments

Comments
 (0)