Fixed a bunch of bugs around page navigation and renaming
This commit is contained in:
@@ -12,15 +12,17 @@ export function PageNavigator({
|
||||
}) {
|
||||
let options: FilterOption[] = [];
|
||||
for (let pageMeta of allPages) {
|
||||
if (currentPage && currentPage === pageMeta.name) {
|
||||
continue;
|
||||
}
|
||||
// Order by last modified date in descending order
|
||||
let orderId = -pageMeta.lastModified;
|
||||
// Unless it was opened in this session
|
||||
if (pageMeta.lastOpened) {
|
||||
orderId = -pageMeta.lastOpened;
|
||||
}
|
||||
// Or it's the currently open page
|
||||
if (currentPage && currentPage === pageMeta.name) {
|
||||
// ... then we put it all the way to the end
|
||||
orderId = Infinity;
|
||||
}
|
||||
options.push({
|
||||
...pageMeta,
|
||||
orderId: orderId,
|
||||
|
||||
@@ -557,8 +557,8 @@ export class Editor {
|
||||
this.editorView!.focus();
|
||||
}
|
||||
|
||||
async navigate(name: string, pos?: number) {
|
||||
await this.pageNavigator.navigate(name, pos);
|
||||
async navigate(name: string, pos?: number, replaceState = false) {
|
||||
await this.pageNavigator.navigate(name, pos, replaceState);
|
||||
}
|
||||
|
||||
async loadPage(pageName: string) {
|
||||
|
||||
@@ -13,12 +13,20 @@ export class PathPageNavigator {
|
||||
|
||||
constructor(readonly root: string = "") {}
|
||||
|
||||
async navigate(page: string, pos?: number) {
|
||||
window.history.pushState(
|
||||
{ page, pos },
|
||||
page,
|
||||
`${this.root}/${encodePageUrl(page)}`
|
||||
);
|
||||
async navigate(page: string, pos?: number, replaceState = false) {
|
||||
if (replaceState) {
|
||||
window.history.replaceState(
|
||||
{ page, pos },
|
||||
page,
|
||||
`${this.root}/${encodePageUrl(page)}`
|
||||
);
|
||||
} else {
|
||||
window.history.pushState(
|
||||
{ page, pos },
|
||||
page,
|
||||
`${this.root}/${encodePageUrl(page)}`
|
||||
);
|
||||
}
|
||||
window.dispatchEvent(
|
||||
new PopStateEvent("popstate", {
|
||||
state: { page, pos },
|
||||
|
||||
@@ -43,6 +43,14 @@ export default function reducer(
|
||||
showPageNavigator: false,
|
||||
};
|
||||
case "pages-listed":
|
||||
// Let's move over any "lastOpened" times to the "allPages" list
|
||||
let oldPageMeta = new Map([...state.allPages].map((pm) => [pm.name, pm]));
|
||||
for (let pageMeta of action.pages) {
|
||||
let oldPageMetaItem = oldPageMeta.get(pageMeta.name);
|
||||
if (oldPageMetaItem && oldPageMetaItem.lastOpened) {
|
||||
pageMeta.lastOpened = oldPageMetaItem.lastOpened;
|
||||
}
|
||||
}
|
||||
return {
|
||||
...state,
|
||||
allPages: action.pages,
|
||||
|
||||
@@ -43,8 +43,13 @@ export function editorSyscalls(editor: Editor): SysCallMapping {
|
||||
"editor.save": async () => {
|
||||
return editor.save(true);
|
||||
},
|
||||
"editor.navigate": async (ctx, name: string, pos: number) => {
|
||||
await editor.navigate(name, pos);
|
||||
"editor.navigate": async (
|
||||
ctx,
|
||||
name: string,
|
||||
pos: number,
|
||||
replaceState = false
|
||||
) => {
|
||||
await editor.navigate(name, pos, replaceState);
|
||||
},
|
||||
"editor.reloadPage": async (ctx) => {
|
||||
await editor.reloadPage();
|
||||
|
||||
Reference in New Issue
Block a user