diff options
| author | kongjun <kongjun18@outlook.com> | 2025-04-29 03:49:28 +0000 |
|---|---|---|
| committer | kongjun <kongjun18@outlook.com> | 2025-04-29 06:52:21 +0000 |
| commit | 6a88d734bdb4660945923c3f4a38c14e45847c2c (patch) | |
| tree | 41598d5759dd40a7c2b75dea85484aefa2ef6d06 /lua/encrypt | |
| parent | 09d7f6ee9ee1d728449131dff4e750e5339f7968 (diff) | |
| download | encrypt.nvim-6a88d734bdb4660945923c3f4a38c14e45847c2c.tar.gz | |
feat: store passwords in a local scope instead of as a buffer variable
Diffstat (limited to 'lua/encrypt')
| -rw-r--r-- | lua/encrypt/helpers.lua | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/lua/encrypt/helpers.lua b/lua/encrypt/helpers.lua index 37a96b3..ff8baef 100644 --- a/lua/encrypt/helpers.lua +++ b/lua/encrypt/helpers.lua @@ -1,13 +1,18 @@ ----@return string -local function getPassword() - local password = vim.b["password"] - if password == nil then - password = vim.fn.inputsecret("Enter password: ") - vim.b["password"] = password +---@return function string +local getPasswordFactory = function() + local bufferPasswordMap = {} + + return function() + local key = string.format("%s", vim.fn.bufnr()) + if bufferPasswordMap[key] == nil then + password = vim.fn.inputsecret("Enter password: ") + bufferPasswordMap[key] = password + end + return bufferPasswordMap[key] end - return password end +local getPassword = getPasswordFactory() local ENCRYPTED_PREFIX = "# <<<encrypted>>>" return { getPassword = getPassword, ENCRYPTED_PREFIX = ENCRYPTED_PREFIX } |
