From 1f5cb56a08897198458d071a91b7fd2cdec5dec5 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 2 Oct 2024 11:26:13 +0400 Subject: [PATCH] feat(config): add `close` counterparts to jump split actions --- README.md | 10 ++++++++++ lua/trouble/config/actions.lua | 14 ++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/README.md b/README.md index 5d205a42..ce5e526c 100644 --- a/README.md +++ b/README.md @@ -555,11 +555,21 @@ require("trouble").jump_only(opts) ---@return trouble.View require("trouble").jump_split(opts) +-- Open the item in a split and close the trouble window +---@param opts? trouble.Mode | { new? : boolean } | string +---@return trouble.View +require("trouble").jump_split_close(opts) + -- Open the item in a vsplit ---@param opts? trouble.Mode | { new? : boolean } | string ---@return trouble.View require("trouble").jump_vsplit(opts) +-- Open the item in a vsplit and close the trouble window +---@param opts? trouble.Mode | { new? : boolean } | string +---@return trouble.View +require("trouble").jump_vsplit_close(opts) + -- Go to the last item ---@param opts? trouble.Mode | { new? : boolean } | string ---@return trouble.View diff --git a/lua/trouble/config/actions.lua b/lua/trouble/config/actions.lua index ecb26942..6b0264b5 100644 --- a/lua/trouble/config/actions.lua +++ b/lua/trouble/config/actions.lua @@ -114,12 +114,26 @@ local M = { self:jump(ctx.item, { split = true }) end end, + -- Open the item in a split and close the trouble window + jump_split_close = function(self, ctx) + if ctx.item then + self:jump(ctx.item, { split = true }) + self:close() + end + end, -- Open the item in a vsplit jump_vsplit = function(self, ctx) if ctx.item then self:jump(ctx.item, { vsplit = true }) end end, + -- Open the item in a vsplit and close the trouble window + jump_vsplit_close = function(self, ctx) + if ctx.item then + self:jump(ctx.item, { vsplit = true }) + self:close() + end + end, -- Dump the item to the console inspect = function(_, ctx) vim.print(ctx.item or (ctx.node and ctx.node.item))