React-ace: 工作人员删除的手动注释

创建于 2018-07-02  ·  5评论  ·  资料来源: securingsincity/react-ace

问题

我正在用annotations渲染一个react-ace组件,如下所示:

<ReactAce
  mode={'javascript'}
  // ...
  annotations={[{row: 0, column: 0, type: 'error', text: 'Some error.'}]}
/>

手动注释将短暂显示,然后在工作人员运行后删除。
此 gif 显示页面刷新。 在每个页面加载时,注释都会出现,但随后会被删除。
annotation

我已经用setOptions={{useWorker: false}}禁用了工人,但这也禁用了手动完成的注释。

谢谢!

Documentation

最有用的评论

我没有使用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}
   />
}

所有5条评论

我觉得应该有两组注释。 手动添加的注释和模式解析器生成的注释。 我认为它们目前相互碰撞并相互擦除......

是的,这就是正在发生的事情。 我不确定是否有可能在工作人员的生命周期之外存在注释。

我正面临着同样的挑战。
我希望能够向编辑器添加自定义注释,同时仍保留工作人员的注释。

在我设置自定义注释后,工作人员的注释会覆盖我的注释。
我已经看到了像这样禁用工人的建议。

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}
   />
}
此页面是否有帮助?
0 / 5 - 0 等级

相关问题

Bobcui001 picture Bobcui001  ·  5评论

henviso picture henviso  ·  7评论

avalkowsky picture avalkowsky  ·  6评论

viridia picture viridia  ·  4评论

kolbinski picture kolbinski  ·  5评论