我正在用annotations
渲染一个react-ace
组件,如下所示:
<ReactAce
mode={'javascript'}
// ...
annotations={[{row: 0, column: 0, type: 'error', text: 'Some error.'}]}
/>
手动注释将短暂显示,然后在工作人员运行后删除。
此 gif 显示页面刷新。 在每个页面加载时,注释都会出现,但随后会被删除。
我已经用setOptions={{useWorker: false}}
禁用了工人,但这也禁用了手动完成的注释。
谢谢!
我觉得应该有两组注释。 手动添加的注释和模式解析器生成的注释。 我认为它们目前相互碰撞并相互擦除......
是的,这就是正在发生的事情。 我不确定是否有可能在工作人员的生命周期之外存在注释。
我正面临着同样的挑战。
我希望能够向编辑器添加自定义注释,同时仍保留工作人员的注释。
在我设置自定义注释后,工作人员的注释会覆盖我的注释。
我已经看到了像这样禁用工人的建议。
setOptions={{useWorker: false}}
但是,这样做会禁用工人的注释,因此我所有的 linting/语法突出显示都消失了。 (不完全是我想要的)
我希望能够将工作人员的注释与我的自定义注释合并。
有人可以建议如何解决这个问题吗?
您好,我遇到了类似的情况,无法添加自定义错误消息。 有什么解决办法吗?
我没有使用annotations
道具,而是手动setAnnotations
。
const Editor = ({ annotations: customAnnotations = [], value }) => {
const [annotations, setAnnotations] = useState([]);
const [editor, setEditor] = useState();
const nextAnnotations = [
...annotations.filter(({ custom }) => !custom), // annotations by worker
...customAnnotations.map((annotation) => ({ ...annotation, custom: true })) // flag for exclusion
];
useEffect(() => {
if (editor) {
editor.getSession().setAnnotations(nextAnnotations);
}
}, [editor, JSON.stringify(nextAnnotations)]);
return (
<ReactAce
mode="html"
onLoad={setEditor}
onValidate={setAnnotations}
setOptions={{ useWorker: true }}
value={value}
/>
}
最有用的评论
我没有使用
annotations
道具,而是手动setAnnotations
。