poc: Add indentMultiplier configuration for customizable indentation in editor (#1212)
parent
ccf86a648b
commit
c27c83bc44
|
@ -67,6 +67,9 @@ config:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
type: string
|
type: string
|
||||||
|
indentMultiplier:
|
||||||
|
type: number
|
||||||
|
nullable: true
|
||||||
functions:
|
functions:
|
||||||
setEditorMode:
|
setEditorMode:
|
||||||
path: "./editor.ts:setEditorMode"
|
path: "./editor.ts:setEditorMode"
|
||||||
|
|
|
@ -51,6 +51,7 @@ export type Config = {
|
||||||
emoji?: EmojiConfig;
|
emoji?: EmojiConfig;
|
||||||
autoCloseBrackets: string;
|
autoCloseBrackets: string;
|
||||||
smartQuotes?: SmartQuotesConfig;
|
smartQuotes?: SmartQuotesConfig;
|
||||||
|
indentMultiplier?: number;
|
||||||
|
|
||||||
schema: SchemaConfig;
|
schema: SchemaConfig;
|
||||||
|
|
||||||
|
@ -73,6 +74,7 @@ export const defaultConfig: Config = {
|
||||||
defaultLinkStyle: "wikilink", // wikilink [[]] or markdown []()
|
defaultLinkStyle: "wikilink", // wikilink [[]] or markdown []()
|
||||||
actionButtons: [], // Actually defaults to defaultActionButtons
|
actionButtons: [], // Actually defaults to defaultActionButtons
|
||||||
autoCloseBrackets: "([{`",
|
autoCloseBrackets: "([{`",
|
||||||
|
indentMultiplier: 1,
|
||||||
|
|
||||||
schema: {
|
schema: {
|
||||||
config: {
|
config: {
|
||||||
|
|
|
@ -4,7 +4,7 @@ import type {
|
||||||
} from "@codemirror/autocomplete";
|
} from "@codemirror/autocomplete";
|
||||||
import type { Compartment, EditorState } from "@codemirror/state";
|
import type { Compartment, EditorState } from "@codemirror/state";
|
||||||
import { EditorView } from "@codemirror/view";
|
import { EditorView } from "@codemirror/view";
|
||||||
import { syntaxTree } from "@codemirror/language";
|
import { indentUnit, syntaxTree } from "@codemirror/language";
|
||||||
import { compile as gitIgnoreCompiler } from "gitignore-parser";
|
import { compile as gitIgnoreCompiler } from "gitignore-parser";
|
||||||
import type { SyntaxNode } from "@lezer/common";
|
import type { SyntaxNode } from "@lezer/common";
|
||||||
import { Space } from "../common/space.ts";
|
import { Space } from "../common/space.ts";
|
||||||
|
@ -119,6 +119,7 @@ export class Client implements ConfigContainer {
|
||||||
// CodeMirror editor
|
// CodeMirror editor
|
||||||
editorView!: EditorView;
|
editorView!: EditorView;
|
||||||
keyHandlerCompartment?: Compartment;
|
keyHandlerCompartment?: Compartment;
|
||||||
|
indentUnitCompartment?: Compartment;
|
||||||
|
|
||||||
private pageNavigator!: PathPageNavigator;
|
private pageNavigator!: PathPageNavigator;
|
||||||
|
|
||||||
|
@ -1173,6 +1174,17 @@ export class Client implements ConfigContainer {
|
||||||
console.error,
|
console.error,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const indentMultiplier = this.config.indentMultiplier ?? 1;
|
||||||
|
this.editorView.dispatch({
|
||||||
|
effects: this.indentUnitCompartment?.reconfigure(
|
||||||
|
indentUnit.of(" ".repeat(indentMultiplier)),
|
||||||
|
), // Change the indentation unit to 2 spaces
|
||||||
|
});
|
||||||
|
document.documentElement.style.setProperty(
|
||||||
|
"--editor-indent-multiplier",
|
||||||
|
indentMultiplier.toString(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
tweakEditorDOM(contentDOM: HTMLElement) {
|
tweakEditorDOM(contentDOM: HTMLElement) {
|
||||||
|
|
|
@ -16,6 +16,7 @@ import {
|
||||||
import {
|
import {
|
||||||
codeFolding,
|
codeFolding,
|
||||||
indentOnInput,
|
indentOnInput,
|
||||||
|
indentUnit,
|
||||||
LanguageDescription,
|
LanguageDescription,
|
||||||
LanguageSupport,
|
LanguageSupport,
|
||||||
syntaxHighlighting,
|
syntaxHighlighting,
|
||||||
|
@ -67,6 +68,11 @@ export function createEditorState(
|
||||||
createKeyBindings(client),
|
createKeyBindings(client),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
client.indentUnitCompartment = new Compartment();
|
||||||
|
const indentUnits = client.indentUnitCompartment.of(
|
||||||
|
indentUnit.of(" "),
|
||||||
|
);
|
||||||
|
|
||||||
return EditorState.create({
|
return EditorState.create({
|
||||||
doc: text,
|
doc: text,
|
||||||
extensions: [
|
extensions: [
|
||||||
|
@ -135,6 +141,7 @@ export function createEditorState(
|
||||||
codeFolding({
|
codeFolding({
|
||||||
placeholderText: "…",
|
placeholderText: "…",
|
||||||
}),
|
}),
|
||||||
|
indentUnits,
|
||||||
indentOnInput(),
|
indentOnInput(),
|
||||||
...cleanModePlugins(client),
|
...cleanModePlugins(client),
|
||||||
EditorView.lineWrapping,
|
EditorView.lineWrapping,
|
||||||
|
|
|
@ -91,25 +91,39 @@
|
||||||
|
|
||||||
// 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: calc(
|
||||||
padding-left: $baseIndent + 2ch;
|
-1 * (#{$baseIndent}ch * var(--editor-indent-multiplier) + 2ch)
|
||||||
|
);
|
||||||
|
padding-left: calc(
|
||||||
|
#{$baseIndent}ch * var(--editor-indent-multiplier) + 2ch
|
||||||
|
);
|
||||||
|
|
||||||
&.sb-line-task {
|
&.sb-line-task {
|
||||||
text-indent: -1 * ($baseIndent + 5ch);
|
text-indent: calc(
|
||||||
padding-left: $baseIndent + 5ch;
|
-1 * (#{$baseIndent}ch * var(--editor-indent-multiplier) + 5ch)
|
||||||
|
);
|
||||||
|
padding-left: calc(
|
||||||
|
#{$baseIndent}ch * var(--editor-indent-multiplier) + 5ch
|
||||||
|
);
|
||||||
|
|
||||||
.cm-list-bullet::after {
|
.cm-list-bullet::after {
|
||||||
left: ($baseIndent + 5ch);
|
left: calc(#{$baseIndent}ch * var(--editor-indent-multiplier) + 5ch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&.sb-line-blockquote {
|
&.sb-line-blockquote {
|
||||||
text-indent: -1 * ($baseIndent + 4ch);
|
text-indent: calc(
|
||||||
padding-left: $baseIndent + 4ch;
|
-1 * (#{$baseIndent}ch * var(--editor-indent-multiplier) + 4ch)
|
||||||
|
);
|
||||||
|
padding-left: calc(
|
||||||
|
#{$baseIndent}ch * var(--editor-indent-multiplier) + 4ch
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
.cm-list-bullet::after {
|
.cm-list-bullet::after {
|
||||||
left: ($baseIndent + $bulletIndent + 2ch);
|
left: calc(
|
||||||
|
#{$baseIndent}ch * var(--editor-indent-multiplier) + #{$bulletIndent}ch + 2ch
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ html {
|
||||||
--meta-subtle-color: #959595;
|
--meta-subtle-color: #959595;
|
||||||
--subtle-color: #676767;
|
--subtle-color: #676767;
|
||||||
--subtle-background-color: rgba(72, 72, 72, 0.1);
|
--subtle-background-color: rgba(72, 72, 72, 0.1);
|
||||||
|
--editor-indent-multiplier: 1;
|
||||||
|
|
||||||
--root-background-color: #fff;
|
--root-background-color: #fff;
|
||||||
--root-color: inherit;
|
--root-color: inherit;
|
||||||
|
@ -124,10 +125,9 @@ html {
|
||||||
--editor-directive-color: #696969;
|
--editor-directive-color: #696969;
|
||||||
--editor-directive-background-color: #ebebeb7d;
|
--editor-directive-background-color: #ebebeb7d;
|
||||||
|
|
||||||
--ui-font:
|
--ui-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
|
||||||
-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
|
"Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji",
|
||||||
Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji",
|
"Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
|
||||||
"Segoe UI Symbol", "Noto Color Emoji";
|
|
||||||
--editor-font: "iA-Mono", "Menlo";
|
--editor-font: "iA-Mono", "Menlo";
|
||||||
--editor-width: 800px;
|
--editor-width: 800px;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue