mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 21:11:30 +08:00 
			
		
		
		
	fixed autocomplete
This commit is contained in:
		
							parent
							
								
									e992087720
								
							
						
					
					
						commit
						658f4872af
					
				| @ -27,7 +27,7 @@ const addLink = (function() { | |||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         autoCompleteEl.autocomplete({ |         autoCompleteEl.autocomplete({ | ||||||
|             source: getAutocompleteItems(glob.allNoteIds), |             source: noteTree.getAutocompleteItems(), | ||||||
|             minLength: 0, |             minLength: 0, | ||||||
|             change: () => { |             change: () => { | ||||||
|                 const val = autoCompleteEl.val(); |                 const val = autoCompleteEl.val(); | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ const jumpToNote = (function() { | |||||||
|         }); |         }); | ||||||
| 
 | 
 | ||||||
|         autoCompleteEl.autocomplete({ |         autoCompleteEl.autocomplete({ | ||||||
|             source: getAutocompleteItems(glob.allNoteIds), |             source: noteTree.getAutocompleteItems(), | ||||||
|             minLength: 0 |             minLength: 0 | ||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -57,10 +57,10 @@ $.ui.autocomplete.filter = (array, terms) => { | |||||||
| 
 | 
 | ||||||
|     for (const item of array) { |     for (const item of array) { | ||||||
|         let found = true; |         let found = true; | ||||||
|         const lcValue = item.value.toLowerCase(); |         const lcLabel = item.label.toLowerCase(); | ||||||
| 
 | 
 | ||||||
|         for (const token of tokens) { |         for (const token of tokens) { | ||||||
|             if (lcValue.indexOf(token) === -1) { |             if (lcLabel.indexOf(token) === -1) { | ||||||
|                 found = false; |                 found = false; | ||||||
|                 break; |                 break; | ||||||
|             } |             } | ||||||
|  | |||||||
| @ -418,8 +418,8 @@ const noteTree = (function() { | |||||||
|         tree.clearFilter(); |         tree.clearFilter(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     function getByNoteId(noteId) { |     function getByNoteTreeId(noteTreeId) { | ||||||
|         return notesMap[noteId]; |         return notesMap[noteTreeId]; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     // note that if you want to access data like note_id or is_protected, you need to go into "data" property
 |     // 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); |         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); |     $("button#reset-search-button").click(resetSearch); | ||||||
| 
 | 
 | ||||||
|     $("input[name=search]").keyup(e => { |     $("input[name=search]").keyup(e => { | ||||||
| @ -477,7 +515,7 @@ const noteTree = (function() { | |||||||
|         collapseTree, |         collapseTree, | ||||||
|         scrollToCurrentNote, |         scrollToCurrentNote, | ||||||
|         toggleSearch, |         toggleSearch, | ||||||
|         getByNoteId, |         getByNoteTreeId, | ||||||
|         getKeyFromNoteTreeId, |         getKeyFromNoteTreeId, | ||||||
|         getNoteTreeIdFromKey, |         getNoteTreeIdFromKey, | ||||||
|         setCurrentNoteTreeBasedOnProtectedStatus, |         setCurrentNoteTreeBasedOnProtectedStatus, | ||||||
| @ -486,6 +524,7 @@ const noteTree = (function() { | |||||||
|         activateNode, |         activateNode, | ||||||
|         getCurrentNotePath, |         getCurrentNotePath, | ||||||
|         getNoteTitle, |         getNoteTitle, | ||||||
|         setCurrentNotePathToHash |         setCurrentNotePathToHash, | ||||||
|  |         getAutocompleteItems | ||||||
|     }; |     }; | ||||||
| })(); | })(); | ||||||
| @ -35,7 +35,7 @@ const treeUtils = (function() { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     function getFullName(noteTreeId) { |     function getFullName(noteTreeId) { | ||||||
|         let note = noteTree.getByNoteId(noteTreeId); |         let note = noteTree.getByNoteTreeId(noteTreeId); | ||||||
| 
 | 
 | ||||||
|         if (note === null) { |         if (note === null) { | ||||||
|             return "[unknown]"; |             return "[unknown]"; | ||||||
| @ -46,7 +46,7 @@ const treeUtils = (function() { | |||||||
|         while (note) { |         while (note) { | ||||||
|             path.push(note.note_title); |             path.push(note.note_title); | ||||||
| 
 | 
 | ||||||
|             note = noteTree.getByNoteId(note.note_pid); |             note = noteTree.getByNoteTreeId(note.note_pid); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         return path.reverse().join(" > "); |         return path.reverse().join(" > "); | ||||||
|  | |||||||
| @ -20,25 +20,6 @@ function showError(str) { | |||||||
|     error.fadeOut(10000); |     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) { | function getDateFromTS(timestamp) { | ||||||
|     // Date accepts number of milliseconds since epoch so UTC timestamp works without any extra handling
 |     // 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
 |     // 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