Fixed issue with cursor position in Composer, fixes emoji picker postioning

• Fixed:
- issue with cursor position in Composer, fixes emoji picker postioning
This commit is contained in:
mgabdev
2020-12-31 18:48:35 -05:00
parent 4174597a24
commit 3809700f17
4 changed files with 11 additions and 7 deletions

View File

@@ -175,13 +175,17 @@ class Composer extends React.PureComponent {
plainText: value,
})
const selectionState = editorState.getSelection()
const selectionState = editorState.getSelection()
const currentBlockKey = selectionState.getStartKey()
const currentBlockIndex = blocks.findIndex((k) => k.key === currentBlockKey)
const priorBlockTextLength = blocks.splice(0, currentBlockIndex).map(block => (!block.text.trim() && '') || block.text).join('\n').length
const selectionStart = selectionState.getStartOffset()
const cursorPosition = priorBlockTextLength + selectionStart
const rawObject = convertToRaw(content)
const markdownString = this.props.isPro ? draftToMarkdown(rawObject,markdownOptions) : null
this.props.onChange(null, value, markdownString, selectionStart)
this.props.onChange(null, value, markdownString, cursorPosition)
}
handleOnFocus = () => {

View File

@@ -285,7 +285,7 @@ const mapDispatchToProps = (dispatch) => ({
onPickEmoji: (emoji) => {
dispatch(useEmoji(emoji))
dispatch(insertEmojiCompose(emoji, false))
dispatch(insertEmojiCompose(emoji))
},
})