mirror of
https://github.com/kou029w/quot.git
synced 2025-01-31 22:38:07 +00:00
Compare commits
No commits in common. "c9d33c28d62690d1bd47dcd3a2c1b88380ac2be6" and "85b02bf020d7d78be206fde17408d024cc0b0c52" have entirely different histories.
c9d33c28d6
...
85b02bf020
4 changed files with 19 additions and 90 deletions
|
@ -1,79 +0,0 @@
|
||||||
import { indentWithTab } from "@codemirror/commands";
|
|
||||||
import { indentService, indentUnit, syntaxTree } from "@codemirror/language";
|
|
||||||
import {
|
|
||||||
type DecorationSet,
|
|
||||||
type EditorView,
|
|
||||||
type ViewUpdate,
|
|
||||||
Decoration,
|
|
||||||
ViewPlugin,
|
|
||||||
WidgetType,
|
|
||||||
keymap,
|
|
||||||
} from "@codemirror/view";
|
|
||||||
|
|
||||||
class IndentWidget extends WidgetType {
|
|
||||||
constructor(readonly bullet: boolean) {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
toDOM() {
|
|
||||||
const indent = document.createElement("span");
|
|
||||||
indent.textContent = this.bullet ? "•" : " ";
|
|
||||||
indent.style.paddingInline = "0.5em";
|
|
||||||
return indent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function indentDecorations(view: EditorView) {
|
|
||||||
const decorations: Array<{
|
|
||||||
from: number;
|
|
||||||
to: number;
|
|
||||||
value: Decoration;
|
|
||||||
}> = [];
|
|
||||||
for (const { from, to } of view.visibleRanges) {
|
|
||||||
syntaxTree(view.state).iterate({
|
|
||||||
from,
|
|
||||||
to,
|
|
||||||
enter(node) {
|
|
||||||
if (node.name === "Indent") {
|
|
||||||
const next = view.state.doc.sliceString(node.to, node.to + 1);
|
|
||||||
const decoration = Decoration.widget({
|
|
||||||
widget: new IndentWidget(/^[^ \t]?$/.test(next)),
|
|
||||||
});
|
|
||||||
decorations.push(decoration.range(node.from));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return Decoration.set(decorations);
|
|
||||||
}
|
|
||||||
|
|
||||||
const indentDecorationsPlugin = ViewPlugin.fromClass(
|
|
||||||
class {
|
|
||||||
decorations: DecorationSet;
|
|
||||||
constructor(view: EditorView) {
|
|
||||||
this.decorations = indentDecorations(view);
|
|
||||||
}
|
|
||||||
update(update: ViewUpdate) {
|
|
||||||
if (update.docChanged || update.viewportChanged) {
|
|
||||||
this.decorations = indentDecorations(update.view);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
decorations(v) {
|
|
||||||
return v.decorations;
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
const indentPlugins = [
|
|
||||||
keymap.of([indentWithTab]),
|
|
||||||
indentUnit.of(" "),
|
|
||||||
indentService.of((context, pos) => {
|
|
||||||
const previousLine = context.lineAt(pos, -1).text;
|
|
||||||
if (previousLine.trim() === "") return null;
|
|
||||||
return /^[ \t]*/.exec(previousLine)?.[0]?.length ?? null;
|
|
||||||
}),
|
|
||||||
indentDecorationsPlugin,
|
|
||||||
];
|
|
||||||
|
|
||||||
export default indentPlugins;
|
|
|
@ -11,6 +11,7 @@ export const quotLanguage = LRLanguage.define({
|
||||||
props: [
|
props: [
|
||||||
styleTags({
|
styleTags({
|
||||||
Heading: t.heading,
|
Heading: t.heading,
|
||||||
|
Indent: t.separator,
|
||||||
AutoLink: t.link,
|
AutoLink: t.link,
|
||||||
Code: t.monospace,
|
Code: t.monospace,
|
||||||
}),
|
}),
|
||||||
|
@ -26,15 +27,21 @@ export const quotHighlighting = syntaxHighlighting(
|
||||||
fontSize: "1.25em",
|
fontSize: "1.25em",
|
||||||
marginBlockEnd: "0.5em",
|
marginBlockEnd: "0.5em",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
tag: t.separator,
|
||||||
|
letterSpacing: "1.5em",
|
||||||
|
"&:last-child:after": {
|
||||||
|
content: `"•"`,
|
||||||
|
marginInline: "-0.9em",
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
tag: t.link,
|
tag: t.link,
|
||||||
class: "auto-link",
|
class: "auto-link",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
tag: t.monospace,
|
tag: t.monospace,
|
||||||
borderStyle: "solid",
|
background: "var(--nc-bg-3)",
|
||||||
borderColor: "var(--nc-bg-3)",
|
|
||||||
borderWidth: "1px",
|
|
||||||
borderRadius: "0.25em",
|
borderRadius: "0.25em",
|
||||||
padding: "0.2em 0.4em",
|
padding: "0.2em 0.4em",
|
||||||
fontSize: "0.9em",
|
fontSize: "0.9em",
|
||||||
|
|
|
@ -13,10 +13,6 @@
|
||||||
outline: unset;
|
outline: unset;
|
||||||
}
|
}
|
||||||
|
|
||||||
.editor .cm-editor.cm-focused .cm-selectionBackground {
|
|
||||||
background-color: var(--nc-ac-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
.editor .cm-content {
|
.editor .cm-content {
|
||||||
font-family: "sans-serif";
|
font-family: "sans-serif";
|
||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import { onCleanup, onMount } from "solid-js";
|
import { onCleanup, onMount } from "solid-js";
|
||||||
import { minimalSetup } from "codemirror";
|
import { minimalSetup } from "codemirror";
|
||||||
import { emacsStyleKeymap } from "@codemirror/commands";
|
import { emacsStyleKeymap, indentWithTab } from "@codemirror/commands";
|
||||||
|
import { indentService, indentUnit } from "@codemirror/language";
|
||||||
import { EditorView, keymap } from "@codemirror/view";
|
import { EditorView, keymap } from "@codemirror/view";
|
||||||
import type Pages from "../../protocol/pages";
|
import type Pages from "../../protocol/pages";
|
||||||
import "./editor.css";
|
import "./editor.css";
|
||||||
import { quotHighlighting, quotLanguage } from "../../syntax/quot";
|
import { quotHighlighting, quotLanguage } from "../../syntax/quot";
|
||||||
import indentPlugins from "../../syntax/indent-plugins";
|
|
||||||
|
|
||||||
export default (props: {
|
export default (props: {
|
||||||
id: number;
|
id: number;
|
||||||
|
@ -36,11 +36,16 @@ export default (props: {
|
||||||
props.onUpdatePage({ id: props.id, title, text });
|
props.onUpdatePage({ id: props.id, title, text });
|
||||||
}),
|
}),
|
||||||
EditorView.lineWrapping,
|
EditorView.lineWrapping,
|
||||||
keymap.of(emacsStyleKeymap.filter(({ key }) => key !== "Ctrl-v")),
|
indentUnit.of(" "),
|
||||||
|
indentService.of((context, pos) => {
|
||||||
|
const previousLine = context.lineAt(pos, -1).text;
|
||||||
|
if (previousLine.trim() === "") return null;
|
||||||
|
return /^[ \t]*/.exec(previousLine)?.[0]?.length ?? null;
|
||||||
|
}),
|
||||||
|
keymap.of([indentWithTab, ...emacsStyleKeymap]),
|
||||||
minimalSetup,
|
minimalSetup,
|
||||||
quotLanguage,
|
quotLanguage,
|
||||||
quotHighlighting,
|
quotHighlighting,
|
||||||
...indentPlugins,
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
ref.addEventListener("click", (e) => {
|
ref.addEventListener("click", (e) => {
|
||||||
|
|
Loading…
Add table
Reference in a new issue