1
0

Maintain modal focus

This commit is contained in:
Zef Hemel 2023-07-29 12:19:35 +02:00
parent 9a113c7105
commit 7442aac7e0
2 changed files with 7 additions and 6 deletions

View File

@ -130,7 +130,7 @@ export class Client {
parent: document.getElementById("sb-editor")!,
});
this.openPages = new OpenPages(this.editorView);
this.openPages = new OpenPages(this);
this.focus();

View File

@ -1,3 +1,4 @@
import { Client } from "./client.ts";
import { EditorSelection, EditorView } from "./deps.ts";
class PageState {
@ -10,11 +11,11 @@ class PageState {
export class OpenPages {
openPages = new Map<string, PageState>();
constructor(private editorView: EditorView) {}
constructor(private client: Client) {}
restoreState(pageName: string): boolean {
const pageState = this.openPages.get(pageName);
const editorView = this.editorView;
const editorView = this.client.editorView;
if (pageState) {
// Restore state
try {
@ -40,7 +41,7 @@ export class OpenPages {
scrollIntoView: true,
});
}
editorView.focus();
this.client.focus();
return !!pageState;
}
@ -48,8 +49,8 @@ export class OpenPages {
this.openPages.set(
currentPage,
new PageState(
this.editorView.scrollDOM.scrollTop,
this.editorView.state.selection,
this.client.editorView.scrollDOM.scrollTop,
this.client.editorView.state.selection,
),
);
}