Group {{query:...}} results by page

This commit is contained in:
Peter Stuifzand 2021-08-08 14:51:54 +02:00
parent dec8e85064
commit 707f84ec43

View File

@ -157,22 +157,24 @@ function showSearchResultsExtended(element, template, searchTool, query, input,
}) })
} }
function formatLineResult(hit) { function formatLineResult(hits, key) {
return [ return [
{ {
text: "[[" + hit.title + "]]", text: "[[" + key + "]]",
indented: 0, indented: 0,
fold: 'open', fold: 'open',
hidden: false, hidden: false,
fleeting: true fleeting: true
}, },
{ ..._.map(hits, (hit) => {
text: hit.line, return {
indented: 1, text: hit.line,
fold: 'open', indented: 1,
hidden: false, fold: 'open',
fleeting: true hidden: false,
} fleeting: true
}
})
] ]
} }
@ -629,6 +631,7 @@ function Editor(holder, input) {
.finally(() => editor.render()) .finally(() => editor.render())
} else { } else {
return search.startQuery(res[2]) return search.startQuery(res[2])
.then(hits => _.groupBy(hits, (it) => it.title))
.then(hits => _.flatMap(hits, formatLineResult)) .then(hits => _.flatMap(hits, formatLineResult))
.then(results => editor.replaceChildren(id, results)) .then(results => editor.replaceChildren(id, results))
.finally(() => editor.render()) .finally(() => editor.render())