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
better back/forward navigation
zadam493d088d80e7
diff --git a/src/public/javascripts/desktop.js b/src/public/javascripts/desktop.jsindex a9895230e8..79140ec135 100644--- a/src/public/javascripts/desktop.js+++ b/src/public/javascripts/desktop.js@@ -180,6 +180,10 @@ if (utils.isElectron()) {});}+ if (items.length === 0) {+ return;+ }+contextMenu.show({x: params.x,y: params.y,diff --git a/src/public/javascripts/services/entrypoints.js b/src/public/javascripts/services/entrypoints.jsindex 152428458e..d53b7709c7 100644--- a/src/public/javascripts/services/entrypoints.js+++ b/src/public/javascripts/services/entrypoints.js@@ -138,17 +138,11 @@ export default class Entrypoints extends Component {}backInNoteHistoryCommand() {- const electron = require('electron');- const {webContents} = electron.remote.getCurrentWindow();-- webContents.goBack();+ window.history.back();}- forwardInNoteHistoryCommand() {console.log("forward");- const electron = require('electron');- const {webContents} = electron.remote.getCurrentWindow();-- webContents.goForward();+ forwardInNoteHistoryCommand() {+ window.history.forward();}async searchForResultsCommand({searchText}) {diff --git a/src/public/javascripts/services/tab_manager.js b/src/public/javascripts/services/tab_manager.jsindex 11af52d2a6..ba5d0fdeb9 100644--- a/src/public/javascripts/services/tab_manager.js+++ b/src/public/javascripts/services/tab_manager.js@@ -104,8 +104,8 @@ export default class TabManager extends Component {setCurrentNotePathToHash() {const activeTabContext = this.getActiveTabContext();- if (activeTabContext- && activeTabContext.notePath !== treeService.getHashValueFromAddress()) {+ if (window.history.length === 0 // first history entry+ || (activeTabContext && activeTabContext.notePath !== treeService.getHashValueFromAddress()[0])) {const url = '#' + (activeTabContext.notePath || "") + "-" + activeTabContext.tabId;// using pushState instead of directly modifying document.location because it does not trigger hashchange@@ -117,9 +117,9 @@ export default class TabManager extends Component {// it helps navigating in history if note title is included in the titledocument.title += " - " + activeTabContext.note.title;}-- this.triggerEvent('activeNoteChanged');}++ this.triggerEvent('activeNoteChanged'); // trigger this even in on popstate event}/** @return {TabContext[]} */diff --git a/src/public/javascripts/widgets/history_navigation.js b/src/public/javascripts/widgets/history_navigation.jsindex 8d964e3841..f939d1e06a 100644--- a/src/public/javascripts/widgets/history_navigation.js+++ b/src/public/javascripts/widgets/history_navigation.js@@ -24,8 +24,7 @@ export default class HistoryNavigationWidget extends BasicWidget {if (utils.isElectron()) {this.$widget = $(TPL);- this.$backInHistory = this.$widget.find("[data-trigger-command='backInNoteHistory']");- this.$backInHistory.on('contextmenu', e => {+ const contextMenuHandler = e => {e.preventDefault();if (this.webContents.history.length < 2) {@@ -33,13 +32,18 @@ export default class HistoryNavigationWidget extends BasicWidget {}this.showContextMenu(e);- });+ };+ this.$backInHistory = this.$widget.find("[data-trigger-command='backInNoteHistory']");+ this.$backInHistory.on('contextmenu', contextMenuHandler);this.$forwardInHistory = this.$widget.find("[data-trigger-command='forwardInNoteHistory']");+ this.$forwardInHistory.on('contextmenu', contextMenuHandler);const electron = require('electron');this.webContents = electron.remote.getCurrentWindow().webContents;++ // without this the history is preserved across frontend reloadsthis.webContents.clearHistory();this.refresh();@@ -54,7 +58,8 @@ export default class HistoryNavigationWidget extends BasicWidget {async showContextMenu(e) {let items = [];- for (const url of this.webContents.history) {+ for (const idx in this.webContents.history) {+ const url = this.webContents.history[idx];const [_, notePathWithTab] = url.split('#');const [notePath, tabId] = notePathWithTab.split('-');@@ -62,25 +67,22 @@ export default class HistoryNavigationWidget extends BasicWidget {items.push({title,- notePath,- tabId,+ idx,uiIcon: "empty"});}items.reverse();- items = items.slice(1); // remove the current note-if (items.length > 20) {- items = items.slice(0, 20);+ items = items.slice(0, 50);}contextMenu.show({x: e.pageX,y: e.pageY,items,- selectMenuItemHandler: ({notePath, tabId}) => appContext.tabManager.switchToTab(tabId, notePath)+ selectMenuItemHandler: ({idx}) => this.webContents.goToIndex(idx)});}