首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >多个插件中的SlateJs RenderMark

多个插件中的SlateJs RenderMark
EN

Stack Overflow用户
提问于 2019-07-05 10:20:13
回答 1查看 328关注 0票数 1

我在多个插件中使用renderMark,但是只有插件堆栈中的顶级插件才会被调用,其余的将被忽略。

//第一个插件

代码语言:javascript
复制
function MarkHotkey(options) {
  const { type, key, RenderTag, icon } = options

  return {
    onKeyDown(event, editor, next) {
      if (!event.ctrlKey || event.key != key) return next();
      event.preventDefault();
      editor.toggleMark(type)
    },
    renderMark(props, editor, next){
      const { children, mark, attributes } = props;
      if(type === mark.type){
       return <u {...attributes}>{children}</u>
     }
      next();
    }

//第二个插件

代码语言:javascript
复制
function MarkHotkey1(options) {
  const { type, key, RenderTag, icon } = options
  return {
    onKeyDown(event, editor, next) {
      if (!event.ctrlKey || event.key != key) return next();
      event.preventDefault();
      editor.toggleMark(type)
    },
    renderMark(props, editor, next){
      const { children, mark, attributes } = props;
      if(type === mark.type){
       return <i {...attributes}>{children}</i>
      }
      next();
    }

//插件阵列

代码语言:javascript
复制
const plugins = [
  MarkHotkey1({ key: 'i', type: 'italic' ,RenderTag : 'em',icon :''}),
  MarkHotkey({ key: 'u', type: 'underline' ,RenderTag : 'u',icon :''}),
]

//带有插件的呈现编辑器

代码语言:javascript
复制
class App extends React.Component {
  state = {
    value: Value.fromJSON(initialValue), // editor initialisation
  }

  onChange = ({ value }) => {
    this.setState({ value })
  }

  render() {
    return <Editor 
    value={this.state.value} 
    onChange={this.onChange}
    plugins={plugins}
    />
  }

}

export default App;

当我按下ctrl+i时,它正按预期工作,而ctrl+u则无法工作。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-07-11 04:10:47

你必须返回next(),而不仅仅是调用它。在此之后,您的插件应该按列出的顺序启动,并继续传递事件,直到其中一个插件不返回next()

希望这能有所帮助!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56901165

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档