mirror of
https://github.com/zadam/trilium.git
synced 2025-11-01 02:45:54 +01:00
53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
import server from './server.js';
|
|
import ws from "./ws.js";
|
|
import treeCache from "./tree_cache.js";
|
|
import NoteComplement from "../entities/note_full.js";
|
|
import appContext from "./app_context.js";
|
|
|
|
function getActiveEditor() {
|
|
const activeTabContext = appContext.getActiveTabContext();
|
|
|
|
if (activeTabContext && activeTabContext.note && activeTabContext.note.type === 'text') {
|
|
return activeTabContext.getComponent().getEditor();
|
|
}
|
|
else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
async function loadNoteComplement(noteId) {
|
|
const row = await server.get('notes/' + noteId);
|
|
|
|
return new NoteComplement(row);
|
|
}
|
|
|
|
function focusOnTitle() {
|
|
appContext.trigger('focusOnTitle');
|
|
}
|
|
|
|
function focusAndSelectTitle() {
|
|
appContext.trigger('focusAndSelectTitle');
|
|
}
|
|
|
|
function noteChanged() {
|
|
const activeTabContext = appContext.getActiveTabContext();
|
|
|
|
if (activeTabContext) {
|
|
activeTabContext.noteChanged();
|
|
}
|
|
}
|
|
|
|
// this makes sure that when user e.g. reloads the page or navigates away from the page, the note's content is saved
|
|
// this sends the request asynchronously and doesn't wait for result
|
|
// FIXME
|
|
$(window).on('beforeunload', () => {
|
|
//saveNotesIfChanged();
|
|
});
|
|
|
|
export default {
|
|
loadNoteComplement,
|
|
focusOnTitle,
|
|
focusAndSelectTitle,
|
|
getActiveEditor,
|
|
noteChanged
|
|
}; |