Skip to content

Commit cf289a4

Browse files
authored
refactor(renderer): remove dead pinned-overlay scroll short-circuit (#463)
* refactor(renderer): remove dead pinned-overlay scroll short-circuit * fix: another case * chore: simplify * chore: dead code * chore: is_new_part seems not needed here * chore: cleanup
1 parent f9bf2da commit cf289a4

12 files changed

Lines changed: 23 additions & 106 deletions

File tree

lua/opencode/state/store.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ local _state = {
6161
pre_zoom_width = nil,
6262
last_window_width_ratio = nil,
6363
last_sent_context = nil,
64-
current_context_config = {},
64+
current_context_config = nil,
6565
context_updated_at = nil,
6666
active_session = nil,
6767
restore_points = {},

lua/opencode/state/ui.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ function M.get_window_cursor(win_id)
268268
return nil
269269
end
270270

271-
return normalize_cursor(pos)
271+
return pos
272272
end
273273

274274
---@param win_type 'input'|'output'

lua/opencode/types.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@
316316
---@field capture_streamed_events boolean
317317
---@field show_ids boolean
318318
---@field highlight_changed_lines boolean
319-
---@field highlight_changed_lines_timeout_ms number
319+
---@field highlight_changed_lines_timeout_ms integer
320320
---@field quick_chat {keep_session: boolean, set_active_session: boolean}
321321

322322
---@alias OpencodeCommandLifecycleStage 'before'|'after'|'error'|'finally'

lua/opencode/ui/formatter.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,7 @@ function M.format_message_header(message, previous_message)
285285
local current_mode = message.info.mode or state.current_mode
286286
same_mode_as_previous = previous_role == 'assistant'
287287
and current_mode
288-
and previous_mode
289288
and current_mode ~= ''
290-
and previous_mode ~= ''
291289
and current_mode == previous_mode
292290
end
293291

lua/opencode/ui/input_window.lua

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,6 @@ function M.handle_submit()
133133

134134
local input_content = table.concat(vim.api.nvim_buf_get_lines(windows.input_buf, 0, -1, false), '\n')
135135
vim.api.nvim_buf_set_lines(windows.input_buf, 0, -1, false, {})
136-
vim.api.nvim_exec_autocmds('TextChanged', {
137-
buffer = windows.input_buf,
138-
modeline = false,
139-
})
140136

141137
if input_content == '' then
142138
return false

lua/opencode/ui/output.lua

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,15 @@
11
local config = require('opencode.config')
22

3-
local Output = {}
4-
Output.__index = Output
5-
63
---@class Output
74
---@field lines string[]
85
---@field extmarks table<number, OutputExtmark[]>
96
---@field actions OutputAction[]
107
---@field targets OutputTarget[]
11-
---@field add_line fun(self: Output, line: string, fit?: boolean): number
12-
---@field get_line fun(self: Output, idx: number): string?
13-
---@field merge_line fun(self: Output, idx: number, text: string)
14-
---@field add_lines fun(self: Output, lines: string[], prefix?: string)
15-
---@field add_empty_line fun(self: Output): number?
16-
---@field clear fun(self: Output)
17-
---@field get_line_count fun(self: Output): number
18-
---@field get_lines fun(self: Output): string[]
19-
---@field add_extmark fun(self: Output, idx: number, extmark: OutputExtmark|fun(): OutputExtmark)
20-
---@field get_extmarks fun(self: Output): table<number, table[]>
21-
---@field add_actions fun(self: Output, actions: OutputAction[])
22-
---@field add_action fun(self: Output, action: OutputAction)
23-
---@field get_actions_for_line fun(self: Output, line: number): OutputAction[]?
24-
---@field add_target fun(self: Output, target: OutputTarget)
25-
---@field add_targets fun(self: Output, targets: OutputTarget[])
26-
---@return self Output
8+
---@field fold_ranges {from: integer, to: integer}[]
9+
local Output = {}
10+
Output.__index = Output
11+
12+
---@return Output
2713
function Output.new()
2814
local self = setmetatable({}, Output)
2915
self.lines = {}

lua/opencode/ui/output_window.lua

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -627,13 +627,12 @@ function M.highlight_changed_lines(start_line, end_line)
627627
local last = math.max(first, end_line)
628628

629629
vim.api.nvim_buf_clear_namespace(buf, M.debug_namespace, first, last + 1)
630-
for line = first, last do
631-
vim.api.nvim_buf_set_extmark(buf, M.debug_namespace, line, 0, {
632-
line_hl_group = 'OpencodeChangedLines',
633-
hl_eol = true,
634-
priority = 250,
635-
})
636-
end
630+
vim.api.nvim_buf_set_extmark(buf, M.debug_namespace, first, 0, {
631+
end_row = last,
632+
line_hl_group = 'OpencodeChangedLines',
633+
hl_eol = true,
634+
priority = 250,
635+
})
637636

638637
vim.defer_fn(function()
639638
if vim.api.nvim_buf_is_valid(buf) then

lua/opencode/ui/permission_window.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,15 @@ end
103103

104104
---Update permission from message part data
105105
---@param permission_id string
106-
---@param part table
106+
---@param part OpencodeMessagePart
107107
---@return boolean
108108
function M.update_permission_from_part(permission_id, part)
109109
if not permission_id or not part then
110110
return false
111111
end
112112

113113
local permission = nil
114-
for i, existing in ipairs(M._permission_queue) do
114+
for _, existing in ipairs(M._permission_queue) do
115115
if existing.id == permission_id then
116116
permission = existing
117117
break
@@ -244,7 +244,7 @@ function M.format_display(output)
244244
title = icons.get('warning') .. ' Permission Required' .. progress,
245245
title_hl = 'OpencodePermissionTitle',
246246
border_hl = 'OpencodePermissionBorder',
247-
content = render_content and nil or content,
247+
content = content,
248248
render_content = render_content,
249249
options = options,
250250
unfocused_message = 'Focus Opencode window to respond to permission',

lua/opencode/ui/render_state.lua

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,9 @@ end
212212
---@param message_id string
213213
---@return RenderedMessage?
214214
function RenderState:get_previous_message(messages, message_id)
215-
for i = #messages, 1, -1 do
215+
for i = #messages, 2, -1 do
216216
local message = messages[i]
217217
if message and message.info and message.info.id == message_id then
218-
if i <= 1 then
219-
return nil
220-
end
221218
local previous_message = messages[i - 1]
222219
return previous_message and previous_message.info and self._messages[previous_message.info.id] or nil
223220
end

lua/opencode/ui/renderer/events.lua

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ function M.on_part_updated(properties, revert_index)
380380
local is_new_part = not part_data
381381

382382
local prev_last_part_id = get_last_part_for_message(message)
383-
local existing_part_index = nil
383+
local existing_part_index = nil ---@type integer?
384384
for i = #message.parts, 1, -1 do
385385
if message.parts[i].id == part.id then
386386
existing_part_index = i
@@ -391,7 +391,7 @@ function M.on_part_updated(properties, revert_index)
391391
-- Preserve state.input when the update omits it. MCP tool completion
392392
-- events sometimes arrive with an empty input table, clobbering the
393393
-- call arguments from the earlier running event.
394-
if part.state and part.state.input and type(part.state.input) == 'table' and next(part.state.input) == nil then
394+
if part.state and type(part.state.input) == 'table' and next(part.state.input) == nil then
395395
local old_input = nil
396396
if existing_part_index then
397397
old_input = message.parts[existing_part_index]
@@ -407,24 +407,7 @@ function M.on_part_updated(properties, revert_index)
407407
end
408408

409409
-- Update the part reference in the message
410-
if is_new_part then
411-
if existing_part_index then
412-
message.parts[existing_part_index] = part
413-
else
414-
table.insert(message.parts, part)
415-
end
416-
else
417-
if existing_part_index then
418-
message.parts[existing_part_index] = part
419-
else
420-
for i = #message.parts, 1, -1 do
421-
if message.parts[i].id == part.id then
422-
message.parts[i] = part
423-
break
424-
end
425-
end
426-
end
427-
end
410+
message.parts[existing_part_index or #message.parts + 1] = part
428411

429412
if part.type == 'step-start' or part.type == 'step-finish' then
430413
if part.type == 'step-finish' and part.tokens then

0 commit comments

Comments
 (0)