mirror of
https://github.com/zadam/trilium.git
synced 2024-09-21 16:16:04 +08:00
better back/forward navigation
This commit is contained in:
parent
5f4d963580
commit
493d088d80
|
@ -180,6 +180,10 @@ if (utils.isElectron()) {
|
|||
});
|
||||
}
|
||||
|
||||
if (items.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
contextMenu.show({
|
||||
x: params.x,
|
||||
y: params.y,
|
||||
|
|
|
@ -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}) {
|
||||
|
|
|
@ -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[]} */
|
||||
|
|
|
@ -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)
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue