mirror of
https://github.com/TriliumNext/Notes.git
synced 2026-04-30 01:09:21 -05:00
configurable keyboard shortcuts WIP
This commit is contained in:
@@ -11,6 +11,7 @@ import dateNotesService from './date_notes.js';
|
||||
import StandardWidget from '../widgets/standard_widget.js';
|
||||
import ws from "./ws.js";
|
||||
import hoistedNoteService from "./hoisted_note.js";
|
||||
import KeyboardAction from "./keyboard_action.js";
|
||||
|
||||
/**
|
||||
* This is the main frontend API interface for scripts. It's published in the local "api" object.
|
||||
@@ -40,6 +41,9 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, tabConte
|
||||
/** @property {StandardWidget} */
|
||||
this.StandardWidget = StandardWidget;
|
||||
|
||||
/** @property {KeyboardAction} */
|
||||
this.KeyboardAction = KeyboardAction;
|
||||
|
||||
/**
|
||||
* Activates note in the tree and in the note detail.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,261 @@
|
||||
/**
|
||||
* blaa vlaa
|
||||
*/
|
||||
class KeyboardAction {
|
||||
constructor(params) {
|
||||
/** @property {string} */
|
||||
this.optionName = params.optionName;
|
||||
/** @property {string[]} */
|
||||
this.defaultShortcuts = Array.isArray(params.defaultShortcuts) ? params.defaultShortcuts : [params.defaultShortcuts];
|
||||
/** @property {string[]} */
|
||||
this.activeShortcuts = this.defaultShortcuts.slice();
|
||||
/** @property {string} */
|
||||
this.description = params.description;
|
||||
}
|
||||
|
||||
addShortcut(shortcut) {
|
||||
this.activeShortcuts.push(shortcut);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string|string[]} shortcuts
|
||||
*/
|
||||
replaceShortcuts(shortcuts) {
|
||||
this.activeShortcuts = Array.isArray(shortcuts) ? shortcuts : [shortcuts];
|
||||
}
|
||||
|
||||
/** @return {KeyboardAction[]} */
|
||||
static get allActions() {
|
||||
return Object.keys(KeyboardAction)
|
||||
.map(key => KeyboardAction[key])
|
||||
.filter(obj => obj instanceof KeyboardAction);
|
||||
}
|
||||
}
|
||||
|
||||
const ELECTRON = 1;
|
||||
|
||||
/**
|
||||
* Open "Jump to note" dialog
|
||||
* @static
|
||||
*/
|
||||
KeyboardAction.JumpToNote = new KeyboardAction({
|
||||
optionName: "JumpToNote",
|
||||
defaultShortcuts: "mod+j",
|
||||
description: 'Open "Jump to note" dialog'
|
||||
});
|
||||
|
||||
/** @static */
|
||||
KeyboardAction.MarkdownToHTML = new KeyboardAction({
|
||||
optionName: "MarkdownToHTML",
|
||||
defaultShortcuts: "mod+return"
|
||||
});
|
||||
|
||||
/** @static */
|
||||
KeyboardAction.NewTab = new KeyboardAction({
|
||||
optionName: "NewTab",
|
||||
defaultShortcuts: "mod+t",
|
||||
only: ELECTRON
|
||||
});
|
||||
|
||||
/** @static */
|
||||
KeyboardAction.CloseTab = new KeyboardAction({
|
||||
optionName: "CloseTab",
|
||||
defaultShortcuts: "mod+w",
|
||||
only: ELECTRON
|
||||
});
|
||||
|
||||
/** @static */
|
||||
KeyboardAction.NextTab = new KeyboardAction({
|
||||
optionName: "NextTab",
|
||||
defaultShortcuts: "mod+tab",
|
||||
only: ELECTRON
|
||||
});
|
||||
|
||||
/** @static */
|
||||
KeyboardAction.PreviousTab = new KeyboardAction({
|
||||
optionName: "PreviousTab",
|
||||
defaultShortcuts: "mod+shift+tab",
|
||||
only: ELECTRON
|
||||
});
|
||||
|
||||
/** @static */
|
||||
KeyboardAction.CreateNoteAfter = new KeyboardAction({
|
||||
optionName: "CreateNoteAfter",
|
||||
defaultShortcuts: "mod+o"
|
||||
});
|
||||
|
||||
/** @static */
|
||||
KeyboardAction.CreateNoteInto = new KeyboardAction({
|
||||
optionName: "CreateNoteInto",
|
||||
defaultShortcuts: "mod+p"
|
||||
});
|
||||
|
||||
/** @static */
|
||||
KeyboardAction.ScrollToActiveNote = new KeyboardAction({
|
||||
optionName: "ScrollToActiveNote",
|
||||
defaultShortcuts: "mod+."
|
||||
});
|
||||
|
||||
/** @static */
|
||||
KeyboardAction.CollapseTree = new KeyboardAction({
|
||||
optionName: "CollapseTree",
|
||||
defaultShortcuts: "alt+c"
|
||||
});
|
||||
|
||||
/** @static */
|
||||
KeyboardAction.RunSQL = new KeyboardAction({
|
||||
optionName: "RunSQL",
|
||||
defaultShortcuts: "mod+return"
|
||||
});
|
||||
|
||||
/** @static */
|
||||
KeyboardAction.FocusNote = new KeyboardAction({
|
||||
optionName: "FocusNote",
|
||||
defaultShortcuts: "return"
|
||||
});
|
||||
|
||||
/** @static */
|
||||
KeyboardAction.RunCurrentNote = new KeyboardAction({
|
||||
optionName: "RunCurrentNote",
|
||||
defaultShortcuts: "mod+return"
|
||||
});
|
||||
|
||||
/** @static */
|
||||
KeyboardAction.ClipboardCopy = new KeyboardAction({
|
||||
optionName: "ClipboardCopy",
|
||||
defaultShortcuts: "mod+c"
|
||||
});
|
||||
|
||||
/** @static */
|
||||
KeyboardAction.ClipboardPaste = new KeyboardAction({
|
||||
optionName: "ClipboardPaste",
|
||||
defaultShortcuts: "mod+v"
|
||||
});
|
||||
|
||||
/** @static */
|
||||
KeyboardAction.ClipboardCut = new KeyboardAction({
|
||||
optionName: "ClipboardCut",
|
||||
defaultShortcuts: "mod+x"
|
||||
});
|
||||
|
||||
/** @static */
|
||||
KeyboardAction.SelectAllNotesInParent = new KeyboardAction({
|
||||
optionName: "SelectAllNotesInParent",
|
||||
defaultShortcuts: "mod+a"
|
||||
});
|
||||
|
||||
/** @static */
|
||||
KeyboardAction.Undo = new KeyboardAction({
|
||||
optionName: "Undo",
|
||||
defaultShortcuts: "mod+z"
|
||||
});
|
||||
|
||||
/** @static */
|
||||
KeyboardAction.Redo = new KeyboardAction({
|
||||
optionName: "Redo",
|
||||
defaultShortcuts: "mod+y"
|
||||
});
|
||||
|
||||
/** @static */
|
||||
KeyboardAction.AddLinkToText = new KeyboardAction({
|
||||
optionName: "AddLinkToText",
|
||||
defaultShortcuts: "mod+l"
|
||||
});
|
||||
|
||||
/** @static */
|
||||
KeyboardAction.CloneNotesTo = new KeyboardAction({
|
||||
optionName: "CloneNotesTo",
|
||||
defaultShortcuts: "mod+shift+c"
|
||||
});
|
||||
|
||||
/** @static */
|
||||
KeyboardAction.MoveNotesTo = new KeyboardAction({
|
||||
optionName: "MoveNotesTo",
|
||||
defaultShortcuts: "mod+shift+c"
|
||||
});
|
||||
|
||||
/** @static */
|
||||
KeyboardAction.SearchNotes = new KeyboardAction({
|
||||
optionName: "SearchNotes",
|
||||
defaultShortcuts: "mod+s"
|
||||
});
|
||||
|
||||
/** @static */
|
||||
KeyboardAction.ShowAttributes = new KeyboardAction({
|
||||
optionName: "ShowAttributes",
|
||||
defaultShortcuts: "alt+a"
|
||||
});
|
||||
|
||||
/** @static */
|
||||
KeyboardAction.ShowHelp = new KeyboardAction({
|
||||
optionName: "ShowHelp",
|
||||
defaultShortcuts: "f1"
|
||||
});
|
||||
|
||||
/** @static */
|
||||
KeyboardAction.OpenSQLConsole = new KeyboardAction({
|
||||
optionName: "OpenSQLConsole",
|
||||
defaultShortcuts: "alt+o"
|
||||
});
|
||||
|
||||
/** @static */
|
||||
KeyboardAction.BackInNoteHistory = new KeyboardAction({
|
||||
optionName: "BackInNoteHistory",
|
||||
defaultShortcuts: "alt+left"
|
||||
});
|
||||
|
||||
/** @static */
|
||||
KeyboardAction.ForwardInNoteHistory = new KeyboardAction({
|
||||
optionName: "ForwardInNoteHistory",
|
||||
defaultShortcuts: "alt+right"
|
||||
});
|
||||
|
||||
/** @static */
|
||||
KeyboardAction.ToggleZenMode = new KeyboardAction({
|
||||
optionName: "ToggleZenMode",
|
||||
defaultShortcuts: "alt+m"
|
||||
});
|
||||
|
||||
/** @static */
|
||||
KeyboardAction.InsertDateTime = new KeyboardAction({
|
||||
optionName: "InsertDateTime",
|
||||
defaultShortcuts: "alt+t"
|
||||
});
|
||||
|
||||
/** @static */
|
||||
KeyboardAction.ReloadApp = new KeyboardAction({
|
||||
optionName: "ReloadApp",
|
||||
defaultShortcuts: ["f5", "mod+r"]
|
||||
});
|
||||
|
||||
/** @static */
|
||||
KeyboardAction.OpenDevTools = new KeyboardAction({
|
||||
optionName: "OpenDevTools",
|
||||
defaultShortcuts: "mod+shift+i"
|
||||
});
|
||||
|
||||
/** @static */
|
||||
KeyboardAction.FindInText = new KeyboardAction({
|
||||
optionName: "FindInText",
|
||||
defaultShortcuts: "mod+f"
|
||||
});
|
||||
|
||||
/** @static */
|
||||
KeyboardAction.ToggleFullscreen = new KeyboardAction({
|
||||
optionName: "ToggleFullscreen",
|
||||
defaultShortcuts: "f11"
|
||||
});
|
||||
|
||||
/** @static */
|
||||
KeyboardAction.ZoomOut = new KeyboardAction({
|
||||
optionName: "ZoomOut",
|
||||
defaultShortcuts: "mod+-"
|
||||
});
|
||||
|
||||
/** @static */
|
||||
KeyboardAction.ZoomIn = new KeyboardAction({
|
||||
optionName: "ZoomIn",
|
||||
defaultShortcuts: "mod+="
|
||||
});
|
||||
|
||||
export default KeyboardAction;
|
||||
@@ -0,0 +1,16 @@
|
||||
class Actions {
|
||||
constructor() {
|
||||
this.JUMP_TO = "";
|
||||
}
|
||||
}
|
||||
|
||||
const actions = new Actions();
|
||||
|
||||
function bind() {
|
||||
|
||||
}
|
||||
|
||||
export default {
|
||||
actions,
|
||||
bind
|
||||
};
|
||||
@@ -0,0 +1,157 @@
|
||||
const ELECTRON = "electron";
|
||||
|
||||
const KEYBOARD_ACTIONS = [
|
||||
{
|
||||
optionName: "JumpToNote",
|
||||
defaultShortcuts: ["mod+j"],
|
||||
description: 'Open "Jump to note" dialog'
|
||||
},
|
||||
{
|
||||
optionName: "MarkdownToHTML",
|
||||
defaultShortcuts: ["mod+return"]
|
||||
},
|
||||
{
|
||||
optionName: "NewTab",
|
||||
defaultShortcuts: ["mod+t"],
|
||||
only: ELECTRON
|
||||
},
|
||||
{
|
||||
optionName: "CloseTab",
|
||||
defaultShortcuts: ["mod+w"],
|
||||
only: ELECTRON
|
||||
},
|
||||
{
|
||||
optionName: "NextTab",
|
||||
defaultShortcuts: ["mod+tab"],
|
||||
only: ELECTRON
|
||||
},
|
||||
{
|
||||
optionName: "PreviousTab",
|
||||
defaultShortcuts: ["mod+shift+tab"],
|
||||
only: ELECTRON
|
||||
},
|
||||
{
|
||||
optionName: "CreateNoteAfter",
|
||||
defaultShortcuts: ["mod+o"]
|
||||
},
|
||||
{
|
||||
optionName: "CreateNoteInto",
|
||||
defaultShortcuts: ["mod+p"]
|
||||
},
|
||||
{
|
||||
optionName: "ScrollToActiveNote",
|
||||
defaultShortcuts: ["mod+."]
|
||||
},
|
||||
{
|
||||
optionName: "CollapseTree",
|
||||
defaultShortcuts: ["alt+c"]
|
||||
},
|
||||
{
|
||||
optionName: "RunSQL",
|
||||
defaultShortcuts: ["mod+return"]
|
||||
},
|
||||
{
|
||||
optionName: "FocusNote",
|
||||
defaultShortcuts: ["return"]
|
||||
},
|
||||
{
|
||||
optionName: "RunCurrentNote",
|
||||
defaultShortcuts: ["mod+return"]
|
||||
},
|
||||
{
|
||||
optionName: "ClipboardCopy",
|
||||
defaultShortcuts: ["mod+c"]
|
||||
},
|
||||
{
|
||||
optionName: "ClipboardPaste",
|
||||
defaultShortcuts: ["mod+v"]
|
||||
},
|
||||
{
|
||||
optionName: "ClipboardCut",
|
||||
defaultShortcuts: ["mod+x"]
|
||||
},
|
||||
{
|
||||
optionName: "SelectAllNotesInParent",
|
||||
defaultShortcuts: ["mod+a"]
|
||||
},
|
||||
{
|
||||
optionName: "Undo",
|
||||
defaultShortcuts: ["mod+z"]
|
||||
},
|
||||
{
|
||||
optionName: "Redo",
|
||||
defaultShortcuts: ["mod+y"]
|
||||
},
|
||||
{
|
||||
optionName: "AddLinkToText",
|
||||
defaultShortcuts: ["mod+l"]
|
||||
},
|
||||
{
|
||||
optionName: "CloneNotesTo",
|
||||
defaultShortcuts: ["mod+shift+c"]
|
||||
},
|
||||
{
|
||||
optionName: "MoveNotesTo",
|
||||
defaultShortcuts: ["mod+shift+c"]
|
||||
},
|
||||
{
|
||||
optionName: "SearchNotes",
|
||||
defaultShortcuts: ["mod+s"]
|
||||
},
|
||||
{
|
||||
optionName: "ShowAttributes",
|
||||
defaultShortcuts: ["alt+a"]
|
||||
},
|
||||
{
|
||||
optionName: "ShowHelp",
|
||||
defaultShortcuts: ["f1"]
|
||||
},
|
||||
{
|
||||
optionName: "OpenSQLConsole",
|
||||
defaultShortcuts: ["alt+o"]
|
||||
},
|
||||
{
|
||||
optionName: "BackInNoteHistory",
|
||||
defaultShortcuts: ["alt+left"]
|
||||
},
|
||||
{
|
||||
optionName: "ForwardInNoteHistory",
|
||||
defaultShortcuts: ["alt+right"]
|
||||
},
|
||||
{
|
||||
optionName: "ToggleZenMode",
|
||||
defaultShortcuts: ["alt+m"]
|
||||
},
|
||||
{
|
||||
optionName: "InsertDateTime",
|
||||
defaultShortcuts: ["alt+t"]
|
||||
},
|
||||
{
|
||||
optionName: "ReloadApp",
|
||||
defaultShortcuts: ["f5", "mod+r"]
|
||||
},
|
||||
{
|
||||
optionName: "OpenDevTools",
|
||||
defaultShortcuts: ["mod+shift+i"]
|
||||
},
|
||||
{
|
||||
optionName: "FindInText",
|
||||
defaultShortcuts: ["mod+f"]
|
||||
},
|
||||
{
|
||||
optionName: "ToggleFullscreen",
|
||||
defaultShortcuts: ["f11"]
|
||||
},
|
||||
{
|
||||
optionName: "ZoomOut",
|
||||
defaultShortcuts: ["mod+-"]
|
||||
},
|
||||
{
|
||||
optionName: "ZoomIn",
|
||||
defaultShortcuts: ["mod+="]
|
||||
}
|
||||
];
|
||||
|
||||
module.exports = {
|
||||
KEYBOARD_ACTIONS
|
||||
};
|
||||
@@ -5,6 +5,7 @@ const appInfo = require('./app_info');
|
||||
const utils = require('./utils');
|
||||
const log = require('./log');
|
||||
const dateUtils = require('./date_utils');
|
||||
const keyboardActions = require('./keyboard_actions');
|
||||
|
||||
async function initDocumentOptions() {
|
||||
await optionService.createOption('documentId', utils.randomSecureToken(16), false);
|
||||
@@ -85,7 +86,9 @@ const defaultOptions = [
|
||||
async function initStartupOptions() {
|
||||
const optionsMap = await optionService.getOptionsMap();
|
||||
|
||||
for (const {name, value, isSynced} of defaultOptions) {
|
||||
const allDefaultOptions = defaultOptions.concat(getKeyboardDefaultOptions());
|
||||
|
||||
for (const {name, value, isSynced} of allDefaultOptions) {
|
||||
if (!(name in optionsMap)) {
|
||||
await optionService.createOption(name, value, isSynced);
|
||||
|
||||
@@ -94,6 +97,16 @@ async function initStartupOptions() {
|
||||
}
|
||||
}
|
||||
|
||||
function getKeyboardDefaultOptions() {
|
||||
return keyboardActions.KEYBOARD_ACTIONS.map(ka => {
|
||||
return {
|
||||
name: "keyboardShortcuts" + ka.optionName,
|
||||
value: JSON.stringify(ka.defaultShortcuts),
|
||||
isSynced: false
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
initDocumentOptions,
|
||||
initSyncedOptions,
|
||||
|
||||
Reference in New Issue
Block a user