Make chat windows read only
This commit is contained in:
parent
9aa2236989
commit
e7b9bc1e2c
@ -29,6 +29,7 @@ local function setup_buffer_options(bufnr)
|
||||
swapfile = false,
|
||||
bufhidden = 'wipe',
|
||||
modifiable = false,
|
||||
readonly = true, -- Add readonly option
|
||||
}
|
||||
|
||||
for option, value in pairs(options) do
|
||||
@ -38,7 +39,9 @@ end
|
||||
|
||||
local function setup_buffer_autocmds(bufnr)
|
||||
local augroup = vim.api.nvim_create_augroup('GeminiChatBuffer', { clear = true })
|
||||
vim.api.nvim_create_autocmd({'BufReadCmd', 'FileReadCmd', 'BufWriteCmd'}, {
|
||||
|
||||
-- Block all file operations
|
||||
vim.api.nvim_create_autocmd({'BufReadCmd', 'FileReadCmd', 'BufWriteCmd', 'FileWriteCmd'}, {
|
||||
group = augroup,
|
||||
buffer = bufnr,
|
||||
callback = function()
|
||||
@ -46,25 +49,43 @@ local function setup_buffer_autocmds(bufnr)
|
||||
return true
|
||||
end
|
||||
})
|
||||
|
||||
-- Prevent dropping files into the buffer
|
||||
vim.api.nvim_create_autocmd('BufEnter', {
|
||||
group = augroup,
|
||||
buffer = bufnr,
|
||||
callback = function()
|
||||
vim.opt_local.modifiable = false
|
||||
vim.opt_local.readonly = true
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
local function setup_buffer_keymaps(bufnr)
|
||||
local opts = { buffer = bufnr, nowait = true }
|
||||
local opts = { buffer = bufnr, nowait = true, silent = true }
|
||||
|
||||
-- Disable ALL file operations
|
||||
local operations = {
|
||||
'e', 'edit', 'w', 'write', 'sp', 'split', 'vs', 'vsplit',
|
||||
'new', 'vnew', 'read', 'update', 'saveas', 'f', 'file',
|
||||
'wq', 'wqa', 'wa', 'wall', 'q', 'quit', 'qa', 'qall'
|
||||
}
|
||||
|
||||
-- Disable file operations
|
||||
local operations = {'e', 'edit', 'w', 'write', 'sp', 'split', 'vs', 'vsplit',
|
||||
'new', 'vnew', 'read', 'update', 'saveas'}
|
||||
for _, op in ipairs(operations) do
|
||||
vim.keymap.set('n', ':' .. op, function()
|
||||
vim.notify('Operation not allowed in chat window', vim.log.levels.WARN)
|
||||
end, opts)
|
||||
end
|
||||
|
||||
-- Disable command mode
|
||||
-- Disable command mode completely
|
||||
vim.keymap.set('n', ':', function()
|
||||
vim.notify('Command mode disabled in chat window', vim.log.levels.WARN)
|
||||
end, opts)
|
||||
|
||||
-- Block common file operation key combinations
|
||||
vim.keymap.set('n', 'ZZ', '<Nop>', opts)
|
||||
vim.keymap.set('n', 'ZQ', '<Nop>', opts)
|
||||
|
||||
-- Set chat-specific keymaps
|
||||
local mappings = config.options.mappings
|
||||
vim.keymap.set('n', mappings.close, function()
|
||||
|
Loading…
x
Reference in New Issue
Block a user