fix deleting

This commit is contained in:
zadam 2020-02-12 22:25:52 +01:00
parent 789f62267c
commit 380bb0cd01
6 changed files with 20 additions and 22 deletions

View File

@ -123,7 +123,7 @@ $detail.on("click", ".note-menu-button", async e => {
noteCreateService.createNote(node.data.noteId);
}
else if (cmd === "delete") {
if (await treeChangesService.deleteNodes([node])) {
if (await treeChangesService.deleteNotes([node])) {
// move to the tree
togglePanes();
}

View File

@ -65,7 +65,7 @@ async function moveToParentNote(branchIdsToMove, newParentNoteId) {
}
}
async function deleteNodes(branchIdsToDelete) {
async function deleteNotes(treeWidget, branchIdsToDelete) {
branchIdsToDelete = filterRootNote(branchIdsToDelete);
if (branchIdsToDelete.length === 0) {
@ -119,6 +119,8 @@ async function deleteNodes(branchIdsToDelete) {
}
}
treeWidget.clearSelectedNodes();
return true;
}
@ -202,6 +204,6 @@ export default {
moveBeforeBranch,
moveAfterBranch,
moveToParentNote,
deleteNodes,
deleteNotes,
moveNodeUpInHierarchy
};

View File

@ -160,7 +160,7 @@ class TreeContextMenu {
clipboard.pasteInto(noteId);
}
else if (cmd === "delete") {
treeChangesService.deleteNodes(this.getSelectedOrActiveBranchIds());
treeChangesService.deleteNotes(this.treeWidget, this.getSelectedOrActiveBranchIds());
}
else if (cmd === "export") {
const exportDialog = await import('../dialogs/export.js');

View File

@ -53,7 +53,9 @@ function getSelectedOrActiveBranchIds(treeWidget, node) {
function getTemplates(treeWidget) {
return {
"DeleteNotes": node => {
treeChangesService.deleteNodes(getSelectedOrActiveBranchIds(treeWidget, node));
const branchIds = getSelectedOrActiveBranchIds(treeWidget, node);
treeChangesService.deleteNotes(treeWidget, branchIds);
},
"MoveNoteUp": node => {
const beforeNode = node.getPrevSibling();

View File

@ -432,6 +432,8 @@ export default class NoteTreeWidget extends TabAwareWidget {
}
newActiveNode.setActive(true, {noEvents: true});
newActiveNode.makeVisible({scrollIntoView: true});
}
}
}
@ -458,27 +460,19 @@ export default class NoteTreeWidget extends TabAwareWidget {
for (const branch of loadResults.getBranches()) {
for (const node of this.getNodesByBranchId(branch.branchId)) {
if (branch.isDeleted) {
node.data.toBeRemoved = true;
if (node.isActive()) {
let curNode = node;
const newActiveNode = node.getNextSibling()
|| node.getPrevSibling()
|| node.getParent();
while (curNode.data.toBeRemoved) {
if (curNode.getNextSibling() && !curNode.getNextSibling().data.toBeRemoved) {
curNode = curNode.getNextSibling();
}
else if (curNode.getPrevSibling() && !curNode.getPrevSibling().data.toBeRemoved) {
curNode = curNode.getPrevSibling();
}
else {
curNode = curNode.getParent();
}
if (newActiveNode) {
newActiveNode.setActive(true, {noEvents: true, noFocus: true});
}
curNode.setActive(true, {noEvents:true, noFocus:true});
}
noteIdsToReload.add(branch.parentNoteId);
node.remove();
noteIdsToUpdate.add(branch.parentNoteId);
}
else {
noteIdsToUpdate.add(branch.noteId);

View File

@ -136,7 +136,7 @@ export default class TextTypeWidget extends TypeWidget {
}
}
async doRefresh(note) {console.trace("UPDATE###" + this.componentId);
async doRefresh(note) {
this.textEditor.isReadOnly = await note.hasLabel('readOnly');
const noteComplement = await this.tabContext.getNoteComplement();