Repository navigation
Expand file tree
/
Copy pathnavigation.lua
More file actions
64 lines (51 loc) · 1.7 KB
/
Copy pathnavigation.lua
File metadata and controls
64 lines (51 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
local M = {}
local state = require('opencode.state')
local renderer = require('opencode.ui.renderer')
function M.goto_message_by_id(message_id)
require('opencode.ui.ui').focus_output()
local windows = state.windows or {}
local win = windows.output_win
local buf = windows.output_buf
if not win or not buf then
return
end
local rendered_msg = renderer.get_rendered_message(message_id)
if not rendered_msg or not rendered_msg.line_start then
return
end
vim.api.nvim_win_set_cursor(win, { rendered_msg.line_start + 1, 0 })
end
function M.goto_next_message()
require('opencode.ui.ui').focus_output()
local windows = state.windows or {}
local win = windows.output_win
local buf = windows.output_buf
if not win or not buf then
return
end
local current_line = vim.api.nvim_win_get_cursor(win)[1]
local next_message = renderer.get_next_rendered_message(current_line)
if next_message and next_message.line_start then
vim.api.nvim_win_set_cursor(win, { next_message.line_start + 1, 0 })
return
end
local line_count = vim.api.nvim_buf_line_count(buf)
vim.api.nvim_win_set_cursor(win, { line_count, 0 })
end
function M.goto_prev_message()
require('opencode.ui.ui').focus_output()
local windows = state.windows or {}
local win = windows.output_win
local buf = windows.output_buf
if not win or not buf then
return
end
local current_line = vim.api.nvim_win_get_cursor(win)[1]
local previous_message = renderer.get_prev_rendered_message(current_line)
if previous_message and previous_message.line_start then
vim.api.nvim_win_set_cursor(win, { previous_message.line_start + 1, 0 })
return
end
vim.api.nvim_win_set_cursor(win, { 1, 0 })
end
return M