@@ -17,9 +17,10 @@ import {
1717 Select ,
1818 Switch ,
1919 Text ,
20+ TextArea ,
2021 TextField ,
2122} from "@radix-ui/themes" ;
22- import { useAtom , useAtomValue , useStore } from "jotai" ;
23+ import { atom , useAtom , useAtomValue , useStore } from "jotai" ;
2324import { atomWithStorage } from "jotai/utils" ;
2425import type * as monaco from "monaco-editor" ;
2526import {
@@ -88,15 +89,27 @@ const emptyBeatSymbolAtom = atomWithStorage(
8889 "importFromText.emptyBeatSymbol" ,
8990 "^" ,
9091) ;
92+ const textValueAtom = atom ( "" ) ;
93+
94+ const ImportFromTextEditor = memo ( ( ) => {
95+ const [ value , setValue ] = useAtom ( textValueAtom ) ;
96+ return (
97+ < TextArea
98+ style = { {
99+ height : "calc(80vh - 5em)" ,
100+ flex : "1 1 auto" ,
101+ fontFamily : "var(--code-font-family)"
102+ } }
103+ value = { value }
104+ onChange = { ( evt ) => setValue ( evt . currentTarget . value ) }
105+ />
106+ ) ;
107+ } ) ;
91108
92109export const ImportFromText = ( ) => {
93- const editorRef = useRef < monaco . editor . IStandaloneCodeEditor > ( null ) ;
94- const monacoRef = useRef < Monaco > ( null ) ;
95- const [ value , setValue ] = useState ( "" ) ;
96110 const [ importFromTextDialog , setImportFromTextDialog ] = useAtom (
97111 importFromTextDialogAtom ,
98112 ) ;
99- const isDarkTheme = useAtomValue ( isDarkThemeAtom ) ;
100113
101114 const [ importMode , setImportMode ] = useAtom ( importModeAtom ) ;
102115 const [ lineSeparatorMode , setLineSeparatorMode ] = useAtom (
@@ -269,96 +282,6 @@ export const ImportFromText = () => {
269282 [ store ] ,
270283 ) ;
271284
272- function handleEditorWillMount ( monaco : Monaco ) {
273- console . log (
274- "monaco.languages.getLanguages()" ,
275- monaco . languages . getLanguages ( ) ,
276- ) ;
277- }
278-
279- function handleEditorDidMount (
280- editor : monaco . editor . IStandaloneCodeEditor ,
281- monaco : Monaco ,
282- ) {
283- editorRef . current = editor ;
284- monacoRef . current = monaco ;
285-
286- editor . updateOptions ( {
287- smoothScrolling : true ,
288- } ) ;
289-
290- // let decoCol: IEditorDecorationsCollection | null = null;
291-
292- // editor.onDidChangeModelContent(() => {
293- // try {
294- // decoCol?.clear();
295- // } catch {
296- // /* empty */
297- // }
298- // const model = editor.getModel();
299- // if (!model) return;
300-
301- // const deco: IModelDeltaDecoration[] = [];
302-
303- // deco.push(
304- // ...model
305- // .findMatches(wordSeparator, true, false, true, null, false)
306- // .map((match) => ({
307- // range: match.range,
308- // options: {
309- // inlineClassName: styles.wordSeparator,
310- // },
311- // })),
312- // );
313-
314- // deco.push(
315- // ...model
316- // .findMatches(lineSeparator, true, false, true, null, false)
317- // .map((match) => ({
318- // range: match.range,
319- // options: {
320- // inlineClassName: styles.lineSeparator,
321- // },
322- // })),
323- // );
324-
325- // deco.push(
326- // ...model
327- // .findMatches(bgLyricPrefix, true, false, true, null, false)
328- // .map((match) => ({
329- // range: match.range,
330- // options: {
331- // inlineClassName: styles.bgLinePrefix,
332- // },
333- // })),
334- // );
335-
336- // deco.push(
337- // ...model
338- // .findMatches(duetLyricPrefix, true, false, true, null, false)
339- // .map((match) => ({
340- // range: match.range,
341- // options: {
342- // inlineClassName: styles.duetLinePrefix,
343- // },
344- // })),
345- // );
346-
347- // deco.push(
348- // ...model
349- // .findMatches(emptyBeatSymbol, true, false, true, null, false)
350- // .map((match) => ({
351- // range: match.range,
352- // options: {
353- // inlineClassName: styles.emptyBeatSymbol,
354- // },
355- // })),
356- // );
357-
358- // decoCol = editor.createDecorationsCollection(deco);
359- // });
360- }
361-
362285 return (
363286 < Dialog . Root
364287 open = { importFromTextDialog }
@@ -377,7 +300,7 @@ export const ImportFromText = () => {
377300 < Button
378301 onClick = { ( ) => {
379302 try {
380- onImport ( value ) ;
303+ onImport ( store . get ( textValueAtom ) ) ;
381304 setImportFromTextDialog ( false ) ;
382305 } catch ( e ) {
383306 error (
@@ -397,20 +320,20 @@ export const ImportFromText = () => {
397320 sm : "row" ,
398321 } }
399322 >
400- < Card style = { { flex : "1 1 auto" } } >
323+ { /* <Card style={{ flex: "1 1 auto" }}>
401324 <Inset>
402- < SuspensePlaceHolder >
403- < MonacoEditor
404- height = "calc(80vh - 5em)"
405- theme = { isDarkTheme ? "vs-dark" : "light" }
406- beforeMount = { handleEditorWillMount }
407- onMount = { handleEditorDidMount }
408- value = { value }
409- onChange = { ( v ) => setValue ( v ?? "" ) }
410- />
411- </ SuspensePlaceHolder >
325+ <TextArea
326+ style={{
327+ height: "calc(80vh - 5em)",
328+ flex: "1 1 auto"
329+ }}
330+ value={value}
331+ onChange={(evt) => setValue(evt.currentTarget.value)}
332+ />
412333 </Inset>
413- </ Card >
334+ </Card> */ }
335+
336+ < ImportFromTextEditor />
414337 < Grid
415338 columns = "2"
416339 gapY = "2"
0 commit comments