From 2fc6a0a9389ca561e2249a3d2585c56860eec31a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linhart=20Luk=C3=A1=C5=A1?= Date: Fri, 14 Feb 2025 11:21:40 +0100 Subject: [PATCH 1/2] Add custom bookmark description when creating --- README.md | 7 +++++++ main.lua | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4574907..5af0c0a 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,7 @@ require("bookmarks"):setup({ persist = "none", desc_format = "full", file_pick_mode = "hover", + custom_desc_input = false, notify = { enable = false, timeout = 1, @@ -129,3 +130,9 @@ By default the notification has a 1 second timeout that can be changed with `not Furthermore, you can customize the notification messages with `notify.message`. For the `new` and `delete` messages, the `` and `` keywords can be used, which will be replaced by the respective new/deleted bookmark's associated key and folder. + +### `custom_desc_input` + +When enabled, user can change description for new bookmark before it is saved. + +By default the custom description input is filled with path. diff --git a/main.lua b/main.lua index 7bfa9ca..b9a92a7 100644 --- a/main.lua +++ b/main.lua @@ -118,11 +118,15 @@ local _save_last_directory = ya.sync(function(state, persist) end) end) +local _is_custom_desc_input_enabled = ya.sync(function(state, persist) + return state.custom_desc_input +end) + -- *********************************************** -- **============= C O M M A N D S =============** -- *********************************************** -local save_bookmark = ya.sync(function(state, idx) +local save_bookmark = ya.sync(function(state, idx, custom_desc) local file = _get_bookmark_file() state.bookmarks = state.bookmarks or {} @@ -131,10 +135,15 @@ local save_bookmark = ya.sync(function(state, idx) if not _idx then _idx = #state.bookmarks + 1 end + + local bookmark_desc = tostring(file.url) + if custom_desc then + bookmark_desc = tostring(custom_desc) + end state.bookmarks[_idx] = { on = SUPPORTED_KEYS[idx].on, - desc = _generate_description(file), + desc = bookmark_desc, path = tostring(file.url), is_parent = file.is_parent, } @@ -226,6 +235,21 @@ return { if action == "save" then local key = ya.which { cands = SUPPORTED_KEYS, silent = true } if key then + if _is_custom_desc_input_enabled() then + local file = _get_bookmark_file() + local value, event = ya.input { + title = "Save with custom description:", + position = { "top-center", y = 3, w = 60 }, + value = tostring(file.url) + } + if event ~= 1 then + return + end + + save_bookmark(key, value) + return + end + save_bookmark(key) end return @@ -279,6 +303,10 @@ return { state.file_pick_mode = "hover" end + if type(args.custom_desc_input) == "boolean" then + state.custom_desc_input = args.custom_desc_input + end + state.notify = { enable = false, timeout = 1, From a0c829970425187b86343aa4dd3e8b7bfa43430b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linhart=20Luk=C3=A1=C5=A1?= Date: Wed, 19 Feb 2025 22:50:20 +0100 Subject: [PATCH 2/2] formatting --- main.lua | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/main.lua b/main.lua index b9a92a7..920bcb2 100644 --- a/main.lua +++ b/main.lua @@ -118,9 +118,7 @@ local _save_last_directory = ya.sync(function(state, persist) end) end) -local _is_custom_desc_input_enabled = ya.sync(function(state, persist) - return state.custom_desc_input -end) +local _is_custom_desc_input_enabled = ya.sync(function(state) return state.custom_desc_input end) -- *********************************************** -- **============= C O M M A N D S =============** @@ -135,7 +133,7 @@ local save_bookmark = ya.sync(function(state, idx, custom_desc) if not _idx then _idx = #state.bookmarks + 1 end - + local bookmark_desc = tostring(file.url) if custom_desc then bookmark_desc = tostring(custom_desc) @@ -236,11 +234,10 @@ return { local key = ya.which { cands = SUPPORTED_KEYS, silent = true } if key then if _is_custom_desc_input_enabled() then - local file = _get_bookmark_file() local value, event = ya.input { title = "Save with custom description:", position = { "top-center", y = 3, w = 60 }, - value = tostring(file.url) + value = tostring(_get_bookmark_file().url), } if event ~= 1 then return @@ -249,7 +246,6 @@ return { save_bookmark(key, value) return end - save_bookmark(key) end return