editorState에서 까다로운 상태 변이를하고 있고 선택을 잃어 버리고 있습니다.돌연변이 후 선택을 잃는
필자는 currentText()를 가져와 일부 마법 라이브러리가있는 HTML로 변환하고이를 editorState로 다시 변환해야합니다. 그게 잘 작동, 그것은 너무 열심히 휴식 단지 선택입니다.
지금 당장은 첫 번째 시작에서 선택을 시도한 다음 forceSelection
을 수행하지만 selection.hasFocus()
과 관련된 일부 오류는 발생하지 않습니다.
저는 앵커와 오프셋을 기반으로 "새로운"선택을 계산해야하지만 실제로 그렇게 할 생각은 없다고 생각합니다.
// onChangeHandler:
const currentContentState = editorState.getCurrentContent()
const selectionState = editorState.getSelection()
const plainHtml = magicOperation(currentContentState.getPlainText())
const currentContentBlocks = convertFromHTML(plainHtml)
const contentState = ContentState.createFromBlockArray(currentContentBlocks)
const newEditorState = EditorState.createWithContent(contentState)
this.setState({
editorState: EditorState.forceSelection(
newEditorState,
selectionState
)
})
가 해킹되어 나는 그것을 달성 할 수 있다면 난 그냥 내가 확실히 사용하는 것이 원활하게 작동 내가 할 경우, 주변 DraftJS을 연주 해요 알고 : 같은
는 지금 내 코드 보인다 editorState 내에 HTML을 추가하기위한 Decorator.
시간 내 주셔서 감사합니다.
그래, convertinfFromHTML 대신 엔티티를 구현하고 있는데 여전히 선택 항목을 계산해야합니다. 권리? – davesnx
번호. selectionState의 anchorKey 및 focusKey 속성을 설정해야합니다. –
을 선택하고 병합 하시겠습니까? – davesnx