mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +01:00 
			
		
		
		
	"open" note put into note autocomplete input, also fixes #222
This commit is contained in:
		| @@ -205,21 +205,6 @@ async function createPromotedAttributeRow(definitionAttr, valueAttr) { | |||||||
|         }); |         }); | ||||||
|  |  | ||||||
|         $input.setSelectedPath(valueAttr.value); |         $input.setSelectedPath(valueAttr.value); | ||||||
|  |  | ||||||
|         // ideally we'd use link instead of button which would allow tooltip preview, but |  | ||||||
|         // we can't guarantee updating the link in the a element |  | ||||||
|         const $openButton = $("<button>").addClass("btn btn-sm").text("Open").click(() => { |  | ||||||
|             const notePath = $input.getSelectedPath(); |  | ||||||
|  |  | ||||||
|             if (notePath) { |  | ||||||
|                 treeService.activateNote(notePath); |  | ||||||
|             } |  | ||||||
|             else { |  | ||||||
|                 console.log("Empty note path, nothing to open."); |  | ||||||
|             } |  | ||||||
|         }); |  | ||||||
|  |  | ||||||
|         $actionCell.append($openButton); |  | ||||||
|     } |     } | ||||||
|     else { |     else { | ||||||
|         messagingService.logError("Unknown attribute type=" + valueAttr.type); |         messagingService.logError("Unknown attribute type=" + valueAttr.type); | ||||||
|   | |||||||
| @@ -51,20 +51,6 @@ function getNotePathFromLink($link) { | |||||||
|     return url ? getNotePathFromUrl(url) : null; |     return url ? getNotePathFromUrl(url) : null; | ||||||
| } | } | ||||||
|  |  | ||||||
| function openNotePath(notePath) { |  | ||||||
|     treeService.activateNote(notePath); |  | ||||||
|  |  | ||||||
|     // this is quite ugly hack, but it seems like we can't close the tooltip otherwise |  | ||||||
|     $("[role='tooltip']").remove(); |  | ||||||
|  |  | ||||||
|     if (glob.activeDialog) { |  | ||||||
|         try { |  | ||||||
|             glob.activeDialog.modal('hide'); |  | ||||||
|         } catch (e) { |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
|  |  | ||||||
| function goToLink(e) { | function goToLink(e) { | ||||||
|     e.preventDefault(); |     e.preventDefault(); | ||||||
|  |  | ||||||
| @@ -73,7 +59,7 @@ function goToLink(e) { | |||||||
|     const notePath = getNotePathFromLink($link); |     const notePath = getNotePathFromLink($link); | ||||||
|  |  | ||||||
|     if (notePath) { |     if (notePath) { | ||||||
|         openNotePath(notePath); |         treeService.activateNote(notePath); | ||||||
|     } |     } | ||||||
|     else { |     else { | ||||||
|         const address = $link.attr('href'); |         const address = $link.attr('href'); | ||||||
| @@ -127,7 +113,7 @@ $(document).on('click', 'span.ck-button__label', e => { | |||||||
|     const notePath = getNotePathFromUrl(url); |     const notePath = getNotePathFromUrl(url); | ||||||
|  |  | ||||||
|     if (notePath) { |     if (notePath) { | ||||||
|         openNotePath(notePath); |         treeService.activateNote(notePath); | ||||||
|  |  | ||||||
|         e.preventDefault(); |         e.preventDefault(); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -1,5 +1,6 @@ | |||||||
| import server from "./server.js"; | import server from "./server.js"; | ||||||
| import noteDetailService from "./note_detail.js"; | import noteDetailService from "./note_detail.js"; | ||||||
|  | import treeService from './tree.js'; | ||||||
|  |  | ||||||
| const SELECTED_PATH_KEY = "selected-path"; | const SELECTED_PATH_KEY = "selected-path"; | ||||||
|  |  | ||||||
| @@ -19,16 +20,20 @@ async function autocompleteSource(term, cb) { | |||||||
| } | } | ||||||
|  |  | ||||||
| function clearText($el) { | function clearText($el) { | ||||||
|  |     $el.setSelectedPath(""); | ||||||
|     $el.autocomplete("val", "").change(); |     $el.autocomplete("val", "").change(); | ||||||
| } | } | ||||||
|  |  | ||||||
| function showRecentNotes($el) { | function showRecentNotes($el) { | ||||||
|  |     $el.setSelectedPath(""); | ||||||
|     $el.autocomplete("val", ""); |     $el.autocomplete("val", ""); | ||||||
|     $el.autocomplete("open"); |     $el.autocomplete("open"); | ||||||
| } | } | ||||||
|  |  | ||||||
| function initNoteAutocomplete($el) { | function initNoteAutocomplete($el) { | ||||||
|     if (!$el.hasClass("aa-input")) { |     if (!$el.hasClass("note-autocomplete-input")) { | ||||||
|  |         $el.addClass("note-autocomplete-input"); | ||||||
|  |  | ||||||
|         const $clearTextButton = $("<span>") |         const $clearTextButton = $("<span>") | ||||||
|                 .addClass("input-group-text input-clearer-button jam jam-close") |                 .addClass("input-group-text input-clearer-button jam jam-close") | ||||||
|                 .prop("title", "Clear text field"); |                 .prop("title", "Clear text field"); | ||||||
| @@ -37,15 +42,28 @@ function initNoteAutocomplete($el) { | |||||||
|                 .addClass("input-group-text show-recent-notes-button jam jam-clock") |                 .addClass("input-group-text show-recent-notes-button jam jam-clock") | ||||||
|                 .prop("title", "Show recent notes"); |                 .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>") |         $el.after($("<div>") | ||||||
|             .addClass("input-group-append") |             .addClass("input-group-append") | ||||||
|             .append($clearTextButton) |             .append($clearTextButton) | ||||||
|             .append($showRecentNotesButton)); |             .append($showRecentNotesButton) | ||||||
|  |             .append($goToSelectedNoteButton)); | ||||||
|  |  | ||||||
|         $clearTextButton.click(() => clearText($el)); |         $clearTextButton.click(() => clearText($el)); | ||||||
|  |  | ||||||
|         $showRecentNotesButton.click(() => showRecentNotes($el)); |         $showRecentNotesButton.click(() => showRecentNotes($el)); | ||||||
|  |  | ||||||
|  |         $goToSelectedNoteButton.click(() => { | ||||||
|  |             if ($el.hasClass("disabled")) { | ||||||
|  |                 return; | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             treeService.activateNote($el.getSelectedPath()); | ||||||
|  |         }); | ||||||
|  |  | ||||||
|         $el.autocomplete({ |         $el.autocomplete({ | ||||||
|             appendTo: document.querySelector('body'), |             appendTo: document.querySelector('body'), | ||||||
|             hint: false, |             hint: false, | ||||||
| @@ -85,13 +103,22 @@ $.fn.getSelectedPath = function() { | |||||||
| }; | }; | ||||||
|  |  | ||||||
| $.fn.setSelectedPath = function(path) { | $.fn.setSelectedPath = function(path) { | ||||||
|  |     path = path || ""; | ||||||
|  |  | ||||||
|     $(this).data(SELECTED_PATH_KEY, path); |     $(this).data(SELECTED_PATH_KEY, path); | ||||||
|  |  | ||||||
|  |     $(this) | ||||||
|  |         .closest(".input-group") | ||||||
|  |         .find(".go-to-selected-note-button") | ||||||
|  |         .toggleClass("disabled", !path.trim()); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| ko.bindingHandlers.noteAutocomplete = { | ko.bindingHandlers.noteAutocomplete = { | ||||||
|     init: function(element, valueAccessor, allBindings, viewModel, bindingContext) { |     init: function(element, valueAccessor, allBindings, viewModel, bindingContext) { | ||||||
|         initNoteAutocomplete($(element)); |         initNoteAutocomplete($(element)); | ||||||
|  |  | ||||||
|  |         $(element).setSelectedPath(bindingContext.$data.selectedPath); | ||||||
|  |  | ||||||
|         $(element).on('autocomplete:selected', function(event, suggestion, dataset) { |         $(element).on('autocomplete:selected', function(event, suggestion, dataset) { | ||||||
|             bindingContext.$data.selectedPath = $(element).val().trim() ? suggestion.path : ''; |             bindingContext.$data.selectedPath = $(element).val().trim() ? suggestion.path : ''; | ||||||
|         }); |         }); | ||||||
|   | |||||||
| @@ -111,6 +111,10 @@ async function expandToNote(notePath, expandOpts) { | |||||||
| async function activateNote(notePath, newNote) { | async function activateNote(notePath, newNote) { | ||||||
|     utils.assertArguments(notePath); |     utils.assertArguments(notePath); | ||||||
|  |  | ||||||
|  |     if (glob.activeDialog) { | ||||||
|  |         glob.activeDialog.modal('hide'); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     const node = await expandToNote(notePath); |     const node = await expandToNote(notePath); | ||||||
|  |  | ||||||
|     if (newNote) { |     if (newNote) { | ||||||
| @@ -165,10 +169,10 @@ async function getRunPath(notePath) { | |||||||
|             } |             } | ||||||
|  |  | ||||||
|             if (!parents.some(p => p.noteId === parentNoteId)) { |             if (!parents.some(p => p.noteId === parentNoteId)) { | ||||||
|                 console.log(utils.now(), "Did not find parent " + parentNoteId + " for child " + childNoteId); |                 console.debug(utils.now(), "Did not find parent " + parentNoteId + " for child " + childNoteId); | ||||||
|  |  | ||||||
|                 if (parents.length > 0) { |                 if (parents.length > 0) { | ||||||
|                     console.log(utils.now(), "Available parents:", parents); |                     console.debug(utils.now(), "Available parents:", parents); | ||||||
|  |  | ||||||
|                     const someNotePath = await getSomeNotePath(parents[0]); |                     const someNotePath = await getSomeNotePath(parents[0]); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -455,8 +455,8 @@ html.theme-dark body { | |||||||
| .show-recent-notes-button { | .show-recent-notes-button { | ||||||
|     cursor: pointer; |     cursor: pointer; | ||||||
|     font-size: 1.3em; |     font-size: 1.3em; | ||||||
|     padding-left: 7px; |     padding-left: 5px; | ||||||
|     padding-right: 7px; |     padding-right: 5px; | ||||||
| } | } | ||||||
|  |  | ||||||
| .input-clearer-button { | .input-clearer-button { | ||||||
| @@ -464,10 +464,23 @@ html.theme-dark body { | |||||||
|     font-size: 1.3em; |     font-size: 1.3em; | ||||||
|     background: inherit !important; |     background: inherit !important; | ||||||
|     padding-left: 5px; |     padding-left: 5px; | ||||||
|     padding-right: 7px; |     padding-right: 5px; | ||||||
| } | } | ||||||
|  |  | ||||||
| .promoted-attribute-input.aa-input { | .go-to-selected-note-button { | ||||||
|  |     cursor: pointer; | ||||||
|  |     font-size: 1.3em; | ||||||
|  |     padding-left: 4px; | ||||||
|  |     padding-right: 3px; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .go-to-selected-note-button.disabled { | ||||||
|  |     cursor: inherit; | ||||||
|  |     color: #ccc; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .note-autocomplete-input { | ||||||
|  |     /* this is for seamless integration of "input clearer" button */ | ||||||
|     border-right: 0; |     border-right: 0; | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user