Make chat windows read only

This commit is contained in:
Jonas Widen 2025-03-16 21:01:26 +01:00
parent a4d9f2e1e3
commit 5df3802fdb

View File

@ -122,35 +122,18 @@ end
local function setup_buffer_keymaps(bufnr) local function setup_buffer_keymaps(bufnr)
local opts = { buffer = bufnr, nowait = true, silent = true } local opts = { buffer = bufnr, nowait = true, silent = true }
-- Block ALL leader key combinations -- Block ALL leader key combinations - this is the key fix!
vim.keymap.set({'n', 'v'}, '<leader>', function() vim.keymap.set({'n', 'v'}, '<leader>', function()
vim.notify('Leader key commands are disabled in chat window', vim.log.levels.WARN) vim.notify('Leader key commands are disabled in chat window', vim.log.levels.WARN)
return '<Esc>' return '<Esc>'
end, opts) end, opts)
-- Disable ALL commands -- Disable command mode
vim.keymap.set('n', ':', function() vim.keymap.set('n', ':', function()
vim.notify('Commands are disabled in chat window', vim.log.levels.WARN) vim.notify('Commands are disabled in chat window', vim.log.levels.WARN)
return '<Esc>' return '<Esc>'
end, opts) end, opts)
-- Block ALL normal mode key combinations that could manipulate files
local blocked_keys = {
'ZZ', 'ZQ', 'gf', '<C-w>f', '<C-w>gf', '<C-w>F',
'<C-w>v', '<C-w>s', '<C-w>n', '<C-^>', '<C-6>',
'<C-w>^', '<C-w>6', 'gF', '<C-w>gF',
'<C-w>o', '<C-w>T', '<C-w>H', '<C-w>J', '<C-w>K', '<C-w>L',
-- Add specific telescope/file finder bindings
'<leader>sf', '<leader>ff', '<leader>fg',
}
for _, key in ipairs(blocked_keys) do
vim.keymap.set({'n', 'v', 'i'}, key, function()
vim.notify('Operation not allowed in chat window', vim.log.levels.WARN)
return '<Esc>'
end, opts)
end
-- Only allow specific keymaps for chat functionality -- Only allow specific keymaps for chat functionality
local mappings = config.options.mappings local mappings = config.options.mappings
vim.keymap.set('n', mappings.close, function() vim.keymap.set('n', mappings.close, function()
@ -166,14 +149,11 @@ local function setup_buffer_keymaps(bufnr)
require("gemini").prompt_query(state.current_context) require("gemini").prompt_query(state.current_context)
end, opts) end, opts)
-- Allow only basic navigation -- Allow basic navigation
local allowed_keys = {'j', 'k', '<C-d>', '<C-u>', '<C-f>', '<C-b>', 'G', 'gg'} local allowed_keys = {'j', 'k', '<C-d>', '<C-u>', '<C-f>', '<C-b>', 'G', 'gg'}
for _, key in ipairs(allowed_keys) do for _, key in ipairs(allowed_keys) do
vim.keymap.set('n', key, key, opts) vim.keymap.set('n', key, key, opts)
end end
-- Block all other keys
vim.keymap.set({'n', 'v', 'i'}, '<Space>', '<Nop>', opts)
end end
function M.create_window() function M.create_window()