🐻 minimal ui2 fuzzy finder for Neovim codeberg.org/comfysage/artio.nvim
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(view): set prompt-buffer

- configure prompt text and mark
- fix update cursor pos

robin 517ce960 2fb7ec7c

+22 -11
+22 -11
lua/artio/view.lua
··· 50 50 51 51 local cmdbuff = "" ---@type string Stored cmdline used to calculate translation offset. 52 52 local promptlen = 0 -- Current length of the last line in the prompt. 53 - local promptwidth = 0 -- Current width of the prompt in the cmdline buffer. 54 53 local promptidx = 0 55 54 --- Concatenate content chunks and set the text for the current row in the cmdline buffer. 56 55 --- ··· 62 61 lines[#lines + 1] = vim.fn.strtrans(line) 63 62 end 64 63 64 + local promptstr = lines[#lines] 65 65 promptlen = #lines[#lines] 66 - promptwidth = vim.fn.strdisplaywidth(lines[#lines]) 67 66 68 67 cmdbuff = "" 69 68 for _, chunk in ipairs(content) do 70 69 cmdbuff = cmdbuff .. chunk[2] 71 70 end 72 - lines[#lines] = ("%s%s"):format(lines[#lines], vim.fn.strtrans(cmdbuff)) 71 + lines[#lines] = ("%s%s"):format(promptstr, vim.fn.strtrans(cmdbuff)) 73 72 self:setlines(promptidx, promptidx + 1, lines) 73 + vim.fn.prompt_setprompt(ext.bufs.cmd, promptstr) 74 + vim.schedule(function() 75 + local ok, result = pcall(vim.api.nvim_buf_set_mark, ext.bufs.cmd, ":", promptidx + 1, 0, {}) 76 + if not ok then 77 + vim.notify(("Failed to set mark %d:%d\n\t%s"):format(promptidx, promptlen, result), vim.log.levels.ERROR) 78 + return 79 + end 80 + end) 74 81 end 75 82 76 83 --- Set the cmdline buffer text and cursor position. ··· 129 136 130 137 function View:setopts() 131 138 local opts = { 132 - eventignorewin = "all,-FileType,-TextChangedI,-CursorMovedI", 139 + eventignorewin = "all,-FileType,-InsertCharPre,-TextChangedI,-CursorMovedI", 133 140 winhighlight = "Normal:ArtioNormal," .. ext_winhl, 134 141 laststatus = self.picker.win.hidestatusline and 0 or nil, 135 142 filetype = "artio-picker", 143 + buftype = "prompt", 144 + 136 145 autocomplete = false, 146 + signcolumn = "no", 147 + wrap = false, 137 148 } 138 149 139 150 self.opts = {} ··· 217 228 218 229 cmdline.cmdline_show( 219 230 { self.picker.defaulttext and { 0, self.picker.defaulttext } or nil }, 220 - nil, 231 + -1, 221 232 "", 222 233 self.picker.prompttext, 223 234 1, ··· 231 242 232 243 self:setopts() 233 244 234 - vim._with({ noautocmd = true }, function() 235 - vim.cmd.startinsert() 236 - end) 237 - 238 245 vim.schedule(function() 239 246 self:clear() 240 247 self:updatecursor() 248 + end) 249 + 250 + vim._with({ noautocmd = true }, function() 251 + vim.cmd.startinsert() 241 252 end) 242 253 243 254 vim._with({ win = ext.wins.cmd, wo = { eventignorewin = "" } }, function() ··· 270 281 local text = vim.api.nvim_get_current_line() 271 282 text = text:sub(promptlen + 1) 272 283 273 - cmdline.cmdline_show({ { 0, text } }, nil, "", self.picker.prompttext, cmdline.indent, cmdline.level, prompt_hl_id) 284 + cmdline.cmdline_show({ { 0, text } }, -1, "", self.picker.prompttext, cmdline.indent, cmdline.level, prompt_hl_id) 274 285 end 275 286 276 287 local curpos = { 0, 0 } -- Last drawn cursor position. absolute ··· 278 289 function View:updatecursor(pos) 279 290 self:promptpos() 280 291 281 - if not pos then 292 + if not pos or pos < 0 then 282 293 local cursorpos = vim.api.nvim_win_get_cursor(ext.wins.cmd) 283 294 pos = cursorpos[2] - promptlen 284 295 end