From a9e7d700eb546800e3d341bc53667964ac821a38 Mon Sep 17 00:00:00 2001 From: kongjun Date: Tue, 6 May 2025 10:14:39 +0000 Subject: feat: handle the case where the inputsecret() is cancelled --- lua/encrypt/decrypt.lua | 4 ++++ lua/encrypt/encrypt.lua | 4 ++++ lua/encrypt/helpers.lua | 3 +++ 3 files changed, 11 insertions(+) diff --git a/lua/encrypt/decrypt.lua b/lua/encrypt/decrypt.lua index de49019..a1d6b66 100644 --- a/lua/encrypt/decrypt.lua +++ b/lua/encrypt/decrypt.lua @@ -12,6 +12,10 @@ end local function decrypt() local password = helpers.getPassword() + if not password then + vim.notify("Password can not be empty", vim.log.levels.ERROR) + return + end local encrypted_lines = vim.api.nvim_buf_get_lines(0, 1, -1, false) local decrypted_lines = decrypt_lines(encrypted_lines, password) if vim.v.shell_error ~= 0 then diff --git a/lua/encrypt/encrypt.lua b/lua/encrypt/encrypt.lua index 93d2b78..c7efb1f 100644 --- a/lua/encrypt/encrypt.lua +++ b/lua/encrypt/encrypt.lua @@ -12,6 +12,10 @@ end local function encrypt() local password = helpers.getPassword() + if not password then + vim.notify("Password can not be empty", vim.log.levels.ERROR) + return + end local buf_lines = vim.api.nvim_buf_get_lines(0, 0, -1, false) local encrypted_lines = encrypt_lines(buf_lines, password) diff --git a/lua/encrypt/helpers.lua b/lua/encrypt/helpers.lua index b740f28..c88b448 100644 --- a/lua/encrypt/helpers.lua +++ b/lua/encrypt/helpers.lua @@ -6,6 +6,9 @@ local getPasswordFactory = function() local key = string.format("%s", vim.fn.bufnr()) if bufferPasswordMap[key] == nil then password = vim.fn.inputsecret("Enter password: ") + if password == "" then + vim.notify("Password is cancelled", vim.log.levels.WARN) + end bufferPasswordMap[key] = password end return bufferPasswordMap[key] -- cgit v1.2.3