mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 03:29:02 +01:00 
			
		
		
		
	fixed autocomplete
This commit is contained in:
		
							parent
							
								
									e992087720
								
							
						
					
					
						commit
						658f4872af
					
				| @ -27,7 +27,7 @@ const addLink = (function() { | ||||
|         } | ||||
| 
 | ||||
|         autoCompleteEl.autocomplete({ | ||||
|             source: getAutocompleteItems(glob.allNoteIds), | ||||
|             source: noteTree.getAutocompleteItems(), | ||||
|             minLength: 0, | ||||
|             change: () => { | ||||
|                 const val = autoCompleteEl.val(); | ||||
|  | ||||
| @ -16,7 +16,7 @@ const jumpToNote = (function() { | ||||
|         }); | ||||
| 
 | ||||
|         autoCompleteEl.autocomplete({ | ||||
|             source: getAutocompleteItems(glob.allNoteIds), | ||||
|             source: noteTree.getAutocompleteItems(), | ||||
|             minLength: 0 | ||||
|         }); | ||||
|     } | ||||
|  | ||||
| @ -57,10 +57,10 @@ $.ui.autocomplete.filter = (array, terms) => { | ||||
| 
 | ||||
|     for (const item of array) { | ||||
|         let found = true; | ||||
|         const lcValue = item.value.toLowerCase(); | ||||
|         const lcLabel = item.label.toLowerCase(); | ||||
| 
 | ||||
|         for (const token of tokens) { | ||||
|             if (lcValue.indexOf(token) === -1) { | ||||
|             if (lcLabel.indexOf(token) === -1) { | ||||
|                 found = false; | ||||
|                 break; | ||||
|             } | ||||
|  | ||||
| @ -418,8 +418,8 @@ const noteTree = (function() { | ||||
|         tree.clearFilter(); | ||||
|     } | ||||
| 
 | ||||
|     function getByNoteId(noteId) { | ||||
|         return notesMap[noteId]; | ||||
|     function getByNoteTreeId(noteTreeId) { | ||||
|         return notesMap[noteTreeId]; | ||||
|     } | ||||
| 
 | ||||
|     // note that if you want to access data like note_id or is_protected, you need to go into "data" property
 | ||||
| @ -444,6 +444,44 @@ const noteTree = (function() { | ||||
|         node.toggleClass("protected", !!node.data.is_protected); | ||||
|     } | ||||
| 
 | ||||
|     function getAutocompleteItems(parentNoteId, notePath, titlePath) { | ||||
|         if (!parentNoteId) { | ||||
|             parentNoteId = 'root'; | ||||
|         } | ||||
| 
 | ||||
|         if (!parentToChildren[parentNoteId]) { | ||||
|             return []; | ||||
|         } | ||||
| 
 | ||||
|         if (!notePath) { | ||||
|             notePath = ''; | ||||
|         } | ||||
| 
 | ||||
|         if (!titlePath) { | ||||
|             titlePath = ''; | ||||
|         } | ||||
| 
 | ||||
|         const autocompleteItems = []; | ||||
| 
 | ||||
|         for (const childNoteId of parentToChildren[parentNoteId]) { | ||||
|             const childNotePath = (notePath ? (notePath + '/') : '') + childNoteId; | ||||
|             const childTitlePath = (titlePath ? (titlePath + ' / ') : '') + getNoteTitle(childNoteId); | ||||
| 
 | ||||
|             autocompleteItems.push({ | ||||
|                 value: childNotePath, | ||||
|                 label: childTitlePath | ||||
|             }); | ||||
| 
 | ||||
|             const childItems = getAutocompleteItems(childNoteId, childNotePath, childTitlePath); | ||||
| 
 | ||||
|             for (const childItem of childItems) { | ||||
|                 autocompleteItems.push(childItem); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         return autocompleteItems; | ||||
|     } | ||||
| 
 | ||||
|     $("button#reset-search-button").click(resetSearch); | ||||
| 
 | ||||
|     $("input[name=search]").keyup(e => { | ||||
| @ -477,7 +515,7 @@ const noteTree = (function() { | ||||
|         collapseTree, | ||||
|         scrollToCurrentNote, | ||||
|         toggleSearch, | ||||
|         getByNoteId, | ||||
|         getByNoteTreeId, | ||||
|         getKeyFromNoteTreeId, | ||||
|         getNoteTreeIdFromKey, | ||||
|         setCurrentNoteTreeBasedOnProtectedStatus, | ||||
| @ -486,6 +524,7 @@ const noteTree = (function() { | ||||
|         activateNode, | ||||
|         getCurrentNotePath, | ||||
|         getNoteTitle, | ||||
|         setCurrentNotePathToHash | ||||
|         setCurrentNotePathToHash, | ||||
|         getAutocompleteItems | ||||
|     }; | ||||
| })(); | ||||
| @ -35,7 +35,7 @@ const treeUtils = (function() { | ||||
|     } | ||||
| 
 | ||||
|     function getFullName(noteTreeId) { | ||||
|         let note = noteTree.getByNoteId(noteTreeId); | ||||
|         let note = noteTree.getByNoteTreeId(noteTreeId); | ||||
| 
 | ||||
|         if (note === null) { | ||||
|             return "[unknown]"; | ||||
| @ -46,7 +46,7 @@ const treeUtils = (function() { | ||||
|         while (note) { | ||||
|             path.push(note.note_title); | ||||
| 
 | ||||
|             note = noteTree.getByNoteId(note.note_pid); | ||||
|             note = noteTree.getByNoteTreeId(note.note_pid); | ||||
|         } | ||||
| 
 | ||||
|         return path.reverse().join(" > "); | ||||
|  | ||||
| @ -20,25 +20,6 @@ function showError(str) { | ||||
|     error.fadeOut(10000); | ||||
| } | ||||
| 
 | ||||
| function getAutocompleteItems(noteIds) { | ||||
|     const autocompleteItems = []; | ||||
| 
 | ||||
|     for (const noteId of noteIds) { | ||||
|         const fullName = treeUtils.getFullName(noteId); | ||||
| 
 | ||||
|         if (fullName !== null) { | ||||
|             autocompleteItems.push({ | ||||
|                 value: fullName + " (" + noteId + ")", | ||||
|                 label: fullName | ||||
|             }); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     autocompleteItems.sort((a, b) => a.value < b.value ? -1 : 1); | ||||
| 
 | ||||
|     return autocompleteItems; | ||||
| } | ||||
| 
 | ||||
| function getDateFromTS(timestamp) { | ||||
|     // Date accepts number of milliseconds since epoch so UTC timestamp works without any extra handling
 | ||||
|     // see https://stackoverflow.com/questions/4631928/convert-utc-epoch-to-local-date-with-javascript
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 azivner
						azivner