|
1 | 1 | local state = require('opencode.state') |
2 | 2 | local config = require('opencode.config') |
| 3 | +local ui = require('opencode.ui.ui') |
3 | 4 |
|
4 | 5 | describe('cursor persistence (state)', function() |
5 | 6 | before_each(function() |
@@ -239,3 +240,47 @@ describe('renderer.scroll_to_bottom', function() |
239 | 240 | config.values.ui.output.always_scroll_to_bottom = false |
240 | 241 | end) |
241 | 242 | end) |
| 243 | + |
| 244 | +describe('ui.focus_input', function() |
| 245 | + local input_buf, output_buf, input_win, output_win |
| 246 | + |
| 247 | + before_each(function() |
| 248 | + input_buf = vim.api.nvim_create_buf(false, true) |
| 249 | + output_buf = vim.api.nvim_create_buf(false, true) |
| 250 | + vim.api.nvim_buf_set_lines(input_buf, 0, -1, false, { 'abcde' }) |
| 251 | + vim.api.nvim_buf_set_lines(output_buf, 0, -1, false, { 'output' }) |
| 252 | + |
| 253 | + output_win = vim.api.nvim_open_win(output_buf, true, { |
| 254 | + relative = 'editor', width = 40, height = 5, row = 0, col = 0, |
| 255 | + }) |
| 256 | + input_win = vim.api.nvim_open_win(input_buf, true, { |
| 257 | + relative = 'editor', width = 40, height = 5, row = 6, col = 0, |
| 258 | + }) |
| 259 | + |
| 260 | + state.windows = { |
| 261 | + input_win = input_win, |
| 262 | + output_win = output_win, |
| 263 | + input_buf = input_buf, |
| 264 | + output_buf = output_buf, |
| 265 | + } |
| 266 | + state.last_input_window_position = { 1, 4 } |
| 267 | + end) |
| 268 | + |
| 269 | + after_each(function() |
| 270 | + pcall(vim.api.nvim_win_close, input_win, true) |
| 271 | + pcall(vim.api.nvim_win_close, output_win, true) |
| 272 | + pcall(vim.api.nvim_buf_delete, input_buf, { force = true }) |
| 273 | + pcall(vim.api.nvim_buf_delete, output_buf, { force = true }) |
| 274 | + state.windows = nil |
| 275 | + state.last_input_window_position = nil |
| 276 | + end) |
| 277 | + |
| 278 | + it('does not restore cursor when already focused in input window', function() |
| 279 | + vim.api.nvim_set_current_win(input_win) |
| 280 | + vim.api.nvim_win_set_cursor(input_win, { 1, 2 }) |
| 281 | + |
| 282 | + ui.focus_input({ restore_position = true, start_insert = false }) |
| 283 | + |
| 284 | + assert.same({ 1, 2 }, vim.api.nvim_win_get_cursor(input_win)) |
| 285 | + end) |
| 286 | +end) |
0 commit comments