Skip to content

Commit 9035caf

Browse files
committed
feat(ui/renderer): question navigation and flush
1 parent d6fe72c commit 9035caf

15 files changed

Lines changed: 2562 additions & 1092 deletions

lua/opencode/ui/dialog.lua

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -232,36 +232,24 @@ function Dialog:format_legend(output, options)
232232
end
233233

234234
if keymaps.up and #keymaps.up > 0 and keymaps.down and #keymaps.down > 0 then
235-
local line = output:add_line(string.format('Move: j/k or %s/%s', '', ''))
236-
output:add_extmark(line - 1, { start_col = 6, end_col = 9, hl_group = 'OpencodeQuestionKeyHint' } --[[@as OutputExtmark]])
237-
output:add_extmark(line - 1, { start_col = 13, end_col = 16, hl_group = 'OpencodeQuestionKeyHint' } --[[@as OutputExtmark]])
235+
local line = output:add_line('Move: `j/k` or `↑/↓`')
238236
end
239237

240238
if keymaps.left and #keymaps.left > 0 and keymaps.right and #keymaps.right > 0 then
241-
local line = output:add_line('Question: h/l or <-/->')
242-
output:add_extmark(line - 1, { start_col = 10, end_col = 13, hl_group = 'OpencodeQuestionKeyHint' } --[[@as OutputExtmark]])
243-
output:add_extmark(line - 1, { start_col = 17, end_col = 23, hl_group = 'OpencodeQuestionKeyHint' } --[[@as OutputExtmark]])
239+
local line = output:add_line('Question: `h/l` or `<-/->`')
244240
end
245241

246242
if keymaps.select and keymaps.select ~= '' then
247-
local select_text = 'Select: <CR>'
243+
local select_text = 'Select: `<CR>`'
248244
if keymaps.number_shortcuts and option_count > 0 then
249245
local max_shortcut = math.min(option_count, 9)
250-
select_text = select_text .. string.format(' or 1-%d', max_shortcut)
246+
select_text = select_text .. string.format(' or `1-%d`', max_shortcut)
251247
end
252248
local line = output:add_line(select_text)
253-
output:add_extmark(line - 1, { start_col = 8, end_col = 12, hl_group = 'OpencodeQuestionKeyHint' } --[[@as OutputExtmark]])
254-
if keymaps.number_shortcuts and option_count > 0 then
255-
local max_shortcut = math.min(option_count, 9)
256-
local suffix = string.format('1-%d', max_shortcut)
257-
local start_col = #select_text - #suffix
258-
output:add_extmark(line - 1, { start_col = start_col, end_col = #select_text, hl_group = 'OpencodeQuestionKeyHint' } --[[@as OutputExtmark]])
259-
end
260249
end
261250

262251
if keymaps.dismiss and keymaps.dismiss ~= '' then
263-
local line = output:add_line('Close: <Esc>')
264-
output:add_extmark(line - 1, { start_col = 7, end_col = 12, hl_group = 'OpencodeQuestionKeyHint' } --[[@as OutputExtmark]])
252+
local line = output:add_line('Close: `<Esc>`')
265253
end
266254
else
267255
local message = options.unfocused_message or 'Focus Opencode window to interact'

lua/opencode/ui/question_window.lua

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,10 @@ local function get_question_part(question_request)
159159

160160
if question_request and question_request.sessionID and question_request.sessionID ~= '' then
161161
local render_state = require('opencode.ui.renderer.ctx').render_state
162-
return find_matching_question_part(render_state:get_child_session_parts(question_request.sessionID), question_request)
162+
return find_matching_question_part(
163+
render_state:get_child_session_parts(question_request.sessionID),
164+
question_request
165+
)
163166
end
164167
end
165168

@@ -226,14 +229,16 @@ function M.restore_pending_question(session_id)
226229
M.clear_question()
227230
end
228231

229-
return state.api_client:list_questions()
232+
return state.api_client
233+
:list_questions()
230234
:and_then(function(requests)
231235
if not requests or type(requests) ~= 'table' then
232236
return
233237
end
234238

235239
for _, request in ipairs(requests) do
236-
if request
240+
if
241+
request
237242
and request.questions
238243
and #request.questions > 0
239244
and M.belongs_to_active_session(request)
@@ -385,8 +390,8 @@ local function format_question_tabs(output)
385390
local label = question.header ~= '' and question.header or ('Q' .. i)
386391
local is_active = i == M._current_question_index
387392
local is_done = get_answer_for_index(i) ~= nil
388-
local marker = is_done and 'x' or ' '
389-
local segment = string.format(' %d [%s] %s ', i, marker, label)
393+
local marker = is_done and icons.get('completed') or ' '
394+
local segment = string.format(' %d [%s] %s ', i, label, marker)
390395

391396
if #line > 0 then
392397
line = line .. ' '

lua/opencode/ui/renderer/ctx.lua

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,17 @@ function ctx:bulk_reset()
6767
self.bulk_folds = {}
6868
end
6969

70+
---@param pending? RendererCtx['pending']
71+
---@return boolean
72+
function ctx:has_pending_work(pending)
73+
pending = pending or self.pending
74+
75+
return self.flush_scheduled
76+
or self.bulk_mode
77+
or #pending.dirty_message_order > 0
78+
or #pending.dirty_part_order > 0
79+
or #pending.removed_part_order > 0
80+
or #pending.removed_message_order > 0
81+
end
82+
7083
return ctx

lua/opencode/ui/renderer/flush.lua

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,7 @@ local function apply_pending(pending)
402402
return false
403403
end
404404

405-
local has_updates = #pending.removed_part_order > 0
406-
or #pending.removed_message_order > 0
407-
or #pending.dirty_message_order > 0
408-
or #pending.dirty_part_order > 0
405+
local has_updates = ctx:has_pending_work(pending)
409406

410407
if not has_updates then
411408
return false

0 commit comments

Comments
 (0)