diff --git a/src/public/javascripts/desktop.js b/src/public/javascripts/desktop.js index a9895230e..79140ec13 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.js index 152428458..d53b7709c 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.js index 11af52d2a..ba5d0fdeb 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 title document.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.js index 8d964e384..f939d1e06 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 reloads this.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) }); }