mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
global keyboard shortcuts for quick creating sub-notes under day note
This commit is contained in:
parent
7bbfef7af3
commit
0e9473119e
36
electron.js
36
electron.js
@ -6,6 +6,8 @@ const config = require('./src/services/config');
|
|||||||
const url = require("url");
|
const url = require("url");
|
||||||
|
|
||||||
const app = electron.app;
|
const app = electron.app;
|
||||||
|
const globalShortcut = electron.globalShortcut;
|
||||||
|
const clipboard = electron.clipboard;
|
||||||
|
|
||||||
// Adds debug features like hotkeys for triggering dev tools and reload
|
// Adds debug features like hotkeys for triggering dev tools and reload
|
||||||
require('electron-debug')();
|
require('electron-debug')();
|
||||||
@ -67,6 +69,40 @@ app.on('activate', () => {
|
|||||||
|
|
||||||
app.on('ready', () => {
|
app.on('ready', () => {
|
||||||
mainWindow = createMainWindow();
|
mainWindow = createMainWindow();
|
||||||
|
|
||||||
|
const date_notes = require('./src/services/date_notes');
|
||||||
|
const utils = require('./src/services/utils');
|
||||||
|
|
||||||
|
globalShortcut.register('CommandOrControl+Alt+P', async () => {
|
||||||
|
const parentNoteId = await date_notes.getDateNoteId(utils.nowDate());
|
||||||
|
|
||||||
|
// window may be hidden / not in focus
|
||||||
|
mainWindow.focus();
|
||||||
|
|
||||||
|
mainWindow.webContents.send('create-sub-note', JSON.stringify({
|
||||||
|
parentNoteId: parentNoteId,
|
||||||
|
content: ''
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
globalShortcut.register('CommandOrControl+Alt+C', async () => {
|
||||||
|
const parentNoteId = await date_notes.getDateNoteId(utils.nowDate());
|
||||||
|
|
||||||
|
// window may be hidden / not in focus
|
||||||
|
mainWindow.focus();
|
||||||
|
|
||||||
|
let content = clipboard.readText();
|
||||||
|
content = content.replace(/(\r\n|\n)/g, "<p>");
|
||||||
|
|
||||||
|
mainWindow.webContents.send('create-sub-note', JSON.stringify({
|
||||||
|
parentNoteId: parentNoteId,
|
||||||
|
content: content
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
app.on('will-quit', () => {
|
||||||
|
globalShortcut.unregisterAll();
|
||||||
});
|
});
|
||||||
|
|
||||||
require('./src/www');
|
require('./src/www');
|
||||||
|
@ -192,4 +192,22 @@ $(document).ready(() => {
|
|||||||
executeScript(script);
|
executeScript(script);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (isElectron()) {
|
||||||
|
require('electron').ipcRenderer.on('create-sub-note', async function(event, message) {
|
||||||
|
const {parentNoteId, content} = JSON.parse(message);
|
||||||
|
|
||||||
|
if (!noteTree.noteExists(parentNoteId)) {
|
||||||
|
await noteTree.reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
await noteTree.activateNode(parentNoteId);
|
||||||
|
|
||||||
|
const node = noteTree.getCurrentNode();
|
||||||
|
|
||||||
|
await noteTree.createNote(node, node.data.noteId, 'into', node.data.isProtected);
|
||||||
|
|
||||||
|
setTimeout(() => noteEditor.setContent(content), 1000);
|
||||||
|
});
|
||||||
|
}
|
@ -116,6 +116,32 @@ const noteEditor = (function() {
|
|||||||
isNewNoteCreated = true;
|
isNewNoteCreated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setContent(content) {
|
||||||
|
if (currentNote.detail.type === 'text') {
|
||||||
|
// temporary workaround for https://github.com/ckeditor/ckeditor5-enter/issues/49
|
||||||
|
editor.setData(content ? content : "<p></p>");
|
||||||
|
|
||||||
|
noteDetailEl.show();
|
||||||
|
noteDetailCodeEl.hide();
|
||||||
|
noteDetailRenderEl.html('').hide();
|
||||||
|
}
|
||||||
|
else if (currentNote.detail.type === 'code') {
|
||||||
|
noteDetailEl.hide();
|
||||||
|
noteDetailCodeEl.show();
|
||||||
|
noteDetailRenderEl.html('').hide();
|
||||||
|
|
||||||
|
// this needs to happen after the element is shown, otherwise the editor won't be refresheds
|
||||||
|
codeEditor.setValue(content);
|
||||||
|
|
||||||
|
const info = CodeMirror.findModeByMIME(currentNote.detail.mime);
|
||||||
|
|
||||||
|
if (info) {
|
||||||
|
codeEditor.setOption("mode", info.mime);
|
||||||
|
CodeMirror.autoLoadMode(codeEditor, info.mode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function loadNoteToEditor(noteId) {
|
async function loadNoteToEditor(noteId) {
|
||||||
currentNote = await loadNote(noteId);
|
currentNote = await loadNote(noteId);
|
||||||
|
|
||||||
@ -146,30 +172,7 @@ const noteEditor = (function() {
|
|||||||
noteType.setNoteType(currentNote.detail.type);
|
noteType.setNoteType(currentNote.detail.type);
|
||||||
noteType.setNoteMime(currentNote.detail.mime);
|
noteType.setNoteMime(currentNote.detail.mime);
|
||||||
|
|
||||||
if (currentNote.detail.type === 'text') {
|
if (currentNote.detail.type === 'render') {
|
||||||
// temporary workaround for https://github.com/ckeditor/ckeditor5-enter/issues/49
|
|
||||||
editor.setData(currentNote.detail.content ? currentNote.detail.content : "<p></p>");
|
|
||||||
|
|
||||||
noteDetailEl.show();
|
|
||||||
noteDetailCodeEl.hide();
|
|
||||||
noteDetailRenderEl.html('').hide();
|
|
||||||
}
|
|
||||||
else if (currentNote.detail.type === 'code') {
|
|
||||||
noteDetailEl.hide();
|
|
||||||
noteDetailCodeEl.show();
|
|
||||||
noteDetailRenderEl.html('').hide();
|
|
||||||
|
|
||||||
// this needs to happen after the element is shown, otherwise the editor won't be refresheds
|
|
||||||
codeEditor.setValue(currentNote.detail.content);
|
|
||||||
|
|
||||||
const info = CodeMirror.findModeByMIME(currentNote.detail.mime);
|
|
||||||
|
|
||||||
if (info) {
|
|
||||||
codeEditor.setOption("mode", info.mime);
|
|
||||||
CodeMirror.autoLoadMode(codeEditor, info.mode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (currentNote.detail.type === 'render') {
|
|
||||||
noteDetailEl.hide();
|
noteDetailEl.hide();
|
||||||
noteDetailCodeEl.hide();
|
noteDetailCodeEl.hide();
|
||||||
noteDetailRenderEl.html('').show();
|
noteDetailRenderEl.html('').show();
|
||||||
@ -179,7 +182,7 @@ const noteEditor = (function() {
|
|||||||
noteDetailRenderEl.html(subTree);
|
noteDetailRenderEl.html(subTree);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throwError("Unrecognized type " + currentNote.detail.type);
|
setContent(currentNote.detail.content);
|
||||||
}
|
}
|
||||||
|
|
||||||
noteChangeDisabled = false;
|
noteChangeDisabled = false;
|
||||||
@ -314,6 +317,7 @@ const noteEditor = (function() {
|
|||||||
getEditor,
|
getEditor,
|
||||||
focus,
|
focus,
|
||||||
executeCurrentNote,
|
executeCurrentNote,
|
||||||
loadAttributeList
|
loadAttributeList,
|
||||||
|
setContent
|
||||||
};
|
};
|
||||||
})();
|
})();
|
@ -640,16 +640,15 @@ const noteTree = (function() {
|
|||||||
return document.location.hash.substr(1); // strip initial #
|
return document.location.hash.substr(1); // strip initial #
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadTree() {
|
async function loadTree() {
|
||||||
return server.get('tree').then(resp => {
|
const resp = await server.get('tree');
|
||||||
startNotePath = resp.start_note_path;
|
startNotePath = resp.start_note_path;
|
||||||
|
|
||||||
if (document.location.hash) {
|
if (document.location.hash) {
|
||||||
startNotePath = getNotePathFromAddress();
|
startNotePath = getNotePathFromAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
return prepareNoteTree(resp.notes);
|
return prepareNoteTree(resp.notes);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$(() => loadTree().then(noteTree => initFancyTree(noteTree)));
|
$(() => loadTree().then(noteTree => initFancyTree(noteTree)));
|
||||||
@ -775,7 +774,7 @@ const noteTree = (function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (target === 'after') {
|
if (target === 'after') {
|
||||||
node.appendSibling(newNode).setActive(true);
|
await node.appendSibling(newNode).setActive(true);
|
||||||
}
|
}
|
||||||
else if (target === 'into') {
|
else if (target === 'into') {
|
||||||
if (!node.getChildren() && node.isFolder()) {
|
if (!node.getChildren() && node.isFolder()) {
|
||||||
@ -785,7 +784,7 @@ const noteTree = (function() {
|
|||||||
node.addChildren(newNode);
|
node.addChildren(newNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
node.getLastChild().setActive(true);
|
await node.getLastChild().setActive(true);
|
||||||
|
|
||||||
node.folder = true;
|
node.folder = true;
|
||||||
node.renderTitle();
|
node.renderTitle();
|
||||||
@ -803,6 +802,10 @@ const noteTree = (function() {
|
|||||||
await reload();
|
await reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function noteExists(noteId) {
|
||||||
|
return !!childToParents[noteId];
|
||||||
|
}
|
||||||
|
|
||||||
$(document).bind('keydown', 'ctrl+o', e => {
|
$(document).bind('keydown', 'ctrl+o', e => {
|
||||||
const node = getCurrentNode();
|
const node = getCurrentNode();
|
||||||
const parentNoteId = node.data.parentNoteId;
|
const parentNoteId = node.data.parentNoteId;
|
||||||
@ -876,6 +879,7 @@ const noteTree = (function() {
|
|||||||
removeParentChildRelation,
|
removeParentChildRelation,
|
||||||
setParentChildRelation,
|
setParentChildRelation,
|
||||||
getSelectedNodes,
|
getSelectedNodes,
|
||||||
sortAlphabetically
|
sortAlphabetically,
|
||||||
|
noteExists
|
||||||
};
|
};
|
||||||
})();
|
})();
|
@ -43,6 +43,14 @@ function nowDate() {
|
|||||||
return dateStr(new Date());
|
return dateStr(new Date());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function localDate() {
|
||||||
|
const date = new Date();
|
||||||
|
|
||||||
|
return date.getFullYear() + "-"
|
||||||
|
+ (date.getMonth() < 9 ? "0" : "") + (date.getMonth() + 1) + "-"
|
||||||
|
+ (date.getDate() < 10 ? "0" : "") + date.getDate();
|
||||||
|
}
|
||||||
|
|
||||||
function dateStr(date) {
|
function dateStr(date) {
|
||||||
return date.toISOString();
|
return date.toISOString();
|
||||||
}
|
}
|
||||||
@ -125,6 +133,7 @@ module.exports = {
|
|||||||
randomSecureToken,
|
randomSecureToken,
|
||||||
randomString,
|
randomString,
|
||||||
nowDate,
|
nowDate,
|
||||||
|
localDate,
|
||||||
dateStr,
|
dateStr,
|
||||||
parseDate,
|
parseDate,
|
||||||
parseDateTime,
|
parseDateTime,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user