Fixes #126
This commit is contained in:
parent
e89522b2fc
commit
da1458e02a
@ -70,7 +70,7 @@ if (navigator.serviceWorker) {
|
|||||||
.register(new URL("/service_worker.js", location.href), {
|
.register(new URL("/service_worker.js", location.href), {
|
||||||
type: "module",
|
type: "module",
|
||||||
})
|
})
|
||||||
.then((r) => {
|
.then(() => {
|
||||||
console.log("Service worker registered...");
|
console.log("Service worker registered...");
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
@ -106,6 +106,8 @@ import customMarkdownStyle from "./style.ts";
|
|||||||
import { CollabState } from "./cm_plugins/collab.ts";
|
import { CollabState } from "./cm_plugins/collab.ts";
|
||||||
import { collabSyscalls } from "./syscalls/collab.ts";
|
import { collabSyscalls } from "./syscalls/collab.ts";
|
||||||
|
|
||||||
|
const frontMatterRegex = /^---\s*$(.*?)---\s*$/ms;
|
||||||
|
|
||||||
class PageState {
|
class PageState {
|
||||||
constructor(
|
constructor(
|
||||||
readonly scrollTop: number,
|
readonly scrollTop: number,
|
||||||
@ -295,8 +297,18 @@ export class Editor {
|
|||||||
scrollIntoView: true,
|
scrollIntoView: true,
|
||||||
});
|
});
|
||||||
} else if (!stateRestored) {
|
} 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({
|
this.editorView.dispatch({
|
||||||
selection: { anchor: 0 },
|
selection: { anchor: initialCursorPos },
|
||||||
scrollIntoView: true,
|
scrollIntoView: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -692,10 +704,15 @@ export class Editor {
|
|||||||
meta: doc.meta,
|
meta: doc.meta,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Note: these events are dispatched asynchronously deliberately (not waiting for results)
|
||||||
if (loadingDifferentPage) {
|
if (loadingDifferentPage) {
|
||||||
await this.eventHook.dispatchEvent("editor:pageLoaded", pageName);
|
this.eventHook.dispatchEvent("editor:pageLoaded", pageName).catch(
|
||||||
|
console.error,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
await this.eventHook.dispatchEvent("editor:pageReloaded", pageName);
|
this.eventHook.dispatchEvent("editor:pageReloaded", pageName).catch(
|
||||||
|
console.error,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return stateRestored;
|
return stateRestored;
|
||||||
@ -709,20 +726,6 @@ export class Editor {
|
|||||||
"contenteditable",
|
"contenteditable",
|
||||||
readOnly || this.viewState.forcedROMode ? "false" : "true",
|
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 {
|
private restoreState(pageName: string): boolean {
|
||||||
|
@ -16,11 +16,6 @@
|
|||||||
outline: none !important;
|
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
|
// Indentation of follow-up lines
|
||||||
@mixin lineOverflow($baseIndent, $bulletIndent: 0) {
|
@mixin lineOverflow($baseIndent, $bulletIndent: 0) {
|
||||||
text-indent: -1 * ($baseIndent + 2ch);
|
text-indent: -1 * ($baseIndent + 2ch);
|
||||||
|
Loading…
Reference in New Issue
Block a user