1
0
This commit is contained in:
Zef Hemel 2022-11-24 16:55:30 +01:00
parent e89522b2fc
commit da1458e02a
3 changed files with 21 additions and 23 deletions

View File

@ -70,7 +70,7 @@ if (navigator.serviceWorker) {
.register(new URL("/service_worker.js", location.href), {
type: "module",
})
.then((r) => {
.then(() => {
console.log("Service worker registered...");
});
} else {

View File

@ -106,6 +106,8 @@ import customMarkdownStyle from "./style.ts";
import { CollabState } from "./cm_plugins/collab.ts";
import { collabSyscalls } from "./syscalls/collab.ts";
const frontMatterRegex = /^---\s*$(.*?)---\s*$/ms;
class PageState {
constructor(
readonly scrollTop: number,
@ -295,8 +297,18 @@ export class Editor {
scrollIntoView: true,
});
} else if (!stateRestored) {
// Somewhat ad-hoc way to determine if the document contains frontmatter and if so, putting the cursor _after it_.
const pageText = this.editorView.state.sliceDoc();
// Default the cursor to be at position 0
let initialCursorPos = 0;
const match = frontMatterRegex.exec(pageText);
if (match) {
// Frotnmatter found, put cursor after it
initialCursorPos = match[0].length;
}
this.editorView.dispatch({
selection: { anchor: 0 },
selection: { anchor: initialCursorPos },
scrollIntoView: true,
});
}
@ -692,10 +704,15 @@ export class Editor {
meta: doc.meta,
});
// Note: these events are dispatched asynchronously deliberately (not waiting for results)
if (loadingDifferentPage) {
await this.eventHook.dispatchEvent("editor:pageLoaded", pageName);
this.eventHook.dispatchEvent("editor:pageLoaded", pageName).catch(
console.error,
);
} else {
await this.eventHook.dispatchEvent("editor:pageReloaded", pageName);
this.eventHook.dispatchEvent("editor:pageReloaded", pageName).catch(
console.error,
);
}
return stateRestored;
@ -709,20 +726,6 @@ export class Editor {
"contenteditable",
readOnly || this.viewState.forcedROMode ? "false" : "true",
);
if (isMobileSafari() && readOnly) {
console.log("Safari read only hack");
contentDOM.classList.add("ios-safari-readonly");
} else {
contentDOM.classList.remove("ios-safari-readonly");
}
function isMobileSafari() {
return (
navigator.userAgent.match(/(iPod|iPhone|iPad)/) &&
navigator.userAgent.match(/AppleWebKit/)
);
}
}
private restoreState(pageName: string): boolean {

View File

@ -16,11 +16,6 @@
outline: none !important;
}
// Weird hack to readjust iOS's safari font-size when contenteditable is disabled
.ios-safari-readonly {
font-size: 60%;
}
// Indentation of follow-up lines
@mixin lineOverflow($baseIndent, $bulletIndent: 0) {
text-indent: -1 * ($baseIndent + 2ch);