From 0c02cae37a3989f7a16dbbd170be489f5e18c6b4 Mon Sep 17 00:00:00 2001 From: Weirong Xu Date: Wed, 12 Jun 2024 11:47:52 +0800 Subject: [PATCH] fix: prevent add the same file multiple times to quickfix, resolve #585 --- src/actions/globalActions.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/actions/globalActions.ts b/src/actions/globalActions.ts index 75362a8..e89daef 100644 --- a/src/actions/globalActions.ts +++ b/src/actions/globalActions.ts @@ -784,16 +784,24 @@ export function loadGlobalActions(action: ActionExplorer) { async ({ args, nodes, source }) => { const argAction = (args[0] ?? 'replace') as QuickfixAction; const action = { add: 'a', replace: 'r' }[argAction]; + const list: { filename?: string }[] = await nvim.call('getqflist'); + const existFullpathes = list + .map((it) => it.filename) + .filter(Boolean) as string[]; await nvim.call('setqflist', [ nodes .filter((it) => it.fullpath && !it.expandable) .map((it) => { - const realtive = pathLib.relative(source.root, it.fullpath!); + const fullpath = it.fullpath!; + if (existFullpathes.includes(fullpath)) return undefined; + const realtive = pathLib.relative(source.root, fullpath); return { filename: it.fullpath, text: realtive, + lnum: 1, }; - }), + }) + .filter(Boolean), action, ]); const openCommand = (await nvim.getVar(