diff --git a/src/public/app/services/attribute_autocomplete.js b/src/public/app/services/attribute_autocomplete.js index 544239e8f..5d49c850a 100644 --- a/src/public/app/services/attribute_autocomplete.js +++ b/src/public/app/services/attribute_autocomplete.js @@ -40,44 +40,49 @@ function initAttributeNameAutocomplete({ $el, attributeType, open }) { } async function initLabelValueAutocomplete({ $el, open, nameCallback }) { - if (!$el.hasClass("aa-input")) { - const attributeName = nameCallback(); - - if (attributeName.trim() === "") { - return; - } - - const attributeValues = (await server.get('attributes/values/' + encodeURIComponent(attributeName))) - .map(attribute => ({ value: attribute })); - - if (attributeValues.length === 0) { - return; - } - - $el.autocomplete({ - appendTo: document.querySelector('body'), - hint: false, - openOnFocus: true, - minLength: 0, - tabAutocomplete: false - }, [{ - displayKey: 'value', - source: function (term, cb) { - term = term.toLowerCase(); - - const filtered = attributeValues.filter(attr => attr.value.toLowerCase().includes(term)); - - cb(filtered); - } - }]); - - $el.on('autocomplete:opened', () => { - if ($el.attr("readonly")) { - $el.autocomplete('close'); - } - }) + if ($el.hasClass("aa-input")) { + // we reinit everytime because autocomplete seems to have a bug where it retains state from last + // open even though the value was resetted + $el.autocomplete('destroy'); } + const attributeName = nameCallback(); + + if (attributeName.trim() === "") { + return; + } + + const attributeValues = (await server.get('attributes/values/' + encodeURIComponent(attributeName))) + .map(attribute => ({ value: attribute })); + + if (attributeValues.length === 0) { + return; + } + + $el.autocomplete({ + appendTo: document.querySelector('body'), + hint: false, + openOnFocus: false, // handled manually + minLength: 0, + tabAutocomplete: false + }, [{ + displayKey: 'value', + cache: false, + source: async function (term, cb) { + term = term.toLowerCase(); + + const filtered = attributeValues.filter(attr => attr.value.toLowerCase().includes(term)); + + cb(filtered); + } + }]); + + $el.on('autocomplete:opened', () => { + if ($el.attr("readonly")) { + $el.autocomplete('close'); + } + }); + if (open) { $el.autocomplete("open"); } diff --git a/src/public/app/widgets/attribute_widgets/attribute_detail.js b/src/public/app/widgets/attribute_widgets/attribute_detail.js index 48b3e77ee..0aad9c8fc 100644 --- a/src/public/app/widgets/attribute_widgets/attribute_detail.js +++ b/src/public/app/widgets/attribute_widgets/attribute_detail.js @@ -248,6 +248,8 @@ export default class AttributeDetailWidget extends TabAwareWidget { this.$rowValue = this.$widget.find('.attr-row-value'); this.$inputValue = this.$widget.find('.attr-input-value'); this.$inputValue.on('keyup', () => this.userEditedAttribute()); + this.$inputValue.on('change', () => this.userEditedAttribute()); + this.$inputValue.on('autocomplete:closed', () => this.userEditedAttribute()); this.$inputValue.on('focus', () => { attributeAutocompleteService.initLabelValueAutocomplete({ $el: this.$inputValue, diff --git a/src/services/search/services/search.js b/src/services/search/services/search.js index 196042ae9..f1da13ebe 100644 --- a/src/services/search/services/search.js +++ b/src/services/search/services/search.js @@ -197,18 +197,18 @@ function highlightSearchResults(searchResults, highlightedTokens) { result.highlightedNotePathTitle = result.notePathTitle.replace('/[<\{\}]/g', ''); if (highlightedTokens.find(token => note.type.includes(token))) { - result.highlightedNotePathTitle += ` `; + result.highlightedNotePathTitle += ` "type: ${note.type}'`; } if (highlightedTokens.find(token => note.mime.includes(token))) { - result.highlightedNotePathTitle += ` `; + result.highlightedNotePathTitle += ` "mime: ${note.mime}'`; } for (const attr of note.attributes) { if (highlightedTokens.find(token => attr.name.toLowerCase().includes(token) || attr.value.toLowerCase().includes(token))) { - result.highlightedNotePathTitle += ` <${formatAttribute(attr)}>`; + result.highlightedNotePathTitle += ` "${formatAttribute(attr)}'`; } } } @@ -223,8 +223,8 @@ function highlightSearchResults(searchResults, highlightedTokens) { for (const result of searchResults) { result.highlightedNotePathTitle = result.highlightedNotePathTitle - .replace(/") - .replace(/>/g, "") + .replace(/"/g, "") + .replace(/'/g, "") .replace(/{/g, "") .replace(/}/g, ""); }