Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
"move to new window" respects note hoisting of original tab
zadambed7bdfd00ad
diff --git a/src/public/app/services/entrypoints.js b/src/public/app/services/entrypoints.jsindex 4633bc300b..aef68b4302 100644--- a/src/public/app/services/entrypoints.js+++ b/src/public/app/services/entrypoints.js@@ -184,11 +184,15 @@ export default class Entrypoints extends Component {createTopLevelNoteCommand() { noteCreateService.createNewTopLevelNote(); }- async openInWindowCommand({notePath}) {+ async openInWindowCommand({notePath, hoistedNoteId}) {+ if (!hoistedNoteId) {+ hoistedNoteId = 'root';+ }+if (utils.isElectron()) {const {ipcRenderer} = utils.dynamicRequire('electron');- ipcRenderer.send('create-extra-window', {notePath});+ ipcRenderer.send('create-extra-window', {notePath, hoistedNoteId});}else {const url = window.location.protocol + '//' + window.location.host + window.location.pathname + '?extra=1#' + notePath;@@ -198,7 +202,7 @@ export default class Entrypoints extends Component {}async openNewWindowCommand() {- this.openInWindowCommand({notePath: ''});+ this.openInWindowCommand({notePath: '', hoistedNoteId: 'root'});}async runActiveNoteCommand() {diff --git a/src/public/app/services/hoisted_note.js b/src/public/app/services/hoisted_note.jsindex 953e8ae31d..fffd5d4abb 100644--- a/src/public/app/services/hoisted_note.js+++ b/src/public/app/services/hoisted_note.js@@ -39,7 +39,7 @@ async function checkNoteAccess(notePath, tabContext) {if (hoistedNoteId !== 'root' && !resolvedNotePath.includes(hoistedNoteId)) {const confirmDialog = await import('../dialogs/confirm.js');-console.trace("HI!", hoistedNoteId, notePath);+if (!await confirmDialog.confirm("Requested note is outside of hoisted note subtree and you must unhoist to access the note. Do you want to proceed with unhoisting?")) {return false;}diff --git a/src/public/app/services/link.js b/src/public/app/services/link.jsindex 7f8a2f1acf..ceaf73ab23 100644--- a/src/public/app/services/link.js+++ b/src/public/app/services/link.js@@ -130,7 +130,7 @@ function linkContextMenu(e) {appContext.tabManager.openTabWithNoteWithHoisting(notePath);}else if (command === 'openNoteInNewWindow') {- appContext.triggerCommand('openInWindow', {notePath});+ appContext.triggerCommand('openInWindow', {notePath, hoistedNoteId: 'root'});}}});diff --git a/src/public/app/services/tab_context.js b/src/public/app/services/tab_context.jsindex fd3b81bdcf..80d4eaed3f 100644--- a/src/public/app/services/tab_context.js+++ b/src/public/app/services/tab_context.js@@ -145,6 +145,10 @@ class TabContext extends Component {}async setHoistedNoteId(noteIdToHoist) {+ if (this.notePathArray && !this.notePathArray.includes(noteIdToHoist)) {+ await this.setNote(noteIdToHoist);+ }+this.hoistedNoteId = noteIdToHoist;await this.triggerEvent('hoistedNoteChanged', {diff --git a/src/public/app/services/tab_manager.js b/src/public/app/services/tab_manager.jsindex 44af32da19..b1782dc5f4 100644--- a/src/public/app/services/tab_manager.js+++ b/src/public/app/services/tab_manager.js@@ -58,7 +58,8 @@ export default class TabManager extends Component {else {tabsToOpen.push({notePath: notePath,- active: true+ active: true,+ hoistedNoteId: glob.extraHoistedNoteId || 'root'});}}@@ -83,7 +84,8 @@ export default class TabManager extends Component {if (filteredTabs.length === 0) {filteredTabs.push({notePath: this.isMainWindow ? 'root' : '',- active: true+ active: true,+ extraHoistedNoteId: glob.extraHoistedNoteId || 'root'});}@@ -91,6 +93,8 @@ export default class TabManager extends Component {filteredTabs[0].active = true;}+ console.log("filteredTabs", filteredTabs);+await this.tabsUpdate.allowUpdateWithoutChange(async () => {for (const tab of filteredTabs) {await this.openTabWithNote(tab.notePath, tab.active, tab.tabId, tab.hoistedNoteId);@@ -348,11 +352,11 @@ export default class TabManager extends Component {}moveTabToNewWindowCommand({tabId}) {- const notePath = this.getTabContextById(tabId).notePath;+ const {notePath, hoistedNoteId} = this.getTabContextById(tabId);this.removeTab(tabId);- this.triggerCommand('openInWindow', {notePath});+ this.triggerCommand('openInWindow', {notePath, hoistedNoteId});}hoistedNoteChangedEvent() {diff --git a/src/public/app/widgets/tab_row.js b/src/public/app/widgets/tab_row.jsindex 1991125a4a..2382e3bdc1 100644--- a/src/public/app/widgets/tab_row.js+++ b/src/public/app/widgets/tab_row.js@@ -680,4 +680,14 @@ export default class TabRowWidget extends BasicWidget {this.updateTab($tab, tabContext.note);}}++ hoistedNoteChangedEvent({tabId}) {+ const $tab = this.getTabById(tabId);++ if ($tab) {+ const tabContext = appContext.tabManager.getTabContextById(tabId);++ this.updateTab($tab, tabContext.note);+ }+ }}diff --git a/src/routes/index.js b/src/routes/index.jsindex ec0485f6bc..1f47b305e9 100644--- a/src/routes/index.js+++ b/src/routes/index.js@@ -27,7 +27,8 @@ function index(req, res) {instanceName: config.General ? config.General.instanceName : null,appCssNoteIds: getAppCssNoteIds(),isDev: env.isDev(),- isMainWindow: !req.query.extra+ isMainWindow: !req.query.extra,+ extraHoistedNoteId: req.query.extraHoistedNoteId});}diff --git a/src/services/window.js b/src/services/window.jsindex d2670eec36..b4fc797bc0 100644--- a/src/services/window.js+++ b/src/services/window.js@@ -15,7 +15,7 @@ let mainWindow;/** @type {Electron.BrowserWindow} */let setupWindow;-async function createExtraWindow(notePath) {+async function createExtraWindow(notePath, hoistedNoteId = 'root') {const {BrowserWindow} = require('electron');const win = new BrowserWindow({width: 1000,@@ -31,11 +31,11 @@ async function createExtraWindow(notePath) {});win.setMenuBarVisibility(false);- win.loadURL('http://127.0.0.1:' + await port + '/?extra=1#' + notePath);+ win.loadURL('http://127.0.0.1:' + await port + '/?extra=1&extraHoistedNoteId=' + hoistedNoteId + '#' + notePath);}ipcMain.on('create-extra-window', (event, arg) => {- createExtraWindow(arg.notePath);+ createExtraWindow(arg.notePath, arg.hoistedNoteId);});async function createMainWindow() {diff --git a/src/views/desktop.ejs b/src/views/desktop.ejsindex 631c9ff2a8..9b99a76cd9 100644--- a/src/views/desktop.ejs+++ b/src/views/desktop.ejs@@ -51,7 +51,8 @@csrfToken: '<%= csrfToken %>',isDev: <%= isDev %>,appCssNoteIds: <%- JSON.stringify(appCssNoteIds) %>,- isMainWindow: <%= isMainWindow %>+ isMainWindow: <%= isMainWindow %>,+ extraHoistedNoteId: '<%= extraHoistedNoteId %>',};</script>