Skip to content

Commit

Permalink
separate save and remove
Browse files Browse the repository at this point in the history
  • Loading branch information
otavioschwanck committed Feb 6, 2024
1 parent 75c892c commit a302ceb
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 15 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ Just press the leader_key set on setup and follow you heart. (Is that easy)
edit = "e",
delete_mode = "d",
clear_all_items = "C",
toggle = "s",
toggle = "s", -- used as save if separate_save_and_remove is true
open_vertical = "v",
open_horizontal = "-",
quit = "q",
remove = "x", -- only used if separate_save_and_remove is true
},
separate_save_and_remove = false, -- if true, will remove the toggle and create the save/remove keymaps.
leader_key = ";",
global_bookmarks = false, -- if true, arrow will save files globally (ignores separate_by_branch)
index_keys = "123456789zxcbnmZXVBNM,afghjklAFGHJKLwrtyuiopWRTYUIOP", -- keys mapped to bookmark index, i.e. 1st bookmark will be accessible by 1, and 12th - by c
Expand Down
4 changes: 3 additions & 1 deletion lua/arrow/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function M.setup(opts)
open_vertical = "v",
open_horizontal = "-",
quit = "q",
remove = "x",
}

local leader_key = opts.leader_key or ";"
Expand All @@ -34,10 +35,11 @@ function M.setup(opts)
config.setState("leader_key", leader_key)
config.setState("always_show_path", opts.always_show_path or false)
config.setState("show_icons", opts.show_icons)
config.setState("index_keys", opts.index_keys or "123456789zxcbnmZXVBNM,afghjklAFGHJKLwrtyuiopWRTYUIOP")
config.setState("index_keys", opts.index_keys or "123456789zcbnmZXVBNM,afghjklAFGHJKLwrtyuiopWRTYUIOP")
config.setState("hide_handbook", opts.hide_handbook or false)
config.setState("separate_by_branch", opts.separate_by_branch or false)
config.setState("global_bookmarks", opts.global_bookmarks or false)
config.setState("separate_save_and_remove", opts.separate_save_and_remove or false)

config.setState("save_key", opts.save_key or function()
return vim.loop.cwd()
Expand Down
56 changes: 43 additions & 13 deletions lua/arrow/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,29 @@ local function getActionsMenu()

local already_saved = current_index > 0

local text
local separate_save_and_remove = config.getState("separate_save_and_remove")

if already_saved == true then
text = string.format("%s Remove Current", mappings.toggle)
else
text = string.format("%s Save Current File", mappings.toggle)
end

return {
string.format(text, mappings.toggle),
local return_mappings = {
string.format("%s Edit Arrow File", mappings.edit),
string.format("%s Clear All Items", mappings.clear_all_items),
string.format("%s Delete mode", mappings.delete_mode),
string.format("%s Open Vertical", mappings.open_vertical),
string.format("%s Open Horizontal", mappings.open_horizontal),
string.format("%s Quit", mappings.quit),
}

if separate_save_and_remove then
table.insert(return_mappings, 1, string.format("%s Remove Current File", mappings.remove))
table.insert(return_mappings, 1, string.format("%s Save Current File", mappings.toggle))
else
if already_saved == true then
table.insert(return_mappings, 1, string.format("%s Remove Current File", mappings.toggle))
else
table.insert(return_mappings, 1, string.format("%s Save Current File", mappings.toggle))
end
end

return return_mappings
end

local function format_file_names(file_names)
Expand Down Expand Up @@ -320,6 +326,10 @@ function M.openMenu()

if show_handbook then
height = height + 8

if config.getState("separate_save_and_remove") then
height = height + 1
end
end

local width = max_width + 10
Expand Down Expand Up @@ -348,17 +358,37 @@ function M.openMenu()
border = "double",
})

local separate_save_and_remove = config.getState("separate_save_and_remove")

local menuKeymapOpts = { noremap = true, silent = true, buffer = menuBuf, nowait = true }
vim.keymap.set("n", config.getState("leader_key"), closeMenu, menuKeymapOpts)
vim.keymap.set("n", mappings.quit, closeMenu, menuKeymapOpts)
vim.keymap.set("n", mappings.edit, function()
closeMenu()
persist.open_cache_file()
end, menuKeymapOpts)
vim.keymap.set("n", mappings.toggle, function()
persist.toggle(filename)
closeMenu()
end, menuKeymapOpts)

if separate_save_and_remove then
vim.keymap.set("n", mappings.toggle, function()
filename = filename or utils.get_path_for("%")

persist.save(filename)
closeMenu()
end, menuKeymapOpts)

vim.keymap.set("n", mappings.remove, function()
filename = filename or utils.get_path_for("%")

persist.remove(filename)
closeMenu()
end, menuKeymapOpts)
else
vim.keymap.set("n", mappings.toggle, function()
persist.toggle(filename)
closeMenu()
end, menuKeymapOpts)
end

vim.keymap.set("n", mappings.clear_all_items, function()
persist.clear()
closeMenu()
Expand Down

0 comments on commit a302ceb

Please sign in to comment.