1
0

More or less functional

This commit is contained in:
Zef Hemel 2022-06-14 09:45:22 +02:00
parent c25a53357d
commit 5dbe71568e
4 changed files with 70 additions and 51 deletions

View File

@ -154,7 +154,9 @@ export const insertNewlineContinueMarkup: StateCommand = ({
{ doc } = state;
let dont = null,
changes = state.changeByRange((range) => {
if (!range.empty || !markdownLanguage.isActiveAt(state, range.from))
if (!range.empty)
// TODO: Hack due to languagefacet stuff not working
// || !markdownLanguage.isActiveAt(state, range.from))
return (dont = { range });
let pos = range.from,
line = doc.lineAt(pos);

View File

@ -90,25 +90,25 @@ export default function buildMarkdown(mdExtensions: MDExt[]): Language {
Comment,
Table,
...mdExtensions.map(mdExtensionSyntaxConfig),
parseCode({
codeParser: getCodeParser([
LanguageDescription.of({
name: "yaml",
alias: ["meta", "data"],
support: new LanguageSupport(StreamLanguage.define(yaml)),
}),
LanguageDescription.of({
name: "javascript",
alias: ["js"],
support: new LanguageSupport(javascriptLanguage),
}),
LanguageDescription.of({
name: "typescript",
alias: ["ts"],
support: new LanguageSupport(typescriptLanguage),
}),
]),
}),
// parseCode({
// codeParser: getCodeParser([
// LanguageDescription.of({
// name: "yaml",
// alias: ["meta", "data"],
// support: new LanguageSupport(StreamLanguage.define(yaml)),
// }),
// LanguageDescription.of({
// name: "javascript",
// alias: ["js"],
// support: new LanguageSupport(javascriptLanguage),
// }),
// LanguageDescription.of({
// name: "typescript",
// alias: ["ts"],
// support: new LanguageSupport(typescriptLanguage),
// }),
// ]),
// }),
{
props: [
styleTags({

View File

@ -55,10 +55,12 @@ safeRun(async () => {
});
// if (!isDesktop) {
// if (localStorage.getItem("disable_sw") !== "true") {
if (localStorage.getItem("disable_sw") !== "true") {
if (navigator.serviceWorker) {
navigator.serviceWorker
.register(new URL("service_worker.ts", import.meta.url), { type: "module" })
.register(new URL("service_worker.ts", import.meta.url), {
type: "module",
})
.then((r) => {
console.log("Service worker registered...");
});
@ -67,6 +69,6 @@ if (navigator.serviceWorker) {
"No launching service worker (not present, maybe because not running on localhost or over SSL)"
);
}
// }
}
// }

View File

@ -6,13 +6,9 @@ import {
import { closeBrackets, closeBracketsKeymap } from "@codemirror/autocomplete";
import { indentWithTab, standardKeymap } from "@codemirror/commands";
import { history, historyKeymap } from "@codemirror/commands";
import {
bracketMatching,
defaultHighlightStyle,
syntaxHighlighting,
} from "@codemirror/language";
import { bracketMatching, syntaxHighlighting } from "@codemirror/language";
import { searchKeymap } from "@codemirror/search";
import { EditorSelection, EditorState } from "@codemirror/state";
import { Compartment, EditorSelection, EditorState } from "@codemirror/state";
import {
drawSelection,
dropCursor,
@ -75,6 +71,31 @@ class PageState {
const saveInterval = 1000;
// Monkey patching the languageDataAt, somehow the languageData facet is not set
// properly, no idea why
// TODO: Remove at some point
EditorState.prototype.languageDataAt = function (
name: string,
pos: number,
side = -1
) {
let values = [];
// console.log("Getting language data");
// @ts-ignore
for (let provider of this.facet(EditorState.languageData)) {
let providerResult = provider(this, pos, side);
if (!providerResult) {
// console.log("Empty provider result");
continue;
}
for (let result of providerResult) {
if (Object.prototype.hasOwnProperty.call(result, name))
values.push(result[name]);
}
}
return values;
};
export class Editor {
readonly commandHook: CommandHook;
readonly slashCommandHook: SlashCommandHook;
@ -315,14 +336,15 @@ export class Editor {
return EditorState.create({
doc: text,
extensions: [
markdown({
base: buildMarkdown(this.mdExtensions),
addKeymap: true,
}),
highlightSpecialChars(),
history(),
drawSelection(),
dropCursor(),
syntaxHighlighting(customMarkdownStyle(this.mdExtensions)),
// syntaxHighlighting(defaultHighlightStyle),
bracketMatching(),
closeBrackets(),
autocompletion({
override: [
this.completer.bind(this),
@ -365,14 +387,6 @@ export class Editor {
mac: "Cmd-i",
run: commands.insertMarker("_"),
},
// {
// key: "Ctrl-p",
// mac: "Cmd-p",
// run: (): boolean => {
// window.open(location.href, "_blank")!.focus();
// return true;
// },
// },
{
key: "Ctrl-k",
mac: "Cmd-k",
@ -439,9 +453,10 @@ export class Editor {
}
),
pasteLinkExtension,
markdown({
base: buildMarkdown(this.mdExtensions),
bracketMatching({
brackets: "()[]{}",
}),
closeBrackets(),
],
});
}