when expanding/collpasing, set the flag also to the tree cache

This commit is contained in:
zadam 2020-05-12 10:52:07 +02:00
parent 9d8b8e26a1
commit e08b0141a4

View File

@ -251,8 +251,8 @@ export default class NoteTreeWidget extends TabAwareWidget {
this.triggerCommand('setActiveScreen', {screen:'detail'}); this.triggerCommand('setActiveScreen', {screen:'detail'});
} }
}, },
expand: (event, data) => this.setExpandedToServer(data.node.data.branchId, true), expand: (event, data) => this.setExpanded(data.node.data.branchId, true),
collapse: (event, data) => this.setExpandedToServer(data.node.data.branchId, false), collapse: (event, data) => this.setExpanded(data.node.data.branchId, false),
hotkeys: utils.isMobile() ? undefined : { keydown: await this.getHotKeys() }, hotkeys: utils.isMobile() ? undefined : { keydown: await this.getHotKeys() },
dnd5: { dnd5: {
autoExpandMS: 600, autoExpandMS: 600,
@ -929,12 +929,13 @@ export default class NoteTreeWidget extends TabAwareWidget {
} }
} }
async setExpandedToServer(branchId, isExpanded) { async setExpanded(branchId, isExpanded) {
utils.assertArguments(branchId); utils.assertArguments(branchId);
const expandedNum = isExpanded ? 1 : 0; const branch = treeCache.getBranch(branchId);
branch.isExpanded = isExpanded;
await server.put('branches/' + branchId + '/expanded/' + expandedNum); await server.put(`branches/${branchId}/expanded/${isExpanded ? 1 : 0}`);
} }
async reloadTreeFromCache() { async reloadTreeFromCache() {
@ -994,7 +995,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
return false; return false;
} }
}; };
for (const action of actions) { for (const action of actions) {
for (const shortcut of action.effectiveShortcuts) { for (const shortcut of action.effectiveShortcuts) {
hotKeyMap[utils.normalizeShortcut(shortcut)] = node => { hotKeyMap[utils.normalizeShortcut(shortcut)] = node => {
@ -1019,83 +1020,83 @@ export default class NoteTreeWidget extends TabAwareWidget {
async deleteNotesCommand({node}) { async deleteNotesCommand({node}) {
const branchIds = this.getSelectedOrActiveBranchIds(node); const branchIds = this.getSelectedOrActiveBranchIds(node);
await branchService.deleteNotes(branchIds); await branchService.deleteNotes(branchIds);
this.clearSelectedNodes(); this.clearSelectedNodes();
} }
moveNoteUpCommand({node}) { moveNoteUpCommand({node}) {
const beforeNode = node.getPrevSibling(); const beforeNode = node.getPrevSibling();
if (beforeNode !== null) { if (beforeNode !== null) {
branchService.moveBeforeBranch([node.data.branchId], beforeNode.data.branchId); branchService.moveBeforeBranch([node.data.branchId], beforeNode.data.branchId);
} }
} }
moveNoteDownCommand({node}) { moveNoteDownCommand({node}) {
const afterNode = node.getNextSibling(); const afterNode = node.getNextSibling();
if (afterNode !== null) { if (afterNode !== null) {
branchService.moveAfterBranch([node.data.branchId], afterNode.data.branchId); branchService.moveAfterBranch([node.data.branchId], afterNode.data.branchId);
} }
} }
moveNoteUpInHierarchyCommand({node}) { moveNoteUpInHierarchyCommand({node}) {
branchService.moveNodeUpInHierarchy(node); branchService.moveNodeUpInHierarchy(node);
} }
moveNoteDownInHierarchyCommand({node}) { moveNoteDownInHierarchyCommand({node}) {
const toNode = node.getPrevSibling(); const toNode = node.getPrevSibling();
if (toNode !== null) { if (toNode !== null) {
branchService.moveToParentNote([node.data.branchId], toNode.data.noteId); branchService.moveToParentNote([node.data.branchId], toNode.data.noteId);
} }
} }
addNoteAboveToSelectionCommand() { addNoteAboveToSelectionCommand() {
const node = this.getFocusedNode(); const node = this.getFocusedNode();
if (!node) { if (!node) {
return; return;
} }
if (node.isActive()) { if (node.isActive()) {
node.setSelected(true); node.setSelected(true);
} }
const prevSibling = node.getPrevSibling(); const prevSibling = node.getPrevSibling();
if (prevSibling) { if (prevSibling) {
prevSibling.setActive(true, {noEvents: true}); prevSibling.setActive(true, {noEvents: true});
if (prevSibling.isSelected()) { if (prevSibling.isSelected()) {
node.setSelected(false); node.setSelected(false);
} }
prevSibling.setSelected(true); prevSibling.setSelected(true);
} }
} }
addNoteBelowToSelectionCommand() { addNoteBelowToSelectionCommand() {
const node = this.getFocusedNode(); const node = this.getFocusedNode();
if (!node) { if (!node) {
return; return;
} }
if (node.isActive()) { if (node.isActive()) {
node.setSelected(true); node.setSelected(true);
} }
const nextSibling = node.getNextSibling(); const nextSibling = node.getNextSibling();
if (nextSibling) { if (nextSibling) {
nextSibling.setActive(true, {noEvents: true}); nextSibling.setActive(true, {noEvents: true});
if (nextSibling.isSelected()) { if (nextSibling.isSelected()) {
node.setSelected(false); node.setSelected(false);
} }
nextSibling.setSelected(true); nextSibling.setSelected(true);
} }
} }
@ -1179,4 +1180,4 @@ export default class NoteTreeWidget extends TabAwareWidget {
noteCreateService.duplicateNote(node.data.noteId, branch.parentNoteId); noteCreateService.duplicateNote(node.data.noteId, branch.parentNoteId);
} }
} }