From 58fa0832f6d214483f223e6f82b3fbe349c8ec45 Mon Sep 17 00:00:00 2001 From: zadam Date: Thu, 4 Jun 2020 21:44:34 +0200 Subject: [PATCH] fix focusing title after creating a note --- src/public/app/services/main_tree_executors.js | 4 ++-- src/public/app/services/tab_context.js | 4 ++-- src/public/app/services/tab_manager.js | 2 +- src/public/app/widgets/note_tree.js | 14 ++++++++------ 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/public/app/services/main_tree_executors.js b/src/public/app/services/main_tree_executors.js index a365393f3..9a8306fad 100644 --- a/src/public/app/services/main_tree_executors.js +++ b/src/public/app/services/main_tree_executors.js @@ -34,7 +34,7 @@ export default class MainTreeExecutors extends Component { return; } - const {note} = await noteCreateService.createNote(activeNote.noteId, { + await noteCreateService.createNote(activeNote.noteId, { isProtected: activeNote.isProtected, saveSelection: false }); @@ -56,4 +56,4 @@ export default class MainTreeExecutors extends Component { saveSelection: false }); } -} \ No newline at end of file +} diff --git a/src/public/app/services/tab_context.js b/src/public/app/services/tab_context.js index 9d46e2f6d..920a186f3 100644 --- a/src/public/app/services/tab_context.js +++ b/src/public/app/services/tab_context.js @@ -73,7 +73,7 @@ class TabContext extends Component { protectedSessionHolder.touchProtectedSessionIfNecessary(this.note); if (triggerSwitchEvent) { - this.triggerEvent('tabNoteSwitched', { + await this.triggerEvent('tabNoteSwitched', { tabContext: this, notePath: this.notePath }); @@ -127,4 +127,4 @@ class TabContext extends Component { } } -export default TabContext; \ No newline at end of file +export default TabContext; diff --git a/src/public/app/services/tab_manager.js b/src/public/app/services/tab_manager.js index 40f29f8c9..0c169cba7 100644 --- a/src/public/app/services/tab_manager.js +++ b/src/public/app/services/tab_manager.js @@ -203,7 +203,7 @@ export default class TabManager extends Component { if (activate) { this.activateTab(tabContext.tabId, false); - this.triggerEvent('tabNoteSwitchedAndActivated', { + await this.triggerEvent('tabNoteSwitchedAndActivated', { tabContext, notePath: tabContext.notePath // resolved note path }); diff --git a/src/public/app/widgets/note_tree.js b/src/public/app/widgets/note_tree.js index 12eb68b09..a4006fe19 100644 --- a/src/public/app/widgets/note_tree.js +++ b/src/public/app/widgets/note_tree.js @@ -854,8 +854,11 @@ export default class NoteTreeWidget extends TabAwareWidget { this.toggleInt(this.isEnabled()); const oldActiveNode = this.getActiveNode(); + let oldActiveNodeFocused = false; if (oldActiveNode) { + oldActiveNodeFocused = oldActiveNode.hasFocus(); + oldActiveNode.setActive(false); oldActiveNode.setFocus(false); } @@ -868,8 +871,7 @@ export default class NoteTreeWidget extends TabAwareWidget { await this.expandToNote(this.tabContext.notePath); } - newActiveNode.setActive(true, {noEvents: true}); - + newActiveNode.setActive(true, {noEvents: true, noFocus: !oldActiveNodeFocused}); newActiveNode.makeVisible({scrollIntoView: true}); } } @@ -898,7 +900,7 @@ export default class NoteTreeWidget extends TabAwareWidget { async entitiesReloadedEvent({loadResults}) { const activeNode = this.getActiveNode(); - const activeNodeFocused = activeNode ? activeNode.hasFocus() : false; + const activeNodeFocused = activeNode && activeNode.hasFocus(); const nextNode = activeNode ? (activeNode.getNextSibling() || activeNode.getPrevSibling() || activeNode.getParent()) : null; const activeNotePath = activeNode ? treeService.getNotePath(activeNode) : null; const nextNotePath = nextNode ? treeService.getNotePath(nextNode) : null; @@ -1021,7 +1023,7 @@ export default class NoteTreeWidget extends TabAwareWidget { } if (node) { - node.setActive(true, {noEvents: true}); + node.setActive(true, {noEvents: true, noFocus: true}); } else { // this is used when original note has been deleted and we want to move the focus to the note above/below @@ -1036,7 +1038,7 @@ export default class NoteTreeWidget extends TabAwareWidget { // return focus if the previously active node was also focused if (newActiveNode && activeNodeFocused) { - newActiveNode.setFocus(true); + await newActiveNode.setFocus(true); } } } @@ -1064,7 +1066,7 @@ export default class NoteTreeWidget extends TabAwareWidget { if (activeNotePath) { const node = await this.getNodeFromPath(activeNotePath, true); - await node.setActive(true, {noEvents: true}); + await node.setActive(true, {noEvents: true, noFocus: true}); } }