Fixes #355
parent
4ba11ac66c
commit
804d87436c
|
@ -166,7 +166,6 @@ export const Attribute: MarkdownConfig = {
|
|||
return -1;
|
||||
}
|
||||
const [fullMatch, attributeName, attributeColon] = match;
|
||||
const attributeValueStart = pos + fullMatch.length;
|
||||
let bracketNestingDepth = 1;
|
||||
let valueLength = fullMatch.length;
|
||||
loopLabel:
|
||||
|
|
|
@ -32,15 +32,19 @@ export class HttpSpacePrimitives implements SpacePrimitives {
|
|||
"Got a redirect via the API so will redirect to URL",
|
||||
result.url,
|
||||
);
|
||||
alert("You are not authenticated, redirecting to login page...");
|
||||
location.href = result.url;
|
||||
throw new Error("Not authenticated");
|
||||
}
|
||||
return result;
|
||||
} catch (e: any) {
|
||||
// Firefox: NetworkError when attempting to fetch resource (with SW and without)
|
||||
// Safari: FetchEvent.respondWith received an error: TypeError: Load failed (service worker)
|
||||
// Safari: Load failed (no service worker)
|
||||
// Chrome: Failed to fetch (with service worker and without)
|
||||
// Errors when there is no internet connection:
|
||||
//
|
||||
// * Firefox: NetworkError when attempting to fetch resource (with SW and without)
|
||||
// * Safari (service worker enabled): FetchEvent.respondWith received an error: TypeError: Load failed
|
||||
// * Safari (no service worker): Load failed
|
||||
// * Chrome: Failed to fetch
|
||||
//
|
||||
// Common substrings: "fetch" "load failed"
|
||||
const errorMessage = e.message.toLowerCase();
|
||||
if (
|
||||
|
|
|
@ -31,6 +31,10 @@ functions:
|
|||
command:
|
||||
name: "Editor: Center Cursor"
|
||||
key: "Ctrl-Alt-l"
|
||||
moveToPos:
|
||||
path: "./editor.ts:moveToPosCommand"
|
||||
command:
|
||||
name: "Editor: Move Cursor to Position"
|
||||
clearPageIndex:
|
||||
path: "./page.ts:clearPageIndex"
|
||||
events:
|
||||
|
|
|
@ -42,3 +42,12 @@ export async function centerCursorCommand() {
|
|||
const pos = await editor.getCursor();
|
||||
await editor.moveCursor(pos, true);
|
||||
}
|
||||
|
||||
export async function moveToPosCommand() {
|
||||
const posString = await editor.prompt("Move to position:");
|
||||
if (!posString) {
|
||||
return;
|
||||
}
|
||||
const pos = +posString;
|
||||
await editor.moveCursor(pos);
|
||||
}
|
||||
|
|
|
@ -13,14 +13,7 @@ import {
|
|||
|
||||
import { events } from "$sb/plugos-syscall/mod.ts";
|
||||
|
||||
import {
|
||||
addParentPointers,
|
||||
findNodeOfType,
|
||||
ParseTree,
|
||||
renderToText,
|
||||
replaceNodesMatching,
|
||||
traverseTree,
|
||||
} from "$sb/lib/tree.ts";
|
||||
import { findNodeOfType, traverseTree } from "$sb/lib/tree.ts";
|
||||
import { applyQuery } from "$sb/lib/query.ts";
|
||||
import { extractFrontmatter } from "$sb/lib/frontmatter.ts";
|
||||
import { invokeFunction } from "$sb/silverbullet-syscall/system.ts";
|
||||
|
@ -37,6 +30,7 @@ export type BacklinkEntry = {
|
|||
name: string;
|
||||
alias?: string;
|
||||
inDirective?: boolean;
|
||||
asTemplate?: boolean;
|
||||
};
|
||||
export async function indexLinks({ name, tree }: IndexTreeEvent) {
|
||||
const backLinks: { key: string; value: BacklinkEntry }[] = [];
|
||||
|
@ -65,6 +59,29 @@ export async function indexLinks({ name, tree }: IndexTreeEvent) {
|
|||
traverseTree(tree, (n): boolean => {
|
||||
if (n.type === "DirectiveStart") {
|
||||
directiveDepth++;
|
||||
const pageRef = findNodeOfType(n, "PageRef")!;
|
||||
if (pageRef) {
|
||||
const pageRefName = pageRef.children![0].text!.slice(2, -2);
|
||||
backLinks.push({
|
||||
key: `${backlinkPrefix}${pageRefName}:${pageRef.from! + 2}`,
|
||||
value: { name, asTemplate: true },
|
||||
});
|
||||
}
|
||||
const directiveText = n.children![0].text;
|
||||
// #use or #import
|
||||
if (directiveText) {
|
||||
const match = /\[\[(.+)\]\]/.exec(directiveText);
|
||||
if (match) {
|
||||
const pageRefName = match[1];
|
||||
backLinks.push({
|
||||
key: `${backlinkPrefix}${pageRefName}:${
|
||||
n.from! + match.index! + 2
|
||||
}`,
|
||||
value: { name, asTemplate: true },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
if (n.type === "DirectiveStop") {
|
||||
|
@ -94,7 +111,7 @@ export async function indexLinks({ name, tree }: IndexTreeEvent) {
|
|||
}
|
||||
return false;
|
||||
});
|
||||
// console.log("Found", backLinks.length, "wiki link(s)");
|
||||
// console.log("Found", backLinks.length, "page link(s)");
|
||||
await index.batchSet(name, backLinks);
|
||||
}
|
||||
|
||||
|
@ -118,6 +135,9 @@ export async function linkQueryProvider({
|
|||
if (!blEntry.inDirective) {
|
||||
blEntry.inDirective = false;
|
||||
}
|
||||
if (!blEntry.asTemplate) {
|
||||
blEntry.asTemplate = false;
|
||||
}
|
||||
links.push({ ...blEntry, pos });
|
||||
}
|
||||
return applyQuery(query, links);
|
||||
|
@ -247,29 +267,14 @@ export async function renamePage(cmdDef: any) {
|
|||
// Page likely does not exist, but at least we can skip it
|
||||
continue;
|
||||
}
|
||||
const mdTree = await markdown.parseMarkdown(text);
|
||||
addParentPointers(mdTree);
|
||||
// The links in the page are going to be relative pointers to the old name
|
||||
replaceNodesMatching(mdTree, (n): ParseTree | undefined | null => {
|
||||
if (n.type === "WikiLinkPage") {
|
||||
const pageName = n.children![0].text!;
|
||||
if (pageName === oldName) {
|
||||
n.children![0].text = newName;
|
||||
updatedReferences++;
|
||||
return n;
|
||||
}
|
||||
// page name with @pos position
|
||||
if (pageName.startsWith(`${oldName}@`)) {
|
||||
const [, pos] = pageName.split("@");
|
||||
n.children![0].text = `${newName}@${pos}`;
|
||||
updatedReferences++;
|
||||
return n;
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
const newText = text.replaceAll(`[[${oldName}]]`, () => {
|
||||
updatedReferences++;
|
||||
return `[[${newName}]]`;
|
||||
}).replaceAll(`[[${oldName}@`, () => {
|
||||
updatedReferences++;
|
||||
return `[[${newName}@`;
|
||||
});
|
||||
// let newText = text.replaceAll(`[[${oldName}]]`, `[[${newName}]]`);
|
||||
const newText = renderToText(mdTree);
|
||||
if (text !== newText) {
|
||||
console.log("Changes made, saving...");
|
||||
await space.writePage(pageToUpdate, newText);
|
||||
|
|
|
@ -428,8 +428,7 @@ export class Client {
|
|||
);
|
||||
}
|
||||
|
||||
progressTimeout?: number;
|
||||
|
||||
private progressTimeout?: number;
|
||||
showProgress(progressPerc: number) {
|
||||
this.ui.viewDispatch({
|
||||
type: "set-progress",
|
||||
|
@ -714,7 +713,7 @@ export class Client {
|
|||
}
|
||||
|
||||
async loadCustomStyles() {
|
||||
if (this.settings?.customStyles) {
|
||||
if (this.settings.customStyles) {
|
||||
try {
|
||||
const { text: stylesText } = await this.space.readPage(
|
||||
this.settings?.customStyles,
|
||||
|
|
|
@ -43,7 +43,7 @@ self.addEventListener("install", (event: any) => {
|
|||
});
|
||||
|
||||
self.addEventListener("activate", (event: any) => {
|
||||
console.log("[Service worker]", "Activating new service worker!!!");
|
||||
console.log("[Service worker]", "Activating new service worker!");
|
||||
event.waitUntil(
|
||||
(async () => {
|
||||
const cacheNames = await caches.keys();
|
||||
|
|
Loading…
Reference in New Issue