Skip to content

Commit

Permalink
fix: unlock buffers if we cancel the actions (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Jan 2, 2023
1 parent f70d796 commit 0d6ee14
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lua/oil/mutator/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,10 @@ M.try_write_changes = function(confirm)
local buffers = view.get_all_buffers()
local all_diffs = {}
local all_errors = {}

local was_modifiable = {}
for _, bufnr in ipairs(buffers) do
was_modifiable[bufnr] = vim.bo[bufnr].modifiable
-- Lock the buffer to prevent race conditions
vim.bo[bufnr].modifiable = false
if vim.bo[bufnr].modified then
Expand All @@ -447,6 +450,11 @@ M.try_write_changes = function(confirm)
end
end
end
local function unlock()
for _, bufnr in ipairs(buffers) do
vim.bo[bufnr].modifiable = was_modifiable[bufnr]
end
end

local ns = vim.api.nvim_create_namespace("Oil")
vim.diagnostic.reset(ns)
Expand All @@ -469,17 +477,17 @@ M.try_write_changes = function(confirm)
vim.api.nvim_win_set_buf(0, bufnr)
pcall(vim.api.nvim_win_set_cursor, 0, { errs[1].lnum + 1, errs[1].col })
end
return
return unlock()
end

local actions = M.create_actions_from_diffs(all_diffs)
disclaimer.show(function(disclaimed)
if not disclaimed then
return
return unlock()
end
preview.show(actions, confirm, function(proceed)
if not proceed then
return
return unlock()
end

M.process_actions(
Expand Down

0 comments on commit 0d6ee14

Please sign in to comment.