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.
}
}
Source: stackoverflow.com
Related Query
- Cursor at very start of first line in Draft.js editor
- react-monaco-editor text appears in middle of editor despite cursor being at the start of line
- Focus Editor, Position Cursor at Start of First Block
- ReactJS: How to make a component call a method only the very first it is rendered?
- TinyMCE React cursor back to start after typing a key
- Enforce jsx to start on new line if jsx is multiline
- How to give a focus effect to my Draft JS Editor border?
- Chart.js remove the first vertical line
- Draft JS editor does not update it's content when its value changed by parent component?
- How to stop Editor draftJS cursor jumping to beginning of text while typing in React Hooks?
- React Ace editor marker highlight the whole line even startCol and endCol defined to limit the columns
- Image not showing in react-draft-wysiwyg editor using draft js
- Image insertion at cursor in editor using slatejs
- How to check empty spaces in draft js Editor
- How to set initial editor state in react draft wysiwyg
- Is it possible to prevent moving the cursor to the start of an input field when type changes?
- React draft wysiwyg - Can't able to type text in editor after clearing editorState
- how to display the first and last grid complete in chart js in type line
- React Native-How do I start a TextInput with a value read from AsyncStorage when loading/rendering the screen first time in functional component?
- Why does cursor move to start of input field when value is changed dynamically?
- UnhandledPromiseRejectionWarning: Error: error:0906D06C:PEM routines:PEM_read_bio:no start line
- React.js start a new line after every number
- Draft JS: hide the cursor
- Displaying dates in Nivo Line Chart start at day - 1
- npm ERR! code ERR_OSSL_PEM_NO_START_LINE and routines:get_name:no start line when installing ReactJS
- React Cursor for Input Component Jumps to Start on Certain Deletes
- Set Dropdown Value Back to Placeholder or Very First Option After onClick Event on a Button?
- How to start the second div at the end of the first div.?
- Preserve white space line breaks in tinymce wysiwyg editor
- React DevTools show very big background when moving cursor to a react component
More Query from same tag
- ReactDOM.createPortal() is creating extra blank divs in next.js-typescript
- Dropdown list of names in ReactJS
- Using arrow functions inside React component does not transfer over parent context (which exists). this remains undefined in arrow function
- Why !important is not working in react js with inline style
- Testing: `Error: Invariant Violation: addComponentAsRefTo(...): Only a ReactOwner can have refs.` error
- Redux action no longer works when defining mapDispatchToProps As A Function
- docker containers on different ports work differently with the same configuration
- How to implement forgot password page on react-admin
- react How do I check if string is empty
- Material UI DatePicker Showing Wrong Date
- How to get multiple refs to use the same handleClick function?
- How can I map an array into an HTML grid?
- How to pass variables to Reactjs through kubernetes
- Event binding doesn't work in kendo popup when react is upgraded to 17.0.1
- How to export ReactJS app as package to be used in other app?
- react.js ant design range filter with start and end dates error
- How do I create a Typography component that can be used as h1, h2, h3, h4..etc
- Module not found: Can't resolve 'style'
- Relay container with no data
- React: Encountered two children with the same key
- Container of nav.logo move when i minimize screen
- How to build a table dynamically
- What is the reason routing in my project not works correctly?
- Updating model with GraphQL Mutation
- Why does my Auth.currentAuthenticatedUser() method return updated state after I reload and not when the useEffect's dependency runs (or login/logout)?
- React with Google Maps Api, how to recenter map
- React Use State Hook error TypeError: setUser is not a function
- Positioning modal using CSS in React
- Firestore composite query pagination
- How to create dynamically a Hook in React?