Skip to content

Commit ee633a5

Browse files
authored
Add helpful placeholder text to CodeMirror elements (#1816)
1 parent 7b80d20 commit ee633a5

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

frontend/src/app/(navfooter)/new/NewScratchForm.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,18 +391,18 @@ export default function NewScratchForm({
391391
valueVersion={valueVersion}
392392
onChange={setAsm}
393393
extensions={basicSetup}
394+
placeholder="Place your GAS-compatible assembly code here."
394395
/>
395396
</div>
396397
<div className="flex h-[200px] flex-col">
397-
<FormLabel small="(any typedefs, structs, and declarations you would like to include go here; typically generated with m2ctx.py)">
398-
Context
399-
</FormLabel>
398+
<FormLabel small="(optional)">Context</FormLabel>
400399
<CodeMirror
401400
className="w-full flex-1 overflow-hidden rounded border border-[color:var(--g500)] bg-[color:var(--g200)] [&_.cm-editor]:h-full"
402401
value={context}
403402
valueVersion={valueVersion}
404403
onChange={setContext}
405404
extensions={[basicSetup, cpp()]}
405+
placeholder="Add any typedefs, structs, and declarations here."
406406
/>
407407
</div>
408408

frontend/src/components/Editor/CodeMirror.module.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
cursor: text;
1414
}
1515

16+
:global(.cm-placeholder) {
17+
font-style: italic;
18+
}
19+
1620
:global(.cm-gutters),
1721
:global(.cm-content),
1822
:global(.cm-tooltip-hover) {

frontend/src/components/Editor/CodeMirror.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from "react";
88

99
import { type Extension, EditorState } from "@codemirror/state";
10-
import { EditorView } from "@codemirror/view";
10+
import { EditorView, placeholder } from "@codemirror/view";
1111
import clsx from "clsx";
1212
import { useDebouncedCallback } from "use-debounce";
1313

@@ -49,6 +49,7 @@ export interface Props {
4949
className?: string;
5050
viewRef?: RefObject<EditorView | null>;
5151
extensions: Extension; // const
52+
placeholder?: string;
5253
}
5354

5455
export default function CodeMirror({
@@ -60,6 +61,7 @@ export default function CodeMirror({
6061
className,
6162
viewRef: viewRefProp,
6263
extensions,
64+
placeholder: placeholderText,
6365
}: Props) {
6466
const { ref: el, width } = useSize<HTMLDivElement>();
6567

@@ -96,6 +98,7 @@ export default function CodeMirror({
9698
state: EditorState.create({
9799
doc: valueRef.current,
98100
extensions: [
101+
placeholder(placeholderText || ""),
99102
EditorState.transactionExtender.of(
100103
({ docChanged, newDoc, newSelection }) => {
101104
// value / onChange

frontend/src/components/Scratch/Scratch.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ export default function Scratch({
298298
}}
299299
onSelectedLineChange={setSelectedSourceLine}
300300
extensions={cmExtensionsSource}
301+
placeholder="Write the code for the function you are matching here."
301302
/>
302303
</Tab>
303304
);
@@ -322,6 +323,7 @@ export default function Scratch({
322323
setScratch({ context: value });
323324
}}
324325
extensions={cmExtensionsContext}
326+
placeholder="Add your typedefs, structs, and declarations here."
325327
/>
326328
</Tab>
327329
);

0 commit comments

Comments
 (0)