repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

fix(cmdline): strip leading firstc from cmdline info for format detection

998bbe5336edab323028aede255c0f08b20fd521

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

The nvim_get_cmdline_info() returns cmdline chunks including firstc
(e.g. {":", "h"}), but format.detect patterns expect content without
firstc (e.g. "h"). Strip the leading firstc before comparing text
and detecting format changes.

Changed files (1)

neovim/lua/bugabinga/cmdline/render.lua

Modified
11 11 buffer = -1,
12 12 window = -1,
13 13 current_fmt = nil,
14 + text = '',
16 17 local BORDER_HIGHLIGHT_MAP = {
76 77 function M.show(cmdline_state)
77 78 local text = cmdline_state:text()
79 + state.text = text
78 80 local fmt = format.detect(cmdline_state.firstc, text, cmdline_state.prompt)
79 81 state.current_fmt = fmt
80 82 local display_text = ' ' .. text .. ' '
127 129 state.window = -1
128 130 state.current_fmt = nil
131 + state.text = ''
129 132 position.set_cmdline_anchor(nil)
130 133 vim.g.ui_cmdline_pos = nil
135 138 return
137 140 local info = vim.api.nvim_get_cmdline_info()
138 - local text = info.cmdline and #info.cmdline > 0 and table.concat(info.cmdline, '') or ''
141 + local raw = info.cmdline and #info.cmdline > 0 and table.concat(info.cmdline, '') or ''
139 142 local firstc = info.firstc and info.firstc ~= '' and info.firstc or ''
140 - local fmt = format.detect(firstc, text, cmdline_state.prompt)
141 - if fmt.type ~= state.current_fmt.type then
142 - state.current_fmt = fmt
143 - vim.wo[state.window].winhighlight = get_winhighlight(fmt.type)
144 - vim.api.nvim_buf_clear_namespace(state.buffer, ns, 0, -1)
145 - local icon_hl = ICON_HIGHLIGHT_MAP[fmt.type] or 'CmdlineIconCmdline'
146 - vim.api.nvim_buf_set_extmark(state.buffer, ns, 0, 0, {
147 - virt_text = { { fmt.icon, icon_hl } },
148 - virt_text_pos = 'overlay',
149 - })
143 + local content = raw
144 + if firstc ~= '' and raw:find('^' .. firstc) then
145 + content = raw:sub(#firstc + 1)
146 + end
147 + if content ~= state.text then
148 + state.text = content
149 + local fmt = format.detect(firstc, content, cmdline_state.prompt)
150 + if fmt.type ~= state.current_fmt.type then
151 + state.current_fmt = fmt
152 + vim.wo[state.window].winhighlight = get_winhighlight(fmt.type)
153 + vim.api.nvim_buf_clear_namespace(state.buffer, ns, 0, -1)
154 + local icon_hl = ICON_HIGHLIGHT_MAP[fmt.type] or 'CmdlineIconCmdline'
155 + vim.api.nvim_buf_set_extmark(state.buffer, ns, 0, 0, {
156 + virt_text = { { fmt.icon, icon_hl } },
157 + virt_text_pos = 'overlay',
158 + })
159 + end
151 161 local cursor_byte = cmdline_state:cursor_byte()
152 162 local cursor_col = 2 + cursor_byte