Skip to content

Commit 4e0c919

Browse files
authored
refactor: complete migration to React 19 (#740)
* refactor: complete migration to React 19 * wip * wip: remove `displayName`
1 parent 0a77456 commit 4e0c919

File tree

1 file changed

+54
-56
lines changed

1 file changed

+54
-56
lines changed
Lines changed: 54 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { forwardRef, useImperativeHandle, useMemo, useRef } from "react";
1+
import React, { useImperativeHandle, useMemo, useRef } from "react";
22
import CodeMirror from "@uiw/react-codemirror";
33
import { history } from "@codemirror/history";
44
import { bracketMatching } from "@codemirror/matchbrackets";
@@ -10,65 +10,63 @@ import {
1010
} from "../utils/codemirror-theme";
1111
import "../scss/editor.scss";
1212

13-
const CodeEditor = forwardRef(
14-
({ codeValue, onUpdate, eslintOptions, eslintInstance }, ref) => {
15-
const editorRef = useRef(null);
13+
export default function CodeEditor({
14+
codeValue,
15+
onUpdate,
16+
eslintOptions,
17+
eslintInstance,
18+
ref,
19+
}) {
20+
const editorRef = useRef(null);
1621

17-
const extensions = useMemo(
18-
() => [
19-
history(),
20-
bracketMatching(),
21-
linter(esLint(eslintInstance, eslintOptions), { delay: 0 }),
22-
javascript({ typescript: true }),
23-
ESLintPlaygroundTheme,
24-
ESLintPlaygroundHighlightStyle,
25-
],
26-
[eslintOptions, eslintInstance],
27-
);
22+
const extensions = useMemo(
23+
() => [
24+
history(),
25+
bracketMatching(),
26+
linter(esLint(eslintInstance, eslintOptions), { delay: 0 }),
27+
javascript({ typescript: true }),
28+
ESLintPlaygroundTheme,
29+
ESLintPlaygroundHighlightStyle,
30+
],
31+
[eslintOptions, eslintInstance],
32+
);
2833

29-
useImperativeHandle(ref, () => ({
30-
scrollToPosition(line, col) {
31-
const editorView = editorRef.current.view;
32-
const { state } = editorView;
33-
const pos = state.doc.line(line).from + col;
34+
useImperativeHandle(ref, () => ({
35+
scrollToPosition(line, col) {
36+
const editorView = editorRef.current.view;
37+
const { state } = editorView;
38+
const pos = state.doc.line(line).from + col;
3439

35-
// Set the cursor selection to the position
36-
editorView.dispatch({
37-
selection: { anchor: pos },
38-
scrollIntoView: true,
39-
});
40+
// Set the cursor selection to the position
41+
editorView.dispatch({
42+
selection: { anchor: pos },
43+
scrollIntoView: true,
44+
});
4045

41-
const linePos = editorView.coordsAtPos(
42-
state.doc.line(line).from,
43-
);
46+
const linePos = editorView.coordsAtPos(state.doc.line(line).from);
4447

45-
// Calculate to try to center the line in the editor
46-
if (linePos) {
47-
const editorRect = editorView.dom.getBoundingClientRect();
48-
const offset =
49-
linePos.top - editorRect.top - editorRect.height / 2;
50-
editorView.scrollDOM.scrollTop += offset;
51-
}
48+
// Calculate to try to center the line in the editor
49+
if (linePos) {
50+
const editorRect = editorView.dom.getBoundingClientRect();
51+
const offset =
52+
linePos.top - editorRect.top - editorRect.height / 2;
53+
editorView.scrollDOM.scrollTop += offset;
54+
}
5255

53-
editorView.focus();
54-
},
55-
}));
56+
editorView.focus();
57+
},
58+
}));
5659

57-
return (
58-
<CodeMirror
59-
value={codeValue}
60-
minWidth="100%"
61-
height="100%"
62-
ref={editorRef}
63-
extensions={extensions}
64-
onChange={value => {
65-
onUpdate(value);
66-
}}
67-
/>
68-
);
69-
},
70-
);
71-
72-
CodeEditor.displayName = "CodeEditor";
73-
74-
export default CodeEditor;
60+
return (
61+
<CodeMirror
62+
value={codeValue}
63+
minWidth="100%"
64+
height="100%"
65+
ref={editorRef}
66+
extensions={extensions}
67+
onChange={value => {
68+
onUpdate(value);
69+
}}
70+
/>
71+
);
72+
}

0 commit comments

Comments
 (0)