Browse Source

修复一些bug,撤回操作异常问题,粘贴图片后换行问题

master
fangxin 2 years ago
parent
commit
875ed55237
  1. 37
      im-web/src/components/chat/ChatInput.vue

37
im-web/src/components/chat/ChatInput.vue

@ -52,6 +52,7 @@ export default {
history: [defaultContentHtml], history: [defaultContentHtml],
atIng: false, atIng: false,
isEmpty: true, isEmpty: true,
changeStored: true,
blurRange: null blurRange: null
} }
}, methods: { }, methods: {
@ -134,7 +135,7 @@ export default {
selection.addRange(t1); selection.addRange(t1);
// //
if (element.focus) { if (element.focus) {
element.focus(); element.focus();
} }
}) })
}, },
@ -169,7 +170,9 @@ export default {
if (this.history.length <= 1) { if (this.history.length <= 1) {
return; return;
} }
if (this.changeStored) {
this.history.pop(); this.history.pop();
}
let last = this.history.pop(); let last = this.history.pop();
// console.log('', last); // console.log('', last);
this.contentHtml = last; this.contentHtml = last;
@ -177,19 +180,13 @@ export default {
// //
this.history.push(this.defaultContentHtml); this.history.push(this.defaultContentHtml);
} }
// dom
setTimeout(() => { setTimeout(() => {
let t = this.$refs.content.lastElementChild.lastChild; let t = this.$refs.content.lastElementChild.lastChild;
// t.focus(); if (!t || !t.textContent) {
let r = document.createRange(); return;
r.setStart(t, t.textContent.length); }
r.setEnd(t, t.textContent.length); this.selectElement(t, t.textContent.length);
r.collapse();
// r.selectNodeContents(t.lastChild);
let selection = document.getSelection();
selection.removeAllRanges();
selection.addRange(r);
}) })
} }
} }
@ -212,8 +209,8 @@ export default {
// at // at
if (this.atIng) { if (this.atIng) {
if (e.keyCode === 38) { if (e.keyCode === 38) {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
this.$refs.atBox.moveUp(); this.$refs.atBox.moveUp();
} }
if (e.keyCode === 40) { if (e.keyCode === 40) {
@ -250,11 +247,12 @@ export default {
blurRange.collapse() blurRange.collapse()
this.atSearchText = ""; this.atSearchText = "";
this.selectElement(textNode); this.selectElement(textNode, 1);
}, },
onEditorInput(e) { onEditorInput(e) {
// timeoutcompositionend // timeoutcompositionend
this.isEmpty = false; this.isEmpty = false;
this.changeStored = false;
setTimeout(() => { setTimeout(() => {
if (this.$props.groupMembers && !this.compositionFlag) { if (this.$props.groupMembers && !this.compositionFlag) {
let selection = window.getSelection() let selection = window.getSelection()
@ -282,8 +280,8 @@ export default {
if (textContent[i] === ' ') { if (textContent[i] === ' ') {
endIndex = i; endIndex = i;
break; break;
} }
} }
this.atSearchText = textContent.substring(startIndex + 1, endIndex).trim(); this.atSearchText = textContent.substring(startIndex + 1, endIndex).trim();
} }
}) })
@ -539,11 +537,12 @@ export default {
if (this.compositionFlag) { if (this.compositionFlag) {
return; return;
} }
let last = this.history[this.history.length]; let last = this.history[this.history.length - 1];
let newContent = this.$refs.content.innerHTML; let newContent = this.$refs.content.innerHTML;
if (last !== newContent) { if (last !== newContent) {
this.history.push(newContent); this.history.push(newContent);
} }
this.changeStored = true;
}, 1000); }, 1000);
} }
} }
@ -573,7 +572,7 @@ export default {
> div { > div {
padding-left: 10px; padding-left: 10px;
//width: 1px; //width: 1px;
height: 30px; min-height: 30px;
} }
// bug // bug

Loading…
Cancel
Save