Repository navigation
Expand file tree
/
Copy pathnavigation.lua
More file actions
90 lines (71 loc) · 2.1 KB
/
Copy pathnavigation.lua
File metadata and controls
90 lines (71 loc) · 2.1 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
local M = {}
local state = require('opencode.state')
local output_window = require('opencode.ui.output_window')
local function is_message_header(details)
local icons = require('opencode.ui.icons')
local header_user_icon = icons.get('header_user')
local header_assistant_icon = icons.get('header_assistant')
if not details or not details.virt_text then
return false
end
local first_virt_text = details.virt_text[1]
if not first_virt_text then
return false
end
return first_virt_text[1] == header_user_icon or first_virt_text[1] == header_assistant_icon
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 extmarks = vim.api.nvim_buf_get_extmarks(
buf,
output_window.namespace,
{ current_line, 0 },
-1,
{ details = true }
)
for _, extmark in ipairs(extmarks) do
local line = extmark[2] + 1
local details = extmark[4]
if line > current_line and is_message_header(details) then
vim.api.nvim_win_set_cursor(win, { line, 0 })
return
end
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 extmarks = vim.api.nvim_buf_get_extmarks(
buf,
output_window.namespace,
0,
{ current_line - 1, -1 },
{ details = true }
)
for i = #extmarks, 1, -1 do
local extmark = extmarks[i]
local line = extmark[2] + 1
local details = extmark[4]
if line < current_line and is_message_header(details) then
vim.api.nvim_win_set_cursor(win, { line, 0 })
return
end
end
vim.api.nvim_win_set_cursor(win, { 1, 0 })
end
return M