mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
create note inline
This commit is contained in:
parent
6518d113c6
commit
0eef18a799
@ -42,7 +42,9 @@ export async function showDialog(widget) {
|
|||||||
|
|
||||||
noteAutocompleteService.initNoteAutocomplete($autoComplete);
|
noteAutocompleteService.initNoteAutocomplete($autoComplete);
|
||||||
|
|
||||||
$autoComplete.on('autocomplete:selected', function(event, suggestion, dataset) {
|
$autoComplete.on('autocomplete:noteselected', function(event, suggestion, dataset) {
|
||||||
|
console.log("SELECTED", suggestion);
|
||||||
|
|
||||||
if (!suggestion.notePath) {
|
if (!suggestion.notePath) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,31 @@
|
|||||||
import server from "./server.js";
|
import server from "./server.js";
|
||||||
import appContext from "./app_context.js";
|
import appContext from "./app_context.js";
|
||||||
import utils from './utils.js';
|
import utils from './utils.js';
|
||||||
|
import noteCreateService from './note_create.js';
|
||||||
|
import treeService from './tree.js';
|
||||||
|
|
||||||
// this key needs to have this value so it's hit by the tooltip
|
// this key needs to have this value so it's hit by the tooltip
|
||||||
const SELECTED_NOTE_PATH_KEY = "data-note-path";
|
const SELECTED_NOTE_PATH_KEY = "data-note-path";
|
||||||
|
|
||||||
async function autocompleteSource(term, cb) {
|
async function autocompleteSource(term, cb) {
|
||||||
const result = await server.get('autocomplete'
|
const activeNoteId = appContext.tabManager.getActiveTabNoteId();
|
||||||
+ '?query=' + encodeURIComponent(term)
|
|
||||||
+ '&activeNoteId=' + appContext.tabManager.getActiveTabNoteId());
|
|
||||||
|
|
||||||
cb(result);
|
let results = await server.get('autocomplete'
|
||||||
|
+ '?query=' + encodeURIComponent(term)
|
||||||
|
+ '&activeNoteId=' + activeNoteId);
|
||||||
|
|
||||||
|
if (term.trim().length >= 1) {
|
||||||
|
results = [
|
||||||
|
{
|
||||||
|
action: 'create',
|
||||||
|
noteTitle: term,
|
||||||
|
parentNoteId: activeNoteId,
|
||||||
|
highlightedNotePathTitle: `Create and link child note "${term}"`
|
||||||
|
}
|
||||||
|
].concat(results);
|
||||||
|
}
|
||||||
|
|
||||||
|
cb(results);
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearText($el) {
|
function clearText($el) {
|
||||||
@ -86,19 +101,30 @@ function initNoteAutocomplete($el, options) {
|
|||||||
source: autocompleteSource,
|
source: autocompleteSource,
|
||||||
displayKey: 'notePathTitle',
|
displayKey: 'notePathTitle',
|
||||||
templates: {
|
templates: {
|
||||||
suggestion: function(suggestion) {
|
suggestion: suggestion => suggestion.highlightedNotePathTitle
|
||||||
return suggestion.highlightedNotePathTitle;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
// we can't cache identical searches because notes can be created / renamed, new recent notes can be added
|
// we can't cache identical searches because notes can be created / renamed, new recent notes can be added
|
||||||
cache: false
|
cache: false
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$el.on('autocomplete:selected', (event, suggestion) => {
|
$el.on('autocomplete:selected', async (event, suggestion) => {
|
||||||
|
if (suggestion.action === 'create') {
|
||||||
|
const {note} = await noteCreateService.createNote(suggestion.parentNoteId, {
|
||||||
|
title: suggestion.noteTitle,
|
||||||
|
activate: false
|
||||||
|
});
|
||||||
|
|
||||||
|
suggestion.notePath = treeService.getSomeNotePath(note);
|
||||||
|
}
|
||||||
|
|
||||||
$el.setSelectedNotePath(suggestion.notePath);
|
$el.setSelectedNotePath(suggestion.notePath);
|
||||||
|
|
||||||
$el.autocomplete("val", suggestion.noteTitle);
|
$el.autocomplete("val", suggestion.noteTitle);
|
||||||
|
|
||||||
|
$el.autocomplete("close");
|
||||||
|
|
||||||
|
$el.trigger('autocomplete:noteselected', [event, suggestion]);
|
||||||
});
|
});
|
||||||
|
|
||||||
$el.on('autocomplete:closed', () => {
|
$el.on('autocomplete:closed', () => {
|
||||||
|
@ -666,10 +666,14 @@ a.external:not(.no-arrow):after, a[href^="http://"]:not(.no-arrow):after, a[href
|
|||||||
}
|
}
|
||||||
|
|
||||||
.ck-mentions .ck-button {
|
.ck-mentions .ck-button {
|
||||||
font-size: var(--main-font-size) !important;
|
font-size: var(--detail-font-size) !important;
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ck-mentions .ck-button b {
|
||||||
|
font-size: var(--detail-font-size) !important;
|
||||||
|
}
|
||||||
|
|
||||||
.ck-mentions .ck-button.ck-on {
|
.ck-mentions .ck-button.ck-on {
|
||||||
background-color: var(--active-item-background-color) !important;
|
background-color: var(--active-item-background-color) !important;
|
||||||
color: var(--active-item-text-color) !important;
|
color: var(--active-item-text-color) !important;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user