autocomplete returns items which have at least one of the tokens in the leaf note title, closes #59

This commit is contained in:
azivner 2018-02-22 19:52:08 -05:00
parent 08b8141fdf
commit 4acc5432c3
2 changed files with 23 additions and 11 deletions

View file

@ -114,22 +114,32 @@ $.ui.autocomplete.filter = (array, terms) => {
const tokens = terms.toLowerCase().split(" ");
for (const item of array) {
let found = true;
const lcLabel = item.label.toLowerCase();
for (const token of tokens) {
if (lcLabel.indexOf(token) === -1) {
found = false;
break;
const found = tokens.every(token => lcLabel.indexOf(token) !== -1);
if (!found) {
continue;
}
// this is not completely correct and might cause minor problems with note with names containing this " / "
const lastSegmentIndex = lcLabel.lastIndexOf(" / ");
if (lastSegmentIndex !== -1) {
const lastSegment = lcLabel.substr(lastSegmentIndex + 3);
// at least some token needs to be in the last segment (leaf note), otherwise this
// particular note is not that interesting (query is satisfied by parent note)
const foundInLastSegment = tokens.some(token => lastSegment.indexOf(token) !== -1);
if (!foundInLastSegment) {
continue;
}
}
if (found) {
results.push(item);
results.push(item);
if (results.length > 100) {
break;
}
if (results.length > 100) {
break;
}
}

View file

@ -11,7 +11,7 @@
})(function(CodeMirror) {
"use strict";
async function validator(text, options) {
async function validator(text, options) {console.log("Validating...");
await requireLibrary(ESLINT);
var errors = new eslint().verify(text, {
@ -48,6 +48,8 @@
}
CodeMirror.registerHelper("lint", "javascript", validator);
// CodeMirror.registerHelper("lint", "htmlmixed", validator);
// CodeMirror.registerHelper("lint", "html", validator);
function parseErrors(errors, output) {
for (const error of errors) {