Skip to content

Commit

Permalink
feat(NcRichContenteditable): put caret in the end when focus input
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
  • Loading branch information
Antreesy committed Dec 6, 2023
1 parent 8008811 commit fc0271f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/components/NcRichContenteditable/NcRichContenteditable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ export default {
role="textbox"
v-bind="$attrs"
v-on="listeners"
@focus="setCursorToEnd"
@input="onInput"
@compositionstart="isComposing = true"
@compositionend="isComposing = false"
Expand Down Expand Up @@ -649,6 +650,17 @@ export default {
selection.removeAllRanges()
selection.addRange(range)
},
setCursorToEnd() {
if (!document.createRange) {
return
}
const range = document.createRange()
range.selectNodeContents(this.$refs.contenteditable)
range.collapse(false)
const selection = window.getSelection()
selection.removeAllRanges()
selection.addRange(range)
},
/**
* Re-emit the input event to the parent
*
Expand Down

0 comments on commit fc0271f

Please sign in to comment.