mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
added more careful handling of search note operations, fixes #683
This commit is contained in:
parent
df40accdd4
commit
9c9ef1c7b4
@ -58,6 +58,11 @@ async function moveToNode(nodesToMove, toNode) {
|
|||||||
nodesToMove = await filterRootNote(nodesToMove);
|
nodesToMove = await filterRootNote(nodesToMove);
|
||||||
|
|
||||||
for (const nodeToMove of nodesToMove) {
|
for (const nodeToMove of nodesToMove) {
|
||||||
|
if (nodeToMove.data.noteId === await hoistedNoteService.getHoistedNoteId()
|
||||||
|
|| nodeToMove.getParent().data.noteType === 'search') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
const resp = await server.put('branches/' + nodeToMove.data.branchId + '/move-to/' + toNode.data.noteId);
|
const resp = await server.put('branches/' + nodeToMove.data.branchId + '/move-to/' + toNode.data.noteId);
|
||||||
|
|
||||||
if (!resp.success) {
|
if (!resp.success) {
|
||||||
@ -152,7 +157,9 @@ async function deleteNodes(nodes) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function moveNodeUpInHierarchy(node) {
|
async function moveNodeUpInHierarchy(node) {
|
||||||
if (await hoistedNoteService.isRootNode(node) || await hoistedNoteService.isTopLevelNode(node)) {
|
if (await hoistedNoteService.isRootNode(node)
|
||||||
|
|| await hoistedNoteService.isTopLevelNode(node)
|
||||||
|
|| node.getParent().data.noteType === 'search') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ import treeUtils from "./tree_utils.js";
|
|||||||
import treeChangesService from "./branches.js";
|
import treeChangesService from "./branches.js";
|
||||||
import cloningService from "./cloning.js";
|
import cloningService from "./cloning.js";
|
||||||
import toastService from "./toast.js";
|
import toastService from "./toast.js";
|
||||||
|
import hoistedNoteService from "./hoisted_note.js";
|
||||||
|
|
||||||
let clipboardIds = [];
|
let clipboardIds = [];
|
||||||
let clipboardMode = null;
|
let clipboardMode = null;
|
||||||
@ -66,10 +67,16 @@ function copy(nodes) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function cut(nodes) {
|
function cut(nodes) {
|
||||||
clipboardIds = nodes.map(node => node.key);
|
clipboardIds = nodes
|
||||||
clipboardMode = 'cut';
|
.filter(node => node.data.noteId !== hoistedNoteService.getHoistedNoteNoPromise())
|
||||||
|
.filter(node => node.getParent().data.noteType !== 'search')
|
||||||
|
.map(node => node.data.noteId);
|
||||||
|
|
||||||
toastService.showMessage("Note(s) have been cut into clipboard.");
|
if (clipboardIds.length > 0) {
|
||||||
|
clipboardMode = 'cut';
|
||||||
|
|
||||||
|
toastService.showMessage("Note(s) have been cut into clipboard.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function isEmpty() {
|
function isEmpty() {
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
import treeService from './tree.js';
|
import treeService from './tree.js';
|
||||||
import treeChangesService from './branches.js';
|
import treeChangesService from './branches.js';
|
||||||
|
import hoistedNoteService from './hoisted_note.js';
|
||||||
|
|
||||||
const dragAndDropSetup = {
|
const dragAndDropSetup = {
|
||||||
autoExpandMS: 600,
|
autoExpandMS: 600,
|
||||||
dragStart: (node, data) => {
|
dragStart: (node, data) => {
|
||||||
// don't allow dragging root node
|
// don't allow dragging root node
|
||||||
if (node.data.noteId === 'root') {
|
if (node.data.noteId === hoistedNoteService.getHoistedNoteNoPromise()
|
||||||
|
|| node.getParent().data.noteType === 'search') {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,6 +27,17 @@ const dragAndDropSetup = {
|
|||||||
dragEnter: (node, data) => true, // allow drop on any node
|
dragEnter: (node, data) => true, // allow drop on any node
|
||||||
dragOver: (node, data) => true,
|
dragOver: (node, data) => true,
|
||||||
dragDrop: async (node, data) => {
|
dragDrop: async (node, data) => {
|
||||||
|
if ((data.hitMode === 'over' && node.data.noteType === 'search') ||
|
||||||
|
(['after', 'before'].includes(data.hitMode)
|
||||||
|
&& (node.data.noteId === hoistedNoteService.getHoistedNoteNoPromise() || node.getParent().data.noteType === 'search'))) {
|
||||||
|
|
||||||
|
const infoDialog = await import('../dialogs/info.js');
|
||||||
|
|
||||||
|
await infoDialog.info("Dropping notes into this location is not allowed.");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const dataTransfer = data.dataTransfer;
|
const dataTransfer = data.dataTransfer;
|
||||||
|
|
||||||
if (dataTransfer && dataTransfer.files && dataTransfer.files.length > 0) {
|
if (dataTransfer && dataTransfer.files && dataTransfer.files.length > 0) {
|
||||||
|
@ -3,12 +3,16 @@ import server from "./server.js";
|
|||||||
import tree from "./tree.js";
|
import tree from "./tree.js";
|
||||||
import noteDetailService from "./note_detail.js";
|
import noteDetailService from "./note_detail.js";
|
||||||
|
|
||||||
let hoistedNoteId;
|
let hoistedNoteId = 'root';
|
||||||
|
|
||||||
optionsService.waitForOptions().then(options => {
|
optionsService.waitForOptions().then(options => {
|
||||||
hoistedNoteId = options.get('hoistedNoteId');
|
hoistedNoteId = options.get('hoistedNoteId');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function getHoistedNoteNoPromise() {
|
||||||
|
return hoistedNoteId;
|
||||||
|
}
|
||||||
|
|
||||||
async function getHoistedNoteId() {
|
async function getHoistedNoteId() {
|
||||||
await optionsService.waitForOptions();
|
await optionsService.waitForOptions();
|
||||||
|
|
||||||
@ -49,6 +53,7 @@ async function isRootNode(node) {
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
getHoistedNoteId,
|
getHoistedNoteId,
|
||||||
|
getHoistedNoteNoPromise,
|
||||||
setHoistedNoteId,
|
setHoistedNoteId,
|
||||||
unhoist,
|
unhoist,
|
||||||
isTopLevelNode,
|
isTopLevelNode,
|
||||||
|
@ -676,6 +676,7 @@ async function createNote(node, parentNoteId, target, extraOptions = {}) {
|
|||||||
refKey: branchEntity.noteId,
|
refKey: branchEntity.noteId,
|
||||||
branchId: branchEntity.branchId,
|
branchId: branchEntity.branchId,
|
||||||
isProtected: extraOptions.isProtected,
|
isProtected: extraOptions.isProtected,
|
||||||
|
type: noteEntity.type,
|
||||||
extraClasses: await treeBuilder.getExtraClasses(noteEntity),
|
extraClasses: await treeBuilder.getExtraClasses(noteEntity),
|
||||||
icon: await treeBuilder.getIcon(noteEntity),
|
icon: await treeBuilder.getIcon(noteEntity),
|
||||||
folder: extraOptions.type === 'search',
|
folder: extraOptions.type === 'search',
|
||||||
|
@ -70,6 +70,7 @@ async function prepareNode(branch) {
|
|||||||
parentNoteId: branch.parentNoteId,
|
parentNoteId: branch.parentNoteId,
|
||||||
branchId: branch.branchId,
|
branchId: branch.branchId,
|
||||||
isProtected: note.isProtected,
|
isProtected: note.isProtected,
|
||||||
|
noteType: note.type,
|
||||||
title: utils.escapeHtml(title),
|
title: utils.escapeHtml(title),
|
||||||
extraClasses: await getExtraClasses(note),
|
extraClasses: await getExtraClasses(note),
|
||||||
icon: await getIcon(note),
|
icon: await getIcon(note),
|
||||||
|
@ -65,7 +65,7 @@ class TreeContextMenu {
|
|||||||
{ title: "Copy / clone <kbd>Ctrl+C</kbd>", cmd: "copy", uiIcon: "files",
|
{ title: "Copy / clone <kbd>Ctrl+C</kbd>", cmd: "copy", uiIcon: "files",
|
||||||
enabled: isNotRoot },
|
enabled: isNotRoot },
|
||||||
{ title: "Cut <kbd>Ctrl+X</kbd>", cmd: "cut", uiIcon: "scissors",
|
{ title: "Cut <kbd>Ctrl+X</kbd>", cmd: "cut", uiIcon: "scissors",
|
||||||
enabled: isNotRoot },
|
enabled: isNotRoot && !isHoisted && parentNotSearch },
|
||||||
{ title: "Paste into <kbd>Ctrl+V</kbd>", cmd: "pasteInto", uiIcon: "clipboard",
|
{ title: "Paste into <kbd>Ctrl+V</kbd>", cmd: "pasteInto", uiIcon: "clipboard",
|
||||||
enabled: !clipboard.isEmpty() && notSearch && noSelectedNotes },
|
enabled: !clipboard.isEmpty() && notSearch && noSelectedNotes },
|
||||||
{ title: "Paste after", cmd: "pasteAfter", uiIcon: "clipboard",
|
{ title: "Paste after", cmd: "pasteAfter", uiIcon: "clipboard",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user