mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
fix "create note after" keyboard shortcut
This commit is contained in:
parent
d4d54c5f01
commit
5a6066dcd1
@ -10,6 +10,7 @@ import treeService from "./tree.js";
|
||||
import Component from "../widgets/component.js";
|
||||
import keyboardActionsService from "./keyboard_actions.js";
|
||||
import MobileScreenSwitcherExecutor from "../widgets/mobile_screen_switcher.js";
|
||||
import MainTreeExecutors from "./main_tree_executors.js";
|
||||
|
||||
class AppContext extends Component {
|
||||
setLayout(layout) {
|
||||
@ -45,7 +46,8 @@ class AppContext extends Component {
|
||||
this.executors = [
|
||||
this.tabManager,
|
||||
new DialogCommandExecutor(),
|
||||
new Entrypoints()
|
||||
new Entrypoints(),
|
||||
new MainTreeExecutors()
|
||||
];
|
||||
|
||||
if (utils.isMobile()) {
|
||||
|
@ -165,27 +165,4 @@ export default class Entrypoints extends Component {
|
||||
}
|
||||
|
||||
createTopLevelNoteCommand() { noteCreateService.createNewTopLevelNote(); }
|
||||
|
||||
async cloneNotesToCommand() {
|
||||
const selectedOrActiveNoteIds = appContext.mainTreeWidget.getSelectedOrActiveNodes().map(node => node.data.noteId);
|
||||
|
||||
this.triggerCommand('cloneNoteIdsTo', {noteIds: selectedOrActiveNoteIds});
|
||||
}
|
||||
|
||||
async moveNotesToCommand() {
|
||||
const selectedOrActiveBranchIds = appContext.mainTreeWidget.getSelectedOrActiveNodes().map(node => node.data.branchId);
|
||||
|
||||
this.triggerCommand('moveBranchIdsTo', {branchIds: selectedOrActiveBranchIds});
|
||||
}
|
||||
|
||||
async createNoteIntoCommand() {
|
||||
const note = appContext.tabManager.getActiveTabNote();
|
||||
|
||||
if (note) {
|
||||
await noteCreateService.createNote(note.noteId, {
|
||||
isProtected: note.isProtected,
|
||||
saveSelection: false
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
56
src/public/javascripts/services/main_tree_executors.js
Normal file
56
src/public/javascripts/services/main_tree_executors.js
Normal file
@ -0,0 +1,56 @@
|
||||
import appContext from "./app_context.js";
|
||||
import noteCreateService from "./note_create.js";
|
||||
import treeService from "./tree.js";
|
||||
import hoistedNoteService from "./hoisted_note.js";
|
||||
import Component from "../widgets/component.js";
|
||||
|
||||
/**
|
||||
* This class contains command executors which logically belong to the NoteTree widget, but for better user experience
|
||||
* the keyboard shortcuts must be active on the whole screen and not just on the widget itself, so the executors
|
||||
* must be at the root of the component tree.
|
||||
*/
|
||||
export default class MainTreeExecutors extends Component {
|
||||
get tree() {
|
||||
return appContext.mainTreeWidget;
|
||||
}
|
||||
|
||||
async cloneNotesToCommand() {
|
||||
const selectedOrActiveNoteIds = this.tree.getSelectedOrActiveNodes().map(node => node.data.noteId);
|
||||
|
||||
this.triggerCommand('cloneNoteIdsTo', {noteIds: selectedOrActiveNoteIds});
|
||||
}
|
||||
|
||||
async moveNotesToCommand() {
|
||||
const selectedOrActiveBranchIds = this.tree.getSelectedOrActiveNodes().map(node => node.data.branchId);
|
||||
|
||||
this.triggerCommand('moveBranchIdsTo', {branchIds: selectedOrActiveBranchIds});
|
||||
}
|
||||
|
||||
async createNoteIntoCommand() {
|
||||
const note = appContext.tabManager.getActiveTabNote();
|
||||
|
||||
if (note) {
|
||||
await noteCreateService.createNote(note.noteId, {
|
||||
isProtected: note.isProtected,
|
||||
saveSelection: false
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async createNoteAfterCommand() {
|
||||
const node = this.tree.getActiveNode();
|
||||
const parentNoteId = node.data.parentNoteId;
|
||||
const isProtected = await treeService.getParentProtectedStatus(node);
|
||||
|
||||
if (node.data.noteId === 'root' || node.data.noteId === hoistedNoteService.getHoistedNoteId()) {
|
||||
return;
|
||||
}
|
||||
|
||||
await noteCreateService.createNote(parentNoteId, {
|
||||
target: 'after',
|
||||
targetBranchId: node.data.branchId,
|
||||
isProtected: isProtected,
|
||||
saveSelection: true
|
||||
});
|
||||
}
|
||||
}
|
@ -558,23 +558,6 @@ export default class NoteTreeWidget extends TabAwareWidget {
|
||||
}
|
||||
}
|
||||
|
||||
async createNoteAfterCommand() {
|
||||
const node = this.getActiveNode();
|
||||
const parentNoteId = node.data.parentNoteId;
|
||||
const isProtected = await treeService.getParentProtectedStatus(node);
|
||||
|
||||
if (node.data.noteId === 'root' || node.data.noteId === hoistedNoteService.getHoistedNoteId()) {
|
||||
return;
|
||||
}
|
||||
|
||||
await noteCreateService.createNote(parentNoteId, {
|
||||
target: 'after',
|
||||
targetBranchId: node.data.branchId,
|
||||
isProtected: isProtected,
|
||||
saveSelection: true
|
||||
});
|
||||
}
|
||||
|
||||
async setExpandedToServer(branchId, isExpanded) {
|
||||
utils.assertArguments(branchId);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user