mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	"open" note put into note autocomplete input, also fixes #222
This commit is contained in:
		| @@ -1,5 +1,6 @@ | ||||
| import server from "./server.js"; | ||||
| import noteDetailService from "./note_detail.js"; | ||||
| import treeService from './tree.js'; | ||||
|  | ||||
| const SELECTED_PATH_KEY = "selected-path"; | ||||
|  | ||||
| @@ -19,16 +20,20 @@ async function autocompleteSource(term, cb) { | ||||
| } | ||||
|  | ||||
| function clearText($el) { | ||||
|     $el.setSelectedPath(""); | ||||
|     $el.autocomplete("val", "").change(); | ||||
| } | ||||
|  | ||||
| function showRecentNotes($el) { | ||||
|     $el.setSelectedPath(""); | ||||
|     $el.autocomplete("val", ""); | ||||
|     $el.autocomplete("open"); | ||||
| } | ||||
|  | ||||
| function initNoteAutocomplete($el) { | ||||
|     if (!$el.hasClass("aa-input")) { | ||||
|     if (!$el.hasClass("note-autocomplete-input")) { | ||||
|         $el.addClass("note-autocomplete-input"); | ||||
|  | ||||
|         const $clearTextButton = $("<span>") | ||||
|                 .addClass("input-group-text input-clearer-button jam jam-close") | ||||
|                 .prop("title", "Clear text field"); | ||||
| @@ -37,15 +42,28 @@ function initNoteAutocomplete($el) { | ||||
|                 .addClass("input-group-text show-recent-notes-button jam jam-clock") | ||||
|                 .prop("title", "Show recent notes"); | ||||
|  | ||||
|         const $goToSelectedNoteButton = $("<span>") | ||||
|             .addClass("input-group-text go-to-selected-note-button jam jam-arrow-right") | ||||
|             .prop("title", "Go to selected note"); | ||||
|  | ||||
|         $el.after($("<div>") | ||||
|             .addClass("input-group-append") | ||||
|             .append($clearTextButton) | ||||
|             .append($showRecentNotesButton)); | ||||
|             .append($showRecentNotesButton) | ||||
|             .append($goToSelectedNoteButton)); | ||||
|  | ||||
|         $clearTextButton.click(() => clearText($el)); | ||||
|  | ||||
|         $showRecentNotesButton.click(() => showRecentNotes($el)); | ||||
|  | ||||
|         $goToSelectedNoteButton.click(() => { | ||||
|             if ($el.hasClass("disabled")) { | ||||
|                 return; | ||||
|             } | ||||
|  | ||||
|             treeService.activateNote($el.getSelectedPath()); | ||||
|         }); | ||||
|  | ||||
|         $el.autocomplete({ | ||||
|             appendTo: document.querySelector('body'), | ||||
|             hint: false, | ||||
| @@ -85,13 +103,22 @@ $.fn.getSelectedPath = function() { | ||||
| }; | ||||
|  | ||||
| $.fn.setSelectedPath = function(path) { | ||||
|     path = path || ""; | ||||
|  | ||||
|     $(this).data(SELECTED_PATH_KEY, path); | ||||
|  | ||||
|     $(this) | ||||
|         .closest(".input-group") | ||||
|         .find(".go-to-selected-note-button") | ||||
|         .toggleClass("disabled", !path.trim()); | ||||
| }; | ||||
|  | ||||
| ko.bindingHandlers.noteAutocomplete = { | ||||
|     init: function(element, valueAccessor, allBindings, viewModel, bindingContext) { | ||||
|         initNoteAutocomplete($(element)); | ||||
|  | ||||
|         $(element).setSelectedPath(bindingContext.$data.selectedPath); | ||||
|  | ||||
|         $(element).on('autocomplete:selected', function(event, suggestion, dataset) { | ||||
|             bindingContext.$data.selectedPath = $(element).val().trim() ? suggestion.path : ''; | ||||
|         }); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user