Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何获取codemirror实例?How to get codemirror object? #452

Closed
Cloudkkk opened this issue Feb 2, 2023 · 3 comments
Closed

如何获取codemirror实例?How to get codemirror object? #452

Cloudkkk opened this issue Feb 2, 2023 · 3 comments

Comments

@Cloudkkk
Copy link

Cloudkkk commented Feb 2, 2023

环境:react-codemirror 4.3.2、codemirror 5.65.0、react 17
我的需求是 获取到codemirror实例,然后通过doc.markText类似的api 传入行号将我所需要代码片 高亮/加自定义样式。
但我不知道如何使用react-codemirror实现上述操作?拿不到实例~
期待大佬回答

environment:react-codemirror 4.3.2、codemirror 5.65.0、react 17
What I need to do is getting the codemirror object then using doc.markText .etc APIs with lines number as props to make my code section highlight or get some custom styles。
But now I dont know how to use react-codemirror to achieve because first of all I couldnt get the codemirror object
hope for reply :>

@jaywcjlove
Copy link
Member

useImperativeHandle(ref, () => ({ editor: editor.current, state: state, view: view }), [
editor,
container,
state,
view,
]);

使用 ref 应该可以获取 @Cloudkkk

@Cloudkkk
Copy link
Author

Cloudkkk commented Feb 3, 2023

感谢回答,昨天看了一部分文档,发现之前理解的有点问题。
codemirror6已经不支持使用api去改代码片的样式了,可能要自定义extension来完成,我需要重新想下实现方案。。。。

@jaywcjlove
Copy link
Member

https://github.com/uiwjs/react-codemirror/tree/v3

@Cloudkkk 如果要使用 cm 5 可以使用 @uiw/react-codemirror v3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants