More or less functional
This commit is contained in:
parent
c25a53357d
commit
5dbe71568e
@ -154,7 +154,9 @@ export const insertNewlineContinueMarkup: StateCommand = ({
|
|||||||
{ doc } = state;
|
{ doc } = state;
|
||||||
let dont = null,
|
let dont = null,
|
||||||
changes = state.changeByRange((range) => {
|
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 });
|
return (dont = { range });
|
||||||
let pos = range.from,
|
let pos = range.from,
|
||||||
line = doc.lineAt(pos);
|
line = doc.lineAt(pos);
|
||||||
|
@ -90,25 +90,25 @@ export default function buildMarkdown(mdExtensions: MDExt[]): Language {
|
|||||||
Comment,
|
Comment,
|
||||||
Table,
|
Table,
|
||||||
...mdExtensions.map(mdExtensionSyntaxConfig),
|
...mdExtensions.map(mdExtensionSyntaxConfig),
|
||||||
parseCode({
|
// parseCode({
|
||||||
codeParser: getCodeParser([
|
// codeParser: getCodeParser([
|
||||||
LanguageDescription.of({
|
// LanguageDescription.of({
|
||||||
name: "yaml",
|
// name: "yaml",
|
||||||
alias: ["meta", "data"],
|
// alias: ["meta", "data"],
|
||||||
support: new LanguageSupport(StreamLanguage.define(yaml)),
|
// support: new LanguageSupport(StreamLanguage.define(yaml)),
|
||||||
}),
|
// }),
|
||||||
LanguageDescription.of({
|
// LanguageDescription.of({
|
||||||
name: "javascript",
|
// name: "javascript",
|
||||||
alias: ["js"],
|
// alias: ["js"],
|
||||||
support: new LanguageSupport(javascriptLanguage),
|
// support: new LanguageSupport(javascriptLanguage),
|
||||||
}),
|
// }),
|
||||||
LanguageDescription.of({
|
// LanguageDescription.of({
|
||||||
name: "typescript",
|
// name: "typescript",
|
||||||
alias: ["ts"],
|
// alias: ["ts"],
|
||||||
support: new LanguageSupport(typescriptLanguage),
|
// support: new LanguageSupport(typescriptLanguage),
|
||||||
}),
|
// }),
|
||||||
]),
|
// ]),
|
||||||
}),
|
// }),
|
||||||
{
|
{
|
||||||
props: [
|
props: [
|
||||||
styleTags({
|
styleTags({
|
||||||
|
@ -55,18 +55,20 @@ safeRun(async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// if (!isDesktop) {
|
// if (!isDesktop) {
|
||||||
// if (localStorage.getItem("disable_sw") !== "true") {
|
if (localStorage.getItem("disable_sw") !== "true") {
|
||||||
if (navigator.serviceWorker) {
|
if (navigator.serviceWorker) {
|
||||||
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) => {
|
.then((r) => {
|
||||||
console.log("Service worker registered...");
|
console.log("Service worker registered...");
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.log(
|
console.log(
|
||||||
"No launching service worker (not present, maybe because not running on localhost or over SSL)"
|
"No launching service worker (not present, maybe because not running on localhost or over SSL)"
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// }
|
// }
|
||||||
|
@ -6,13 +6,9 @@ import {
|
|||||||
import { closeBrackets, closeBracketsKeymap } from "@codemirror/autocomplete";
|
import { closeBrackets, closeBracketsKeymap } from "@codemirror/autocomplete";
|
||||||
import { indentWithTab, standardKeymap } from "@codemirror/commands";
|
import { indentWithTab, standardKeymap } from "@codemirror/commands";
|
||||||
import { history, historyKeymap } from "@codemirror/commands";
|
import { history, historyKeymap } from "@codemirror/commands";
|
||||||
import {
|
import { bracketMatching, syntaxHighlighting } from "@codemirror/language";
|
||||||
bracketMatching,
|
|
||||||
defaultHighlightStyle,
|
|
||||||
syntaxHighlighting,
|
|
||||||
} from "@codemirror/language";
|
|
||||||
import { searchKeymap } from "@codemirror/search";
|
import { searchKeymap } from "@codemirror/search";
|
||||||
import { EditorSelection, EditorState } from "@codemirror/state";
|
import { Compartment, EditorSelection, EditorState } from "@codemirror/state";
|
||||||
import {
|
import {
|
||||||
drawSelection,
|
drawSelection,
|
||||||
dropCursor,
|
dropCursor,
|
||||||
@ -75,6 +71,31 @@ class PageState {
|
|||||||
|
|
||||||
const saveInterval = 1000;
|
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 {
|
export class Editor {
|
||||||
readonly commandHook: CommandHook;
|
readonly commandHook: CommandHook;
|
||||||
readonly slashCommandHook: SlashCommandHook;
|
readonly slashCommandHook: SlashCommandHook;
|
||||||
@ -315,14 +336,15 @@ export class Editor {
|
|||||||
return EditorState.create({
|
return EditorState.create({
|
||||||
doc: text,
|
doc: text,
|
||||||
extensions: [
|
extensions: [
|
||||||
|
markdown({
|
||||||
|
base: buildMarkdown(this.mdExtensions),
|
||||||
|
addKeymap: true,
|
||||||
|
}),
|
||||||
highlightSpecialChars(),
|
highlightSpecialChars(),
|
||||||
history(),
|
history(),
|
||||||
drawSelection(),
|
drawSelection(),
|
||||||
dropCursor(),
|
dropCursor(),
|
||||||
syntaxHighlighting(customMarkdownStyle(this.mdExtensions)),
|
syntaxHighlighting(customMarkdownStyle(this.mdExtensions)),
|
||||||
// syntaxHighlighting(defaultHighlightStyle),
|
|
||||||
bracketMatching(),
|
|
||||||
closeBrackets(),
|
|
||||||
autocompletion({
|
autocompletion({
|
||||||
override: [
|
override: [
|
||||||
this.completer.bind(this),
|
this.completer.bind(this),
|
||||||
@ -365,14 +387,6 @@ export class Editor {
|
|||||||
mac: "Cmd-i",
|
mac: "Cmd-i",
|
||||||
run: commands.insertMarker("_"),
|
run: commands.insertMarker("_"),
|
||||||
},
|
},
|
||||||
// {
|
|
||||||
// key: "Ctrl-p",
|
|
||||||
// mac: "Cmd-p",
|
|
||||||
// run: (): boolean => {
|
|
||||||
// window.open(location.href, "_blank")!.focus();
|
|
||||||
// return true;
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
{
|
{
|
||||||
key: "Ctrl-k",
|
key: "Ctrl-k",
|
||||||
mac: "Cmd-k",
|
mac: "Cmd-k",
|
||||||
@ -439,9 +453,10 @@ export class Editor {
|
|||||||
}
|
}
|
||||||
),
|
),
|
||||||
pasteLinkExtension,
|
pasteLinkExtension,
|
||||||
markdown({
|
bracketMatching({
|
||||||
base: buildMarkdown(this.mdExtensions),
|
brackets: "()[]{}",
|
||||||
}),
|
}),
|
||||||
|
closeBrackets(),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user