Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

How to change blockType by pressing keyboard #3170

Open
qirong77 opened this issue Oct 6, 2022 · 0 comments
Open

How to change blockType by pressing keyboard #3170

qirong77 opened this issue Oct 6, 2022 · 0 comments

Comments

@qirong77
Copy link

qirong77 commented Oct 6, 2022

I want to change the blocktype when I tag something.
For example , I want to change the current blocktype to 'header-one' when I press 'x' in my keyboard, here is my code

  const handleBefeforeInput = (
    chars: string,
    editorState: EditorState,
    eventTimeStamp: number
  ) => {
    if (true) {
      if (chars === 'x') {
    setEditorState(RichUtils.toggleBlockType(editorState, 'header-one'))
      }
      return 'not-handled'
    } else {
      return 'handled'
    }
  }

It works at the first time , but when I press enter or tag in other block , the blocktype turn to 'unstyled'. I dont know how to fix this problem , can anybody help me ,thanks

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

No branches or pull requests

1 participant