|
|
@ -515,25 +515,43 @@ |
|
|
insertText(text) { |
|
|
insertText(text) { |
|
|
const editor = this.$refs.editor |
|
|
const editor = this.$refs.editor |
|
|
const selection = window.getSelection() |
|
|
const selection = window.getSelection() |
|
|
|
|
|
|
|
|
if (selection.rangeCount > 0) { |
|
|
if (selection.rangeCount > 0) { |
|
|
const range = selection.getRangeAt(0) |
|
|
const range = selection.getRangeAt(0) |
|
|
const textNode = document.createTextNode(text) |
|
|
const textNode = document.createTextNode(text) |
|
|
range.insertNode(textNode) |
|
|
range.insertNode(textNode) |
|
|
} else { |
|
|
} else { |
|
|
editor.innerHTML += `<p>${text}</p>` |
|
|
if (editor.innerHTML.trim() === '') { |
|
|
|
|
|
editor.innerHTML = `<p>${text}</p>` |
|
|
|
|
|
} else { |
|
|
|
|
|
editor.innerHTML += `<p>${text}</p>` |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.$nextTick(() => { |
|
|
|
|
|
this.updateWordCount() |
|
|
|
|
|
}) |
|
|
}, |
|
|
}, |
|
|
insertHTML(html) { |
|
|
insertHTML(html) { |
|
|
const editor = this.$refs.editor |
|
|
const editor = this.$refs.editor |
|
|
const selection = window.getSelection() |
|
|
const selection = window.getSelection() |
|
|
|
|
|
|
|
|
if (selection.rangeCount > 0) { |
|
|
if (selection.rangeCount > 0) { |
|
|
const range = selection.getRangeAt(0) |
|
|
const range = selection.getRangeAt(0) |
|
|
const div = document.createElement('div') |
|
|
const div = document.createElement('div') |
|
|
div.innerHTML = html |
|
|
div.innerHTML = html |
|
|
range.insertNode(div) |
|
|
range.insertNode(div) |
|
|
} else { |
|
|
} else { |
|
|
editor.innerHTML += html |
|
|
if (editor.innerHTML.trim() === '') { |
|
|
|
|
|
editor.innerHTML = `<p>${html}</p>` |
|
|
|
|
|
} else { |
|
|
|
|
|
editor.innerHTML += `<p>${html}</p>` |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.$nextTick(() => { |
|
|
|
|
|
this.updateWordCount() |
|
|
|
|
|
}) |
|
|
}, |
|
|
}, |
|
|
onInput() { |
|
|
onInput() { |
|
|
this.content = this.$refs.editor.innerHTML |
|
|
this.content = this.$refs.editor.innerHTML |
|
|
@ -566,7 +584,7 @@ |
|
|
}, |
|
|
}, |
|
|
onFocus() { |
|
|
onFocus() { |
|
|
const editor = this.$refs.editor |
|
|
const editor = this.$refs.editor |
|
|
if (editor.innerText.trim() === '' || editor.innerText === this.placeholder) { |
|
|
if (editor.innerText.trim() === '' && editor.innerHTML.trim() === '') { |
|
|
editor.innerHTML = '' |
|
|
editor.innerHTML = '' |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
|