From 4acc5432c3cf3e65558c4783f3bb9c6988ff1d09 Mon Sep 17 00:00:00 2001 From: azivner Date: Thu, 22 Feb 2018 19:52:08 -0500 Subject: [PATCH] autocomplete returns items which have at least one of the tokens in the leaf note title, closes #59 --- src/public/javascripts/init.js | 30 ++++++++++++------- .../libraries/codemirror/addon/lint/eslint.js | 4 ++- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/public/javascripts/init.js b/src/public/javascripts/init.js index c2700afda..f0e25a28b 100644 --- a/src/public/javascripts/init.js +++ b/src/public/javascripts/init.js @@ -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; } } diff --git a/src/public/libraries/codemirror/addon/lint/eslint.js b/src/public/libraries/codemirror/addon/lint/eslint.js index 210f1d096..a1520134b 100644 --- a/src/public/libraries/codemirror/addon/lint/eslint.js +++ b/src/public/libraries/codemirror/addon/lint/eslint.js @@ -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) {