1 Commits

Author SHA1 Message Date
2bbd11a7ed Fixed two way binding 2022-07-09 19:49:29 +03:00

View File

@@ -27,16 +27,21 @@ export default {
},
data () {
return {
focused: false,
body: ''
focused: false
}
},
computed: {
valueModel: {
get () { return this.value },
set (value) {
this.$emit('input', value)
}
},
showPlaceholder () {
return !this.body.replace(/^\s*\n/gm, '').length
return !this.valueModel.replace(/^\s*\n/gm, '').length
},
computedBody () {
return highlight(this.body, {
return highlight(this.valueModel, {
extractUrlsWithoutProtocol: this.extractUrlsWithoutProtocol
})
}
@@ -64,18 +69,14 @@ export default {
},
clear () {
this.$refs.mbody.innerText = ''
this.body = ''
this.valueModel = ''
},
onKeyUp (e) {
const keysToIgnore = ['Shift', 'Meta', 'Control', 'Alt', 'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight']
if (keysToIgnore.includes(e.key)) return
let caretPosition = this.getCaretPos()
if (e.key === 'Enter') {
if (e.keyCode === 13) { // Enter key
caretPosition++
}
this.body = e.target.innerText
this.$emit('input', this.body)
this.valueModel = e.target.innerText
this.$nextTick(() => {
this.setCaretPos(caretPosition)
})