|
1 | 1 | local assert = require('luassert') |
2 | 2 | local store = require('opencode.state.store') |
| 3 | +local default_gg = require('opencode.config').defaults.keymap.output_window.gg |
3 | 4 |
|
4 | 5 | describe('opencode.keymap', function() |
5 | 6 | local set_keymaps = {} |
@@ -65,6 +66,7 @@ describe('opencode.keymap', function() |
65 | 66 | mock_commands = { |
66 | 67 | get_commands = function() |
67 | 68 | return { |
| 69 | + first_message = { desc = 'Load history and go to the first message', execute = function() end }, |
68 | 70 | open_input = { desc = 'Open input window', execute = function() end }, |
69 | 71 | toggle = { desc = 'Toggle opencode windows', execute = function() end }, |
70 | 72 | submit_input_prompt = { desc = 'Submit input prompt', execute = function() end }, |
@@ -155,6 +157,40 @@ describe('opencode.keymap', function() |
155 | 157 | end |
156 | 158 | end |
157 | 159 |
|
| 160 | + it('installs the default gg action and restores it without replacing a custom mapping', function() |
| 161 | + vim.keymap.set = original_keymap_set |
| 162 | + keymap.setup({ output_window = { gg = default_gg } }) |
| 163 | + local windows = panel() |
| 164 | + store.set('windows', windows) |
| 165 | + assert.is_true(vim.wait(200, function() |
| 166 | + return mapping(windows.output_buf, 'gg') ~= nil |
| 167 | + end)) |
| 168 | + mapping(windows.output_buf, 'gg').callback() |
| 169 | + assert.equals('first_message', executed_parsed[1].intent.name) |
| 170 | + |
| 171 | + vim.keymap.del('n', 'gg', { buffer = windows.output_buf }) |
| 172 | + store.set('windows', nil) |
| 173 | + store.set('windows', windows) |
| 174 | + assert.is_true(vim.wait(200, function() |
| 175 | + return mapping(windows.output_buf, 'gg') ~= nil |
| 176 | + end)) |
| 177 | + original_keymap_set('n', 'gg', function() end, { buffer = windows.output_buf, desc = 'Custom gg' }) |
| 178 | + store.set('windows', nil) |
| 179 | + store.set('windows', windows) |
| 180 | + local drained = false |
| 181 | + vim.schedule(function() drained = true end) |
| 182 | + assert.is_true(vim.wait(200, function() return drained end)) |
| 183 | + assert.equals('Custom gg', mapping(windows.output_buf, 'gg').desc) |
| 184 | + end) |
| 185 | + |
| 186 | + it('does not install gg when disabled', function() |
| 187 | + vim.keymap.set = original_keymap_set |
| 188 | + local windows = panel() |
| 189 | + store.set_raw('windows', windows) |
| 190 | + keymap.setup({ output_window = { gg = false } }) |
| 191 | + assert.is_nil(mapping(windows.output_buf, 'gg')) |
| 192 | + end) |
| 193 | + |
158 | 194 | it('binds new panels and restores missing mappings without replacing custom or window mappings', function() |
159 | 195 | vim.keymap.set = original_keymap_set |
160 | 196 | keymap.setup({ |
|
0 commit comments