mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
use notePath instead of noteId for note creation to correctly work with cloned ancestors
This commit is contained in:
parent
8192b51b8a
commit
721e5da672
@ -27,28 +27,28 @@ export default class MainTreeExecutors extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async createNoteIntoCommand() {
|
async createNoteIntoCommand() {
|
||||||
const activeNote = appContext.tabManager.getActiveTabNote();
|
const activeTabContext = appContext.tabManager.getActiveTabContext();
|
||||||
|
|
||||||
if (!activeNote) {
|
if (!activeTabContext) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await noteCreateService.createNote(activeNote.noteId, {
|
await noteCreateService.createNote(activeTabContext.notePath, {
|
||||||
isProtected: activeNote.isProtected,
|
isProtected: activeTabContext.note.isProtected,
|
||||||
saveSelection: false
|
saveSelection: false
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async createNoteAfterCommand() {
|
async createNoteAfterCommand() {
|
||||||
const node = this.tree.getActiveNode();
|
const node = this.tree.getActiveNode();
|
||||||
const parentNoteId = node.data.parentNoteId;
|
const parentNotePath = treeService.getNotePath(node.getParent());
|
||||||
const isProtected = await treeService.getParentProtectedStatus(node);
|
const isProtected = await treeService.getParentProtectedStatus(node);
|
||||||
|
|
||||||
if (node.data.noteId === 'root' || node.data.noteId === hoistedNoteService.getHoistedNoteId()) {
|
if (node.data.noteId === 'root' || node.data.noteId === hoistedNoteService.getHoistedNoteId()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await noteCreateService.createNote(parentNoteId, {
|
await noteCreateService.createNote(parentNotePath, {
|
||||||
target: 'after',
|
target: 'after',
|
||||||
targetBranchId: node.data.branchId,
|
targetBranchId: node.data.branchId,
|
||||||
isProtected: isProtected,
|
isProtected: isProtected,
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
import hoistedNoteService from "./hoisted_note.js";
|
|
||||||
import appContext from "./app_context.js";
|
import appContext from "./app_context.js";
|
||||||
import utils from "./utils.js";
|
import utils from "./utils.js";
|
||||||
import protectedSessionHolder from "./protected_session_holder.js";
|
import protectedSessionHolder from "./protected_session_holder.js";
|
||||||
import server from "./server.js";
|
import server from "./server.js";
|
||||||
import ws from "./ws.js";
|
import ws from "./ws.js";
|
||||||
import treeCache from "./tree_cache.js";
|
import treeCache from "./tree_cache.js";
|
||||||
|
import treeService from "./tree.js";
|
||||||
import toastService from "./toast.js";
|
import toastService from "./toast.js";
|
||||||
|
|
||||||
async function createNote(parentNoteId, options = {}) {
|
async function createNote(parentNotePath, options = {}) {
|
||||||
options = Object.assign({
|
options = Object.assign({
|
||||||
activate: true,
|
activate: true,
|
||||||
focus: 'title',
|
focus: 'title',
|
||||||
@ -30,6 +30,8 @@ async function createNote(parentNoteId, options = {}) {
|
|||||||
|
|
||||||
const newNoteName = options.title || "new note";
|
const newNoteName = options.title || "new note";
|
||||||
|
|
||||||
|
const parentNoteId = treeService.getNoteIdFromNotePath(parentNotePath);
|
||||||
|
|
||||||
const {note, branch} = await server.post(`notes/${parentNoteId}/children?target=${options.target}&targetBranchId=${options.targetBranchId}`, {
|
const {note, branch} = await server.post(`notes/${parentNoteId}/children?target=${options.target}&targetBranchId=${options.targetBranchId}`, {
|
||||||
title: newNoteName,
|
title: newNoteName,
|
||||||
content: options.content || "",
|
content: options.content || "",
|
||||||
@ -47,7 +49,7 @@ async function createNote(parentNoteId, options = {}) {
|
|||||||
|
|
||||||
if (options.activate) {
|
if (options.activate) {
|
||||||
const activeTabContext = appContext.tabManager.getActiveTabContext();
|
const activeTabContext = appContext.tabManager.getActiveTabContext();
|
||||||
await activeTabContext.setNote(note.noteId);
|
await activeTabContext.setNote(`${parentNotePath}/${note.noteId}`);
|
||||||
|
|
||||||
if (options.focus === 'title') {
|
if (options.focus === 'title') {
|
||||||
appContext.triggerEvent('focusAndSelectTitle');
|
appContext.triggerEvent('focusAndSelectTitle');
|
||||||
@ -82,12 +84,13 @@ function parseSelectedHtml(selectedHtml) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function duplicateSubtree(noteId, parentNoteId) {
|
async function duplicateSubtree(noteId, parentNotePath) {
|
||||||
|
const parentNoteId = treeService.getNoteIdFromNotePath(parentNotePath);
|
||||||
const {note} = await server.post(`notes/${noteId}/duplicate/${parentNoteId}`);
|
const {note} = await server.post(`notes/${noteId}/duplicate/${parentNoteId}`);
|
||||||
|
|
||||||
await ws.waitForMaxKnownEntityChangeId();
|
await ws.waitForMaxKnownEntityChangeId();
|
||||||
|
|
||||||
await appContext.tabManager.activateOrOpenNote(note.noteId);
|
await appContext.tabManager.activateOrOpenNote(`${parentNotePath}/${note.noteId}`);
|
||||||
|
|
||||||
const origNote = await treeCache.getNote(noteId);
|
const origNote = await treeCache.getNote(noteId);
|
||||||
toastService.showMessage(`Note "${origNote.title}" has been duplicated`);
|
toastService.showMessage(`Note "${origNote.title}" has been duplicated`);
|
||||||
|
@ -112,10 +112,10 @@ class TreeContextMenu {
|
|||||||
appContext.tabManager.openTabWithNoteWithHoisting(notePath);
|
appContext.tabManager.openTabWithNoteWithHoisting(notePath);
|
||||||
}
|
}
|
||||||
else if (command === "insertNoteAfter") {
|
else if (command === "insertNoteAfter") {
|
||||||
const parentNoteId = this.node.data.parentNoteId;
|
const parentNotePath = treeService.getNotePath(this.node.getParent());
|
||||||
const isProtected = await treeService.getParentProtectedStatus(this.node);
|
const isProtected = await treeService.getParentProtectedStatus(this.node);
|
||||||
|
|
||||||
noteCreateService.createNote(parentNoteId, {
|
noteCreateService.createNote(parentNotePath, {
|
||||||
target: 'after',
|
target: 'after',
|
||||||
targetBranchId: this.node.data.branchId,
|
targetBranchId: this.node.data.branchId,
|
||||||
type: type,
|
type: type,
|
||||||
@ -123,14 +123,14 @@ class TreeContextMenu {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if (command === "insertChildNote") {
|
else if (command === "insertChildNote") {
|
||||||
noteCreateService.createNote(noteId, {
|
const parentNotePath = treeService.getNotePath(this.node);
|
||||||
|
|
||||||
|
noteCreateService.createNote(parentNotePath, {
|
||||||
type: type,
|
type: type,
|
||||||
isProtected: this.node.data.isProtected
|
isProtected: this.node.data.isProtected
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.log("Triggering", command, notePath);
|
|
||||||
|
|
||||||
this.treeWidget.triggerCommand(command, {node: this.node, notePath: notePath});
|
this.treeWidget.triggerCommand(command, {node: this.node, notePath: notePath});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -491,7 +491,7 @@ export default class AttributeEditorWidget extends TabAwareWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async createNoteForReferenceLink(title) {
|
async createNoteForReferenceLink(title) {
|
||||||
const {note} = await noteCreateService.createNote(this.noteId, {
|
const {note} = await noteCreateService.createNote(this.notePath, {
|
||||||
activate: false,
|
activate: false,
|
||||||
title: title
|
title: title
|
||||||
});
|
});
|
||||||
|
@ -26,7 +26,7 @@ class MobileDetailMenuWidget extends BasicWidget {
|
|||||||
],
|
],
|
||||||
selectMenuItemHandler: async ({command}) => {
|
selectMenuItemHandler: async ({command}) => {
|
||||||
if (command === "insertChildNote") {
|
if (command === "insertChildNote") {
|
||||||
noteCreateService.createNote(note.noteId);
|
noteCreateService.createNote(appContext.tabManager.getActiveTabNotePath());
|
||||||
}
|
}
|
||||||
else if (command === "delete") {
|
else if (command === "delete") {
|
||||||
const notePath = appContext.tabManager.getActiveTabNotePath();
|
const notePath = appContext.tabManager.getActiveTabNotePath();
|
||||||
|
@ -318,7 +318,7 @@ export default class NoteDetailWidget extends TabAwareWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// without await as this otherwise causes deadlock through component mutex
|
// without await as this otherwise causes deadlock through component mutex
|
||||||
noteCreateService.createNote(note.noteId, {
|
noteCreateService.createNote(appContext.tabManager.getActiveTabNotePath(), {
|
||||||
isProtected: note.isProtected,
|
isProtected: note.isProtected,
|
||||||
saveSelection: true
|
saveSelection: true
|
||||||
});
|
});
|
||||||
|
@ -203,8 +203,9 @@ export default class NoteTreeWidget extends TabAwareWidget {
|
|||||||
this.$tree.on("mousedown", ".refresh-search-button", e => this.refreshSearch(e));
|
this.$tree.on("mousedown", ".refresh-search-button", e => this.refreshSearch(e));
|
||||||
this.$tree.on("mousedown", ".add-note-button", e => {
|
this.$tree.on("mousedown", ".add-note-button", e => {
|
||||||
const node = $.ui.fancytree.getNode(e);
|
const node = $.ui.fancytree.getNode(e);
|
||||||
|
const parentNotePath = treeService.getNotePath(node);
|
||||||
|
|
||||||
noteCreateService.createNote(node.data.noteId, {
|
noteCreateService.createNote(parentNotePath, {
|
||||||
isProtected: node.data.isProtected
|
isProtected: node.data.isProtected
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -274,7 +274,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async createNoteForReferenceLink(title) {
|
async createNoteForReferenceLink(title) {
|
||||||
const {note} = await noteCreateService.createNote(this.noteId, {
|
const {note} = await noteCreateService.createNote(this.notePath, {
|
||||||
activate: false,
|
activate: false,
|
||||||
title: title
|
title: title
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user