PR Feedback filtering by label and section name. Disable default filter highlighting

This commit is contained in:
Dean 2023-05-30 15:02:13 +01:00
parent 1a8470e949
commit 6c184bd6d9
1 changed files with 28 additions and 6 deletions

View File

@ -172,6 +172,19 @@ export const getHelperCompletions = () => {
}, []) }, [])
} }
const bindingFilter = (options, query) => {
return options.filter(completion => {
const section_parsed = completion.section.name.toLowerCase()
const label_parsed = completion.label.toLowerCase()
const query_parsed = query.toLowerCase()
return (
section_parsed.includes(query_parsed) ||
label_parsed.includes(query_parsed)
)
})
}
export const hbAutocomplete = baseCompletions => { export const hbAutocomplete = baseCompletions => {
async function coreCompletion(context) { async function coreCompletion(context) {
let bindingStart = context.matchBefore(EditorModes.Handlebars.match) let bindingStart = context.matchBefore(EditorModes.Handlebars.match)
@ -181,10 +194,15 @@ export const hbAutocomplete = baseCompletions => {
if (!bindingStart) { if (!bindingStart) {
return null return null
} }
// Accomodate spaces
const match = bindingStart.text.match(/{{[\s]*/)
const query = bindingStart.text.replace(match[0], "")
let filtered = bindingFilter(options, query)
return { return {
from: bindingStart.from + 2, from: bindingStart.from + match[0].length,
filter: true, filter: false,
options, options: filtered,
} }
} }
@ -197,10 +215,14 @@ export const jsAutocomplete = baseCompletions => {
let options = baseCompletions || [] let options = baseCompletions || []
if (jsBinding) { if (jsBinding) {
// Accomodate spaces
const match = jsBinding.text.match(/\$\("[\s]*/)
const query = jsBinding.text.replace(match[0], "")
let filtered = bindingFilter(options, query)
return { return {
from: jsBinding.from + 3, from: jsBinding.from + match[0].length,
filter: true, filter: false,
options, options: filtered,
} }
} }