I'm using draft.js (and Electron). I have my custom spell checker set up and it's working to the extent that after doing a "webFrame.setSpellCheckProvider(...)" my draft editor is correcting displaying the mis-spelled words. At the same time I also am computing a list of possible replacements for a mis-spelled word, but the draft.js API documentation does not mention how to go about actually making the correction. I know there are a couple of npm modules that claim to handle this, but I want to understand how to do it "from scratch". Any suggestions would be greatly appreciated!
Asked
Active
Viewed 1,361 times
1 Answers
1
If you have identified a spelling mistake you want to fix, it would be identified by a block key with a start and ending position in the given block.
Then you need to replace the text using the Modifier component from Draft.js:
EditorState.push(
editorState,
Modifier.replaceText(
editorState.getCurrentContent(),
SelectionState.createEmpty(blockKey).merge({ anchorOffset: start, focusOffset: end}),
theCorrectedPhrase
)
)

mzedeler
- 4,177
- 4
- 28
- 41