Skip to content

Commit 7121f13

Browse files
committed
feat(context-bar): align the bar to the right
With the bar aligned to the right there is no need for the icon anymore
1 parent 5994f0f commit 7121f13

File tree

4 files changed

+7
-52
lines changed

4 files changed

+7
-52
lines changed

lua/opencode/ui/context_bar.lua

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,7 @@ end
4646

4747
local function create_winbar_segments()
4848
local ctx = context.delta_context()
49-
local segments = {
50-
{
51-
icon = icons.get('context'),
52-
text = '',
53-
highlight = 'OpencodeContext',
54-
},
55-
}
49+
local segments = {}
5650

5751
local current_file = get_current_file_info(ctx)
5852
if context.is_context_enabled('current_file') and current_file then
@@ -127,8 +121,9 @@ local function create_winbar_segments()
127121
end
128122

129123
local function format_winbar_text(segments)
124+
local right_align = '%='
130125
if #segments == 0 then
131-
return ''
126+
return right_align
132127
end
133128

134129
local parts = {}
@@ -144,7 +139,7 @@ local function format_winbar_text(segments)
144139
end
145140
end
146141

147-
return ' ' .. table.concat(parts, '')
142+
return right_align .. table.concat(parts, '')
148143
end
149144

150145
local function update_winbar_highlights(win_id)

lua/opencode/ui/icons.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ local presets = {
3333
border = '',
3434
-- context bar
3535
cursor_data = '󰗧 ',
36-
context = '',
3736
error = '',
3837
warning = '',
3938
info = '',
@@ -69,7 +68,6 @@ local presets = {
6968
border = '',
7069
-- context bar
7170
cursor_data = '[|] ',
72-
context = '[Ctx] ',
7371
error = '[E]',
7472
warning = '[W]',
7573
info = '[I] ',

lua/opencode/ui/input_window.lua

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ function M.setup(windows)
112112
M.recover_input(windows)
113113

114114
require('opencode.ui.context_bar').render(windows)
115-
116-
M.add_winbar_padding(windows)
117115
end
118116

119117
function M.update_dimensions(windows)
@@ -198,7 +196,6 @@ function M.set_content(text, windows)
198196
local lines = type(text) == 'table' and text or vim.split(tostring(text), '\n')
199197

200198
vim.api.nvim_buf_set_lines(windows.input_buf, 0, -1, false, lines)
201-
M.add_winbar_padding(windows)
202199
end
203200

204201
function M.set_current_line(text, windows)
@@ -208,7 +205,6 @@ function M.set_current_line(text, windows)
208205
end
209206

210207
vim.api.nvim_set_current_line(text)
211-
M.add_winbar_padding(windows)
212208
end
213209

214210
function M.remove_mention(mention_name, windows)
@@ -229,7 +225,6 @@ function M.remove_mention(mention_name, windows)
229225

230226
vim.api.nvim_buf_set_lines(windows.input_buf, 0, -1, false, lines)
231227
require('opencode.ui.mention').highlight_all_mentions(windows.input_buf)
232-
M.add_winbar_padding(windows)
233228
end
234229

235230
function M.is_empty()
@@ -242,34 +237,6 @@ function M.is_empty()
242237
return #lines == 0 or (#lines == 1 and lines[1] == '')
243238
end
244239

245-
function M.add_winbar_padding(windows)
246-
if not M.mounted(windows) then
247-
return
248-
end
249-
250-
local ns_id = vim.api.nvim_create_namespace('winbar_padding')
251-
vim.api.nvim_buf_clear_namespace(windows.input_buf, ns_id, 0, -1)
252-
253-
vim.api.nvim_buf_set_extmark(windows.input_buf, ns_id, 0, 0, {
254-
virt_lines = { { { ' ' } } },
255-
virt_lines_above = true,
256-
})
257-
258-
M.apply_topfill_workaround(windows)
259-
end
260-
261-
function M.apply_topfill_workaround(windows)
262-
if not M.mounted(windows) then
263-
return
264-
end
265-
266-
local topfill = 1
267-
local win = windows.input_win
268-
if win and vim.api.nvim_win_is_valid(win) then
269-
vim.fn.win_execute(win, 'lua vim.fn.winrestview({ topfill = ' .. topfill .. ' })')
270-
end
271-
end
272-
273240
function M.setup_keymaps(windows)
274241
local keymap = require('opencode.keymap')
275242
keymap.setup_window_keymaps(config.keymap.input_window, windows.input_buf)
@@ -283,7 +250,6 @@ function M.setup_autocmds(windows, group)
283250
M.refresh_placeholder(windows)
284251
state.last_focused_opencode_window = 'input'
285252
require('opencode.ui.context_bar').render()
286-
M.apply_topfill_workaround(windows)
287253
end,
288254
})
289255

@@ -294,9 +260,6 @@ function M.setup_autocmds(windows, group)
294260
state.input_content = input_lines
295261
M.refresh_placeholder(windows, input_lines)
296262
require('opencode.ui.context_bar').render()
297-
if #input_lines == 0 or (#input_lines == 1 and input_lines[1] == '') then
298-
M.add_winbar_padding(windows)
299-
end
300263
end,
301264
})
302265

tests/unit/context_bar_spec.lua

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ describe('opencode.ui.context_bar', function()
9595
end)
9696

9797
after_each(function()
98-
-- Restore original functions
9998
context.delta_context = original_delta_context
10099
context.is_context_enabled = original_is_context_enabled
101100
icons.get = original_get_icon
@@ -109,15 +108,15 @@ describe('opencode.ui.context_bar', function()
109108
end)
110109

111110
describe('opencode.ui.context_bar', function()
112-
it('renders minimal winbar with context icon only', function()
111+
it('renders minimal winbar with right aligh token only', function()
113112
local mock_input_win = 2001
114113
local winbar_capture = create_mock_window(mock_input_win)
115114

116115
state.windows = { input_win = mock_input_win }
117116
context_bar.render()
118117

119118
assert.is_string(winbar_capture.value)
120-
assert.is_not_nil(winbar_capture.value:find(icons.get('context')))
119+
assert.is_equal(winbar_capture.value, '%=')
121120
end)
122121

123122
it('renders winbar with current file when present', function()
@@ -207,7 +206,7 @@ describe('opencode.ui.context_bar', function()
207206
context_bar.render()
208207

209208
assert.is_string(winbar_capture.value)
210-
assert.is_not_nil(winbar_capture.value:find(icons.get('context'))) -- Should still have context icon
209+
assert.is_equal(winbar_capture.value, '%=')
211210
end)
212211

213212
it('does nothing when window is invalid', function()

0 commit comments

Comments
 (0)