score:2

Accepted answer

based on your check, and this editorState.getCurrentContent().getBlockMap().first().getKey() === selectionState.getAnchor/FocusKey()

score:1

Here is an example of how I use the standard handleKeyCommand function to detect whether or not I am at the start of the first line of a DraftJS editor:

handleKeyCommand(command, editorState) {

  const selectionState = editorState.getSelection()

  const firstline = (editorState.getCurrentContent().getBlockMap().first().getKey() == selectionState.getFocusKey())

  const startofline = (selectionState.getAnchorOffset() == 0)

  if (firstline && startofline) {
    // Your caret is at the start of the first line of your DraftJS editor.
  }
}

Related Query

More Query from same tag