facebookarchive / draft-js

A React framework for building text editors.
https://draftjs.org/
MIT License
22.56k stars 2.64k forks source link

how to stop the style i add in replaceText? #3176

Open chenjiashrimp opened 1 year ago

chenjiashrimp commented 1 year ago
`(text: string, anchorOffset: number, focusOffset: number) => {
    const contentState = editorState.getCurrentContent()
    const selection = editorState.getSelection()
    const newSelection = selection.merge({
        anchorOffset: anchorOffset,
        focusOffset: focusOffset
    })

    let nextEditorState = EditorState.createEmpty()
    let nextContentState

    nextContentState = Modifier.replaceText(contentState, newSelection, text, OrderedSet.of('Blue'))
    nextEditorState = EditorState.push(editorState, nextContentState, 'insert-characters')

    setEditorState(nextEditorState);`

i want to use replaceText to replace partial text with blue font(i define a style called 'Blue').I only want blue text from 'anchorOffset' to 'focusOffset', But when i continue to enter the text, the text is always blue, not black. I do not know how to stop 'Blue' style.