+49
lua/vcsigns/actions.lua
+49
lua/vcsigns/actions.lua
···
240
fold.toggle(bufnr)
241
end
242
243
+
function M.diffthis(bufnr)
244
+
local diff_win = vim.b[bufnr].vcsigns_diff_win
245
+
if diff_win then
246
+
vim.api.nvim_win_close(diff_win, true)
247
+
vim.b[bufnr].vcsigns_diff_win = nil
248
+
vim.cmd "diffoff"
249
+
return
250
+
end
251
+
252
+
local s = state.get(bufnr)
253
+
local base_lines = s.diff.old_lines
254
+
255
+
-- Open a diff buffer with the base text.
256
+
if not base_lines or #base_lines == 0 then
257
+
vim.notify(
258
+
"Could not get base text from VCS",
259
+
vim.log.levels.ERROR,
260
+
{ title = "VCSigns" }
261
+
)
262
+
return
263
+
end
264
+
local diff_buf = vim.api.nvim_create_buf(false, true)
265
+
vim.api.nvim_buf_set_lines(diff_buf, 0, -1, false, base_lines)
266
+
267
+
-- Open the diff buffer in a new window.
268
+
local win = vim.api.nvim_open_win(diff_buf, false, {
269
+
split = "right",
270
+
win = 0,
271
+
})
272
+
-- TODO(algmyr): Store this in the state module.
273
+
vim.b[bufnr].vcsigns_diff_win = win
274
+
275
+
-- Sync the filetype and syntax.
276
+
vim.bo[diff_buf].filetype = vim.bo[bufnr].filetype
277
+
278
+
vim.bo[diff_buf].buftype = "nofile"
279
+
vim.bo[diff_buf].bufhidden = "wipe"
280
+
vim.bo[diff_buf].swapfile = false
281
+
vim.bo[diff_buf].modifiable = false
282
+
vim.wo[win].foldcolumn = "0"
283
+
284
+
-- Run diffthis in both windows.
285
+
local current = vim.api.nvim_get_current_win()
286
+
vim.api.nvim_set_current_win(win)
287
+
vim.cmd "diffthis"
288
+
vim.api.nvim_set_current_win(current)
289
+
vim.cmd "diffthis"
290
+
end
291
+
292
return M
+1
lua/vcsigns/init.lua
+1
lua/vcsigns/init.lua