英文:
Add Theme in Ace Editor (in react using ace-builds)
问题
I cannot directly access external URLs or view images, so I won't be able to see the browser error logs you've linked. However, I can help you with the code you provided and any specific questions you have regarding it. If you have any code-related questions or need assistance with a particular issue, please let me know, and I'll do my best to assist you.
英文:
I'm trying to use AceEditor (preferring to use ace-builds npm package than react-ace npm package) in a react project.
I succeed to create a basic text editor but cannot figure out how to change the themes or the languages workers, I have some problem to load the js files from the node_modules certainly a webpack problem but I don't really understand what's happening so if someone has some clue.
I'm using "ace-builds": "^1.15.2"
my code is
import React from "react";
import * as Ace from "ace-builds";
import "ace-builds/src-noconflict/theme-monokai";
type T_Props = { };
const OnlineIDE:React.FunctionComponent<T_Props> = (props:T_Props) =>
{
const editorElement = React.useRef<HTMLDivElement>(null);
const editorInstance:React.MutableRefObject<Ace.Ace.Editor|null> = React.useRef(null);
React.useEffect(():void =>
{
if (editorElement.current != null)
editorInstance.current = Ace.edit(editorElement.current);
if (editorInstance.current != null)
editorInstance.current.setTheme("theme_monokai");
}, []);
return (
<div
style=
{{
width: "50vw",
height: "50vh",
border: "black solid 2px",
display: "flex",
flexDirection: "column",
}}
>
<div
style=
{{
background: "rgb(235, 235, 235)",
color: "white",
display: "flex",
justifyContent: "end",
padding: "10px",
}}
>
</div>
<div style={{ width: "100%", height: "inherit" }} ref={editorElement}></div>
</div>
);
};
export default OnlineIDE;
and the errors I get in the browser:
答案1
得分: 0
在ace-builds中的路径名称相当混乱,使用.setTheme("ace/theme/monokai");
应该可以工作。
英文:
Path names in ace-builds are rather confusing, using .setTheme("ace/theme/monokai");
should work.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论