Commit f37e92cc authored by STLighter's avatar STLighter Committed by 杨奕

Input: cursor goes to the end when typing Chinese quickly (#11235)

autocomplete: remove composition event listeners because input has already handle it.
parent 563b4c0e
...@@ -10,9 +10,6 @@ ...@@ -10,9 +10,6 @@
<el-input <el-input
ref="input" ref="input"
v-bind="$props" v-bind="$props"
@compositionstart.native="handleComposition"
@compositionupdate.native="handleComposition"
@compositionend.native="handleComposition"
@input="handleChange" @input="handleChange"
@focus="handleFocus" @focus="handleFocus"
@blur="handleBlur" @blur="handleBlur"
...@@ -122,7 +119,6 @@ ...@@ -122,7 +119,6 @@
data() { data() {
return { return {
activated: false, activated: false,
isOnComposition: false,
suggestions: [], suggestions: [],
loading: false, loading: false,
highlightedIndex: -1 highlightedIndex: -1
...@@ -163,17 +159,9 @@ ...@@ -163,17 +159,9 @@
} }
}); });
}, },
handleComposition(event) {
if (event.type === 'compositionend') {
this.isOnComposition = false;
this.handleChange(event.target.value);
} else {
this.isOnComposition = true;
}
},
handleChange(value) { handleChange(value) {
this.$emit('input', value); this.$emit('input', value);
if (this.isOnComposition || (!this.triggerOnFocus && !value)) { if (!this.triggerOnFocus && !value) {
this.suggestions = []; this.suggestions = [];
return; return;
} }
......
...@@ -130,7 +130,8 @@ ...@@ -130,7 +130,8 @@
suffixOffset: null, suffixOffset: null,
hovering: false, hovering: false,
focused: false, focused: false,
isOnComposition: false isOnComposition: false,
valueBeforeComposition: null
}; };
}, },
...@@ -260,28 +261,34 @@ ...@@ -260,28 +261,34 @@
handleComposition(event) { handleComposition(event) {
if (event.type === 'compositionend') { if (event.type === 'compositionend') {
this.isOnComposition = false; this.isOnComposition = false;
this.currentValue = this.valueBeforeComposition;
this.valueBeforeComposition = null;
this.handleInput(event); this.handleInput(event);
} else { } else {
const text = event.target.value; const text = event.target.value;
const lastCharacter = text[text.length - 1] || ''; const lastCharacter = text[text.length - 1] || '';
this.isOnComposition = !isKorean(lastCharacter); this.isOnComposition = !isKorean(lastCharacter);
if (this.isOnComposition && event.type === 'compositionstart') {
this.valueBeforeComposition = text;
}
} }
}, },
handleInput(event) { handleInput(event) {
if (this.isOnComposition) return;
const value = event.target.value; const value = event.target.value;
this.$emit('input', value);
this.setCurrentValue(value); this.setCurrentValue(value);
if (this.isOnComposition) return;
this.$emit('input', value);
}, },
handleChange(event) { handleChange(event) {
this.$emit('change', event.target.value); this.$emit('change', event.target.value);
}, },
setCurrentValue(value) { setCurrentValue(value) {
if (value === this.currentValue) return; if (this.isOnComposition && value === this.valueBeforeComposition) return;
this.currentValue = value;
if (this.isOnComposition) return;
this.$nextTick(_ => { this.$nextTick(_ => {
this.resizeTextarea(); this.resizeTextarea();
}); });
this.currentValue = value;
if (this.validateEvent) { if (this.validateEvent) {
this.dispatch('ElFormItem', 'el.form.change', [value]); this.dispatch('ElFormItem', 'el.form.change', [value]);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment