-
我自己做了一个界面,然后希望在界面的一部分使用monaco编辑器展示数据(如下红色框内用于展示数据),应该如何使用opensumi现有的service来把数据渲染出来? |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 17 replies
-
你可以尝试使用 EditorCollectionService 来创建monaco Editor。
|
Beta Was this translation helpful? Give feedback.
-
以及一些monaco包的导入,因为本身做Opensumi模块开发的时候,Opensumi会自带monaco的依赖。因此可以这样导包:
|
Beta Was this translation helpful? Give feedback.
-
直接使用 monaco.createEditor 可能会导致一些monaco全局共享状态的错乱,以及一些textmate服务也没法在自定义编辑器上用到。因此用editorCollectionService.createCodeEditor会更方便些。 不过editorCollectionService.createCodeEditor这个本身也不算是我们在文档中固定对外的api,这个做法更像是通过代码去调用Opensumi创建Editor过程中的一些核心服务。 |
Beta Was this translation helpful? Give feedback.
-
推荐查看 官方的MonacoPlayground: https://microsoft.github.io/monaco-editor/playground.html?source=v0.36.1#example-creating-the-editor-hello-world 或者可以问问 ChatGPT 也可以获得不错的答案 |
Beta Was this translation helpful? Give feedback.
-
可以使用 CodeEditor 组件, 不过这样不能直接使用 monaco 的 model,需要参照 opensumi 标准的向 documentModel 的注册 provider,通过 uri 来获取内容的 import { CodeEditor } from '@opensumi/ide-editor/lib/browser';
() => {
return <CodeEditor style={{"height": "500px"}} uri={URI.parse('custom-scheme:/path/something')}/>
} CodeEditor 组件源码 ref: https://github.com/opensumi/core/blob/main/packages/editor/src/browser/view/editor.react.tsx |
Beta Was this translation helpful? Give feedback.
-
参考一下我最近写的这个Samples,看看能否解答你的疑问 |
Beta Was this translation helpful? Give feedback.
参考一下我最近写的这个Samples,看看能否解答你的疑问
https://github.com/opensumi/opensumi-module-samples/pull/24/files