1 Commits

Author SHA1 Message Date
c136bbe2bb Ignore keys used for text highlight 2022-07-09 15:14:18 +03:00

View File

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