From ec652e61d1f6ff3fa48a77bd4f24495e7b3d7638 Mon Sep 17 00:00:00 2001 From: Timo Date: Fri, 10 Jan 2025 12:28:20 +0100 Subject: [PATCH] No Auto Indentation for `mercury` and `mercury-web` languages (#327) --- packages/web/src/components/editor.tsx | 13 +++++++++++++ packages/web/src/settings.json | 1 + 2 files changed, 14 insertions(+) diff --git a/packages/web/src/components/editor.tsx b/packages/web/src/components/editor.tsx index 425221b..f0fafbf 100644 --- a/packages/web/src/components/editor.tsx +++ b/packages/web/src/components/editor.tsx @@ -16,6 +16,7 @@ import { langByTarget as langByTargetUntyped, panicCodes as panicCodesUntyped, targetsWithDocumentEvalMode, + noAutoIndent, webTargets, } from "@/settings.json"; import { javascript } from "@codemirror/lang-javascript"; @@ -39,6 +40,7 @@ import React, { useEffect, useState } from "react"; import { yCollab } from "y-codemirror.next"; import { UndoManager } from "yjs"; import themes from "@/lib/themes"; +import { insertNewline } from "@codemirror/commands"; const defaultLanguage = "javascript"; const langByTarget = langByTargetUntyped as { [lang: string]: string }; @@ -68,6 +70,16 @@ const panicKeymap = ( : []; }; +// overwrites the default insertNewlineAndIndent command on Enter +const autoIndentKeymap = (doc: Document) => { + // if any of the targets is part of the noAutoIndent setting in settings.json + const noIndent = noAutoIndent.includes(doc.target); + // overwrite the Enter with insertNewline + return noIndent + ? Prec.high(keymap.of([{ key: "Enter", run: insertNewline }])) + : []; +}; + interface FlokSetupOptions { readOnly?: boolean; } @@ -88,6 +100,7 @@ const flokSetup = ( remoteEvalFlash(doc), Prec.high(evalKeymap(doc, { defaultMode, web })), panicKeymap(doc), + autoIndentKeymap(doc), yCollab(text, doc.session.awareness, { undoManager, hideCaret: readOnly, diff --git a/packages/web/src/settings.json b/packages/web/src/settings.json index 1ce4428..def74b6 100644 --- a/packages/web/src/settings.json +++ b/packages/web/src/settings.json @@ -45,6 +45,7 @@ "sardine": "panic()", "dummy": "silence" }, + "noAutoIndent": ["mercury", "mercury-web"], "webTargets": ["hydra", "mercury-web", "punctual", "strudel"], "repoUrl": "https://github.com/munshkr/flok", "changeLogUrl": "https://github.com/munshkr/flok/blob/main/CHANGELOG.md#changelog"