diff options
| author | kongjun <kongjun18@outlook.com> | 2025-04-29 04:05:35 +0000 |
|---|---|---|
| committer | kongjun <kongjun18@outlook.com> | 2025-04-29 06:55:46 +0000 |
| commit | e6057b3c13f004477f4963f3cdf054e5ca1bf2f4 (patch) | |
| tree | 3fc89e4d9234a7f6b9b230204c27375849b97685 /lua/encrypt/setup-buffer.lua | |
| parent | 6a88d734bdb4660945923c3f4a38c14e45847c2c (diff) | |
| download | encrypt.nvim-e6057b3c13f004477f4963f3cdf054e5ca1bf2f4.tar.gz | |
feat: lock the encrypted file to read-only mode to avoid unintended corruption
Diffstat (limited to 'lua/encrypt/setup-buffer.lua')
| -rw-r--r-- | lua/encrypt/setup-buffer.lua | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lua/encrypt/setup-buffer.lua b/lua/encrypt/setup-buffer.lua index 8b950ec..e03f71c 100644 --- a/lua/encrypt/setup-buffer.lua +++ b/lua/encrypt/setup-buffer.lua @@ -1,4 +1,5 @@ local encrypt = require("encrypt.encrypt") +local helpers = require("encrypt.helpers") local function createWriteAutoCmd() if vim.b["encryptionAutoCmd"] ~= nil then @@ -18,12 +19,18 @@ local function createWriteAutoCmd() }) end -local function setupBuffer() +---@param buftype buftype +local function setupBuffer(buftype) -- buftype="acwrite" means save using the BufWriteCmd command vim.bo.buftype = "acwrite" vim.bo.swapfile = false vim.bo.undofile = false vim.b["encrypted"] = true + -- Lock the encrypted file to read-only mode to avoid corruption + -- caused by unintended modifications. + if buftype == helpers.BUFTYPE.encrypted then + vim.bo.modifiable = false + end createWriteAutoCmd() end |
