diff --git a/lua/artio/builtins.lua b/lua/artio/builtins.lua index 6ed9a42..dffda5d 100644 --- a/lua/artio/builtins.lua +++ b/lua/artio/builtins.lua @@ -47,6 +47,9 @@ builtins.files = function(props) {}, utils.make_setqflistactions(function(item) return { filename = item.v } + end), + utils.make_fileactions(function(item) + return vim.fn.bufnr(item.v, true) end) ), }, props) diff --git a/lua/artio/config.lua b/lua/artio/config.lua index 5db8c01..ec9cb0f 100644 --- a/lua/artio/config.lua +++ b/lua/artio/config.lua @@ -50,6 +50,8 @@ M.default = { [""] = "togglepreview", [""] = "setqflist", [""] = "setqflistmark", + [""] = "split", + [""] = "vsplit", }, } diff --git a/lua/artio/picker.lua b/lua/artio/picker.lua index 7fb91df..a50b9e9 100644 --- a/lua/artio/picker.lua +++ b/lua/artio/picker.lua @@ -220,4 +220,18 @@ function Picker:getmarked() :totable() end +---@param idx? integer index in items +---@return artio.Picker.item? +function Picker:getcurrent(idx) + if not idx then + local i = self.idx + idx = self.matches[i] and self.matches[i][1] + end + if not idx then + return + end + + return self.items[idx] +end + return Picker diff --git a/lua/artio/utils.lua b/lua/artio/utils.lua index 3b1dc68..866b5c1 100644 --- a/lua/artio/utils.lua +++ b/lua/artio/utils.lua @@ -75,4 +75,31 @@ function utils.make_setqflistactions(fn) } end +---@param fn fun(item: artio.Picker.item): integer +---@return table +function utils.make_fileactions(fn) + return { + split = require("artio").wrap(function(self) + coroutine.resume(self.co, 1) + end, function(self) + local item = self:getcurrent() + if not item then + return + end + local buf = fn(item) + vim.api.nvim_open_win(buf, true, { win = -1, vertical = false }) + end), + vsplit = require("artio").wrap(function(self) + coroutine.resume(self.co, 1) + end, function(self) + local item = self:getcurrent() + if not item then + return + end + local buf = fn(item) + vim.api.nvim_open_win(buf, true, { win = -1, vertical = true }) + end), + } +end + return utils