Skip to content

Commit

Permalink
fix merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
tmhglnd committed Jan 10, 2025
2 parents 395e099 + ec652e6 commit 8471a89
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/web/src/components/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
langByTarget as langByTargetUntyped,
panicCodes as panicCodesUntyped,
targetsWithDocumentEvalMode,
noAutoIndent,
webTargets,
} from "@/settings.json";
import { javascript } from "@codemirror/lang-javascript";
Expand All @@ -39,7 +40,7 @@ import React, { useEffect, useState } from "react";
import { yCollab } from "y-codemirror.next";
import { UndoManager } from "yjs";
import themes from "@/lib/themes";
import { toggleLineComment } from "@codemirror/commands";
import { toggleLineComment, insertNewline } from "@codemirror/commands";

const defaultLanguage = "javascript";
const langByTarget = langByTargetUntyped as { [lang: string]: string };
Expand Down Expand Up @@ -69,6 +70,7 @@ const panicKeymap = (
: [];
};

// extra keymaps
const extraKeymap = () => {
return keymap.of([
// fixes the Cmd/Alt-/ issue for Spanish keyboards
Expand All @@ -79,6 +81,16 @@ const extraKeymap = () => {
]);
};

// 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;
}
Expand All @@ -100,6 +112,7 @@ const flokSetup = (
Prec.high(evalKeymap(doc, { defaultMode, web })),
panicKeymap(doc),
extraKeymap(),
autoIndentKeymap(doc),
yCollab(text, doc.session.awareness, {
undoManager,
hideCaret: readOnly,
Expand Down
1 change: 1 addition & 0 deletions packages/web/src/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 8471a89

Please sign in to comment.