From 61f30373d436ceb1e1fccacd85b907e556234748 Mon Sep 17 00:00:00 2001 From: zadam Date: Tue, 24 Nov 2020 23:24:05 +0100 Subject: [PATCH] hoisting improvements --- src/public/app/entities/note_short.js | 5 +++++ src/public/app/services/link.js | 4 ++-- src/public/app/services/tab_manager.js | 18 ++++++++++++++++++ src/public/app/services/tree_context_menu.js | 2 +- src/public/app/widgets/note_tree.js | 4 ++-- src/public/app/widgets/owned_attribute_list.js | 4 ++-- src/public/app/widgets/tab_row.js | 15 +++++++++++++++ .../app/widgets/type_widgets/relation_map.js | 2 +- src/services/attributes.js | 1 + 9 files changed, 47 insertions(+), 8 deletions(-) diff --git a/src/public/app/entities/note_short.js b/src/public/app/entities/note_short.js index 8f6b2260d..0751a31f4 100644 --- a/src/public/app/entities/note_short.js +++ b/src/public/app/entities/note_short.js @@ -546,6 +546,11 @@ class NoteShort { const labels = this.getLabels('cssClass'); return labels.map(l => l.value).join(' '); } + + getHoistedCssClass() { + const labels = this.getLabels('hoistedCssClass'); + return labels.map(l => l.value).join(' '); + } } export default NoteShort; diff --git a/src/public/app/services/link.js b/src/public/app/services/link.js index 5f678fb69..9d1d3bbf9 100644 --- a/src/public/app/services/link.js +++ b/src/public/app/services/link.js @@ -78,7 +78,7 @@ function goToLink(e) { if (notePath) { if ((e.which === 1 && e.ctrlKey) || e.which === 2) { - appContext.tabManager.openTabWithNote(notePath); + appContext.tabManager.openTabWithNoteWithHoisting(notePath); } else if (e.which === 1) { const activeTabContext = appContext.tabManager.getActiveTabContext(); @@ -127,7 +127,7 @@ function linkContextMenu(e) { ], selectMenuItemHandler: ({command}) => { if (command === 'openNoteInNewTab') { - appContext.tabManager.openTabWithNote(notePath); + appContext.tabManager.openTabWithNoteWithHoisting(notePath); } else if (command === 'openNoteInNewWindow') { appContext.triggerCommand('openInWindow', {notePath}); diff --git a/src/public/app/services/tab_manager.js b/src/public/app/services/tab_manager.js index db0bfa2c3..44af32da1 100644 --- a/src/public/app/services/tab_manager.js +++ b/src/public/app/services/tab_manager.js @@ -193,6 +193,24 @@ export default class TabManager extends Component { return tabContext; } + /** + * If the requested notePath is within current note hoisting scope then keep the note hoisting also for the new tab. + */ + async openTabWithNoteWithHoisting(notePath) { + const tabContext = this.getActiveTabContext(); + let hoistedNoteId = 'root'; + + if (tabContext) { + const resolvedNotePath = await treeService.resolveNotePath(notePath); + + if (resolvedNotePath.includes(tabContext.hoistedNoteId)) { + hoistedNoteId = tabContext.hoistedNoteId; + } + } + + return this.openTabWithNote(notePath, false, null, hoistedNoteId); + } + async openTabWithNote(notePath, activate, tabId, hoistedNoteId) { const tabContext = await this.openEmptyTab(tabId, hoistedNoteId); diff --git a/src/public/app/services/tree_context_menu.js b/src/public/app/services/tree_context_menu.js index becf30b1b..16c2939e4 100644 --- a/src/public/app/services/tree_context_menu.js +++ b/src/public/app/services/tree_context_menu.js @@ -109,7 +109,7 @@ class TreeContextMenu { const notePath = treeService.getNotePath(this.node); if (command === 'openInTab') { - appContext.tabManager.openTabWithNote(notePath); + appContext.tabManager.openTabWithNoteWithHoisting(notePath); } else if (command === "insertNoteAfter") { const parentNoteId = this.node.data.parentNoteId; diff --git a/src/public/app/widgets/note_tree.js b/src/public/app/widgets/note_tree.js index a37df0ebe..bd23d4422 100644 --- a/src/public/app/widgets/note_tree.js +++ b/src/public/app/widgets/note_tree.js @@ -181,7 +181,7 @@ export default class NoteTreeWidget extends TabAwareWidget { const notePath = treeService.getNotePath(node); if (notePath) { - appContext.tabManager.openTabWithNote(notePath); + appContext.tabManager.openTabWithNoteWithHoisting(notePath); } e.stopPropagation(); @@ -311,7 +311,7 @@ export default class NoteTreeWidget extends TabAwareWidget { } else if (event.ctrlKey) { const notePath = treeService.getNotePath(node); - appContext.tabManager.openTabWithNote(notePath); + appContext.tabManager.openTabWithNoteWithHoisting(notePath); } else if (data.node.isActive()) { // this is important for single column mobile view, otherwise it's not possible to see again previously displayed note diff --git a/src/public/app/widgets/owned_attribute_list.js b/src/public/app/widgets/owned_attribute_list.js index c2b1fab92..e0c31f136 100644 --- a/src/public/app/widgets/owned_attribute_list.js +++ b/src/public/app/widgets/owned_attribute_list.js @@ -32,9 +32,9 @@ export default class OwnedAttributeListWidget extends TabAwareWidget { } renderTitle(note) { - const ownedNotes = note.getAttributes().filter(attr => attr.noteId === this.noteId) + const ownedAttrs = note.getAttributes().filter(attr => attr.noteId === this.noteId && !attr.isAutoLink) - this.$title.text(`Owned attrs (${ownedNotes.length})`); + this.$title.text(`Owned attrs (${ownedAttrs.length})`); return { show: true, diff --git a/src/public/app/widgets/tab_row.js b/src/public/app/widgets/tab_row.js index 50f55f1a4..5cfa2aa22 100644 --- a/src/public/app/widgets/tab_row.js +++ b/src/public/app/widgets/tab_row.js @@ -10,6 +10,7 @@ import contextMenu from "../services/context_menu.js"; import utils from "../services/utils.js"; import keyboardActionService from "../services/keyboard_actions.js"; import appContext from "../services/app_context.js"; +import treeCache from "../services/tree_cache.js"; !function(i, e){"function"==typeof define&&define.amd?define("jquery-bridget/jquery-bridget",["jquery"],function(t){return e(i,t)}):"object"==typeof module&&module.exports?module.exports=e(i,utils.dynamicRequire("jquery")):i.jQueryBridget=e(i,i.jQuery)}(window,function(t, i){"use strict";var c=Array.prototype.slice,e=t.console,p=void 0===e?function(){}:function(t){e.error(t)};function n(d, o, u){(u=u||i||t.jQuery)&&(o.prototype.option||(o.prototype.option=function(t){u.isPlainObject(t)&&(this.options=u.extend(!0,this.options,t))}),u.fn[d]=function(t){if("string"==typeof t){var i=c.call(arguments,1);return s=i,a="$()."+d+'("'+(r=t)+'")',(e=this).each(function(t, i){var e=u.data(i,d);if(e){var n=e[r];if(n&&"_"!=r.charAt(0)){var o=n.apply(e,s);h=void 0===h?o:h}else p(a+" is not a valid method")}else p(d+" not initialized. Cannot call methods, i.e. "+a)}),void 0!==h?h:e}var e,r,s,h,a,n;return n=t,this.each(function(t, i){var e=u.data(i,d);e?(e.option(n),e._init()):(e=new o(i,n),u.data(i,d,e))}),this},r(u))}function r(t){!t||t&&t.bridget||(t.bridget=n)}return r(i||t.jQuery),n}),function(t, i){"use strict";"function"==typeof define&&define.amd?define("get-size/get-size",[],function(){return i()}):"object"==typeof module&&module.exports?module.exports=i():t.getSize=i()}(window,function(){"use strict";function m(t){var i=parseFloat(t);return-1==t.indexOf("%")&&!isNaN(i)&&i}var e="undefined"==typeof console?function(){}:function(t){console.error(t)},y=["paddingLeft","paddingRight","paddingTop","paddingBottom","marginLeft","marginRight","marginTop","marginBottom","borderLeftWidth","borderRightWidth","borderTopWidth","borderBottomWidth"],b=y.length;function E(t){var i=getComputedStyle(t);return i||e("Style returned "+i+". Are you running this code in a hidden iframe on Firefox? See http://bit.ly/getsizebug1"),i}var _,x=!1;function P(t){if(function(){if(!x){x=!0;var t=document.createElement("div");t.style.width="200px",t.style.padding="1px 2px 3px 4px",t.style.borderStyle="solid",t.style.borderWidth="1px 2px 3px 4px",t.style.boxSizing="border-box";var i=document.body||document.documentElement;i.appendChild(t);var e=E(t);P.isBoxSizeOuter=_=200==m(e.width),i.removeChild(t)}}(),"string"==typeof t&&(t=document.querySelector(t)),t&&"object"==typeof t&&t.nodeType){var i=E(t);if("none"==i.display)return function(){for(var t={width:0,height:0,innerWidth:0,innerHeight:0,outerWidth:0,outerHeight:0},i=0; i