فهرست منبع

Input / Select: fix Korean IME composition bug (#10648)

* Input: fix cursor goes to the end of the text(#10611)

* Input: fix cursor goes to the end of the text(#10611)

* Update input.vue

* Update select.vue

* Update input.vue
Hyuni 7 سال پیش
والد
کامیت
783cb2691f
3فایلهای تغییر یافته به همراه13 افزوده شده و 3 حذف شده
  1. 4 1
      packages/input/src/input.vue
  2. 5 2
      packages/select/src/select.vue
  3. 4 0
      src/utils/shared.js

+ 4 - 1
packages/input/src/input.vue

@@ -100,6 +100,7 @@
   import Migrating from 'element-ui/src/mixins/migrating';
   import calcTextareaHeight from './calcTextareaHeight';
   import merge from 'element-ui/src/utils/merge';
+  import { isKorean } from 'element-ui/src/utils/shared';
 
   export default {
     name: 'ElInput',
@@ -255,7 +256,9 @@
           this.isOnComposition = false;
           this.handleInput(event);
         } else {
-          this.isOnComposition = true;
+          const text = event.target.value;
+          const lastCharacter = text[text.length - 1] || '';
+          this.isOnComposition = !isKorean(lastCharacter);
         }
       },
       handleInput(event) {

+ 5 - 2
packages/select/src/select.vue

@@ -147,6 +147,7 @@
   import { getValueByPath } from 'element-ui/src/utils/util';
   import { valueEquals } from 'element-ui/src/utils/util';
   import NavigationMixin from './navigation-mixin';
+  import { isKorean } from 'element-ui/src/utils/shared';
 
   const sizeMap = {
     'medium': 36,
@@ -412,11 +413,13 @@
 
     methods: {
       handleComposition(event) {
+        const text = event.target.value;
         if (event.type === 'compositionend') {
           this.isOnComposition = false;
-          this.handleQueryChange(event.target.value);
+          this.handleQueryChange(text);
         } else {
-          this.isOnComposition = true;
+          const lastCharacter = text[text.length - 1] || '';
+          this.isOnComposition = !isKorean(lastCharacter);
         }
       },
       handleQueryChange(val) {

+ 4 - 0
src/utils/shared.js

@@ -1,3 +1,7 @@
 export function isDef(val) {
   return val !== undefined && val !== null;
 }
+export function isKorean(text) {
+  const reg = /([(\uAC00-\uD7AF)|(\u3130-\u318F)])+/gi;
+  return reg.test(text);
+}