From 707f84ec43a10f50c4dda0f6c4ea68977f16cfc8 Mon Sep 17 00:00:00 2001 From: Peter Stuifzand Date: Sun, 8 Aug 2021 14:51:54 +0200 Subject: [PATCH] Group {{query:...}} results by page --- editor/src/editor.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/editor/src/editor.js b/editor/src/editor.js index f6ebf18..c79081b 100644 --- a/editor/src/editor.js +++ b/editor/src/editor.js @@ -157,22 +157,24 @@ function showSearchResultsExtended(element, template, searchTool, query, input, }) } -function formatLineResult(hit) { +function formatLineResult(hits, key) { return [ { - text: "[[" + hit.title + "]]", + text: "[[" + key + "]]", indented: 0, fold: 'open', hidden: false, fleeting: true }, - { - text: hit.line, - indented: 1, - fold: 'open', - hidden: false, - fleeting: true - } + ..._.map(hits, (hit) => { + return { + text: hit.line, + indented: 1, + fold: 'open', + hidden: false, + fleeting: true + } + }) ] } @@ -629,6 +631,7 @@ function Editor(holder, input) { .finally(() => editor.render()) } else { return search.startQuery(res[2]) + .then(hits => _.groupBy(hits, (it) => it.title)) .then(hits => _.flatMap(hits, formatLineResult)) .then(results => editor.replaceChildren(id, results)) .finally(() => editor.render())