mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
"open" note put into note autocomplete input, also fixes #222
This commit is contained in:
parent
7be85acf11
commit
74acb08f7b
@ -205,21 +205,6 @@ async function createPromotedAttributeRow(definitionAttr, valueAttr) {
|
||||
});
|
||||
|
||||
$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 {
|
||||
messagingService.logError("Unknown attribute type=" + valueAttr.type);
|
||||
|
@ -51,20 +51,6 @@ function getNotePathFromLink($link) {
|
||||
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) {
|
||||
e.preventDefault();
|
||||
|
||||
@ -73,7 +59,7 @@ function goToLink(e) {
|
||||
const notePath = getNotePathFromLink($link);
|
||||
|
||||
if (notePath) {
|
||||
openNotePath(notePath);
|
||||
treeService.activateNote(notePath);
|
||||
}
|
||||
else {
|
||||
const address = $link.attr('href');
|
||||
@ -127,7 +113,7 @@ $(document).on('click', 'span.ck-button__label', e => {
|
||||
const notePath = getNotePathFromUrl(url);
|
||||
|
||||
if (notePath) {
|
||||
openNotePath(notePath);
|
||||
treeService.activateNote(notePath);
|
||||
|
||||
e.preventDefault();
|
||||
}
|
||||
|
@ -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 : '';
|
||||
});
|
||||
|
@ -111,6 +111,10 @@ async function expandToNote(notePath, expandOpts) {
|
||||
async function activateNote(notePath, newNote) {
|
||||
utils.assertArguments(notePath);
|
||||
|
||||
if (glob.activeDialog) {
|
||||
glob.activeDialog.modal('hide');
|
||||
}
|
||||
|
||||
const node = await expandToNote(notePath);
|
||||
|
||||
if (newNote) {
|
||||
@ -165,10 +169,10 @@ async function getRunPath(notePath) {
|
||||
}
|
||||
|
||||
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) {
|
||||
console.log(utils.now(), "Available parents:", parents);
|
||||
console.debug(utils.now(), "Available parents:", parents);
|
||||
|
||||
const someNotePath = await getSomeNotePath(parents[0]);
|
||||
|
||||
|
@ -455,8 +455,8 @@ html.theme-dark body {
|
||||
.show-recent-notes-button {
|
||||
cursor: pointer;
|
||||
font-size: 1.3em;
|
||||
padding-left: 7px;
|
||||
padding-right: 7px;
|
||||
padding-left: 5px;
|
||||
padding-right: 5px;
|
||||
}
|
||||
|
||||
.input-clearer-button {
|
||||
@ -464,10 +464,23 @@ html.theme-dark body {
|
||||
font-size: 1.3em;
|
||||
background: inherit !important;
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user