Skip to content

Commit c6fcce3

Browse files
committed
インデックスを正常に取得できていなかった問題を修正
1 parent 9dec20b commit c6fcce3

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

curve_editor/ui/src/editor_text.tsx

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,8 @@ const TextEditorPanel: React.FC<TextEditorPanelProps> = (props: TextEditorPanelP
1212
const editorRef = React.useRef<monaco.editor.IStandaloneCodeEditor | null>(null);
1313
const idxRef = React.useRef(props.idx);
1414

15-
const getIdx = () => {
16-
return props.idx;
17-
}
18-
1915
const updateEditor = () => {
2016
editorRef.current?.setValue(scriptEditor.getScript(scriptEditor.getId(props.idx)));
21-
console.log(props.idx, scriptEditor.getScript(scriptEditor.getId(props.idx)));
2217
}
2318

2419
const applyPreferences = () => {
@@ -42,10 +37,12 @@ const TextEditorPanel: React.FC<TextEditorPanelProps> = (props: TextEditorPanelP
4237
}
4338
}
4439

45-
if (idxRef.current != props.idx) {
46-
idxRef.current = props.idx;
47-
updateEditor();
48-
}
40+
React.useEffect(() => {
41+
if (idxRef.current != props.idx) {
42+
idxRef.current = props.idx;
43+
updateEditor();
44+
}
45+
}, [props.idx]);
4946

5047
React.useEffect(() => {
5148
const container = document.getElementById('container');
@@ -70,8 +67,7 @@ const TextEditorPanel: React.FC<TextEditorPanelProps> = (props: TextEditorPanelP
7067
// });
7168

7269
editorRef.current?.getModel()?.onDidChangeContent(event => {
73-
scriptEditor.setScript(scriptEditor.getId(getIdx()), editorRef.current?.getValue() ?? '');
74-
console.log(getIdx(), scriptEditor.getId(getIdx()), editorRef.current?.getValue() ?? '', scriptEditor.getScript(scriptEditor.getId(props.idx)));
70+
scriptEditor.setScript(scriptEditor.getId(idxRef.current), editorRef.current?.getValue() ?? '');
7571
});
7672

7773
window.chrome.webview.addEventListener('message', onMessageFromNative);

0 commit comments

Comments
 (0)