diff --git a/components/autocomplete/AutoComplete.vue b/components/autocomplete/AutoComplete.vue index 8730d6798..8b648b225 100755 --- a/components/autocomplete/AutoComplete.vue +++ b/components/autocomplete/AutoComplete.vue @@ -663,29 +663,19 @@ export default { this.multiple && event.stopPropagation(); // To prevent onArrowRightKeyOnMultiple method }, onHomeKey(event) { - const target = event.currentTarget; - const len = target.value.length; - - if (event.shiftKey) { - event.currentTarget.setSelectionRange(0, len); - } else { - event.currentTarget.setSelectionRange(0, 0); - } + const { currentTarget } = event; + const len = currentTarget.value.length; + currentTarget.setSelectionRange(0, event.shiftKey ? len : 0); this.focusedOptionIndex = -1; event.preventDefault(); }, onEndKey(event) { - const target = event.currentTarget; - const len = target.value.length; - - if (event.shiftKey) { - event.currentTarget.setSelectionRange(0, len); - } else { - target.setSelectionRange(len, len); - } + const { currentTarget } = event; + const len = currentTarget.value.length; + currentTarget.setSelectionRange(event.shiftKey ? 0 : len, len); this.focusedOptionIndex = -1; event.preventDefault(); diff --git a/components/multiselect/MultiSelect.vue b/components/multiselect/MultiSelect.vue index 9ce02cc4c..fa5fe5412 100755 --- a/components/multiselect/MultiSelect.vue +++ b/components/multiselect/MultiSelect.vue @@ -660,8 +660,12 @@ export default { pressedInInputText && (this.focusedOptionIndex = -1); }, onHomeKey(event, pressedInInputText = false) { + const { currentTarget } = event; + if (pressedInInputText) { - event.currentTarget.setSelectionRange(0, 0); + const len = currentTarget.value.length; + + currentTarget.setSelectionRange(0, event.shiftKey ? len : 0); this.focusedOptionIndex = -1; } else { let metaKey = event.metaKey || event.ctrlKey; @@ -679,11 +683,12 @@ export default { event.preventDefault(); }, onEndKey(event, pressedInInputText = false) { - if (pressedInInputText) { - const target = event.currentTarget; - const len = target.value.length; + const { currentTarget } = event; - target.setSelectionRange(len, len); + if (pressedInInputText) { + const len = currentTarget.value.length; + + currentTarget.setSelectionRange(event.shiftKey ? 0 : len, len); this.focusedOptionIndex = -1; } else { let metaKey = event.metaKey || event.ctrlKey;