为所有文本输入框添加右键快速粘贴的功能
This commit is contained in:
@@ -10,10 +10,13 @@
|
||||
@input="handleInput"
|
||||
@change="$emit('change', $event.target.value.trim())"
|
||||
@keyup.enter="$emit('submit', $event.target.value.trim())"
|
||||
@contextmenu="handleContextMenu"
|
||||
>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { clipboardReadText } from '@common/utils/electron'
|
||||
|
||||
export default {
|
||||
props: {
|
||||
placeholder: {
|
||||
@@ -32,17 +35,54 @@ export default {
|
||||
type: String,
|
||||
default: 'text',
|
||||
},
|
||||
trim: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
stopContentEventPropagation: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
autoPaste: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
// bindValue: {
|
||||
// type: Boolean,
|
||||
// default: true,
|
||||
// },
|
||||
},
|
||||
emits: ['update:modelValue', 'submit', 'change'],
|
||||
methods: {
|
||||
handleInput(event) {
|
||||
let value = event.target.value.trim()
|
||||
event.target.value = value
|
||||
let value = event.target.value
|
||||
if (this.trim) {
|
||||
value = value.trim()
|
||||
event.target.value = value
|
||||
}
|
||||
this.$emit('update:modelValue', value)
|
||||
},
|
||||
focus() {
|
||||
this.$refs.dom_input.focus()
|
||||
},
|
||||
handleContextMenu(event) {
|
||||
if (this.stopContentEventPropagation) event.stopPropagation()
|
||||
if (!this.autoPaste) return
|
||||
let dom_input = this.$refs.dom_input
|
||||
if (dom_input.selectionStart === null) return
|
||||
let str = clipboardReadText()
|
||||
str = str.trim()
|
||||
str = str.replace(/\t|\r\n|\n|\r/g, ' ')
|
||||
str = str.replace(/\s+/g, ' ')
|
||||
const text = dom_input.value
|
||||
// if (dom_input.selectionStart == dom_input.selectionEnd) {
|
||||
const value = text.substring(0, dom_input.selectionStart) + str + text.substring(dom_input.selectionEnd, text.length)
|
||||
event.target.value = value
|
||||
this.$emit('update:modelValue', value)
|
||||
// } else {
|
||||
// clipboardWriteText(text.substring(dom_input.selectionStart, dom_input.selectionEnd))
|
||||
// }
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xlink="http://www.w3.org/1999/xlink" viewBox="0 0 42 42" space="preserve">
|
||||
<use xlink:href="#icon-addTo" />
|
||||
</svg>
|
||||
<input :class="$style.newListInput" :value="newListName" type="text" :placeholder="$t('lists__new_list_input')" @keyup.enter="handleSaveList($event)" @blur="handleSaveList($event)">
|
||||
<base-input :class="$style.newListInput" :value="newListName" :placeholder="$t('lists__new_list_input')" @keyup.enter="handleSaveList($event)" @blur="handleSaveList($event)" />
|
||||
</base-btn>
|
||||
<span v-for="i in spaceNum" :key="i" :class="$style.btn" />
|
||||
</div>
|
||||
@@ -170,7 +170,7 @@ export default {
|
||||
handleSaveList(event) {
|
||||
let name = event.target.value
|
||||
this.newListName = event.target.value = ''
|
||||
this.isEditing = false
|
||||
// this.isEditing = false
|
||||
if (!name) return
|
||||
createUserList({ name })
|
||||
},
|
||||
@@ -256,16 +256,14 @@ export default {
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: 34px;
|
||||
border: none;
|
||||
padding: 0;
|
||||
line-height: 34px;
|
||||
background: none;
|
||||
outline: none;
|
||||
background: none !important;
|
||||
font-size: 14px;
|
||||
text-align: center;
|
||||
font-family: inherit;
|
||||
box-sizing: border-box;
|
||||
padding: 0 10px;
|
||||
border-radius: 0;
|
||||
display: none;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xlink="http://www.w3.org/1999/xlink" viewBox="0 0 42 42" space="preserve">
|
||||
<use xlink:href="#icon-addTo" />
|
||||
</svg>
|
||||
<input :class="$style.newListInput" :value="newListName" type="text" :placeholder="$t('lists__new_list_input')" @keyup.enter="handleSaveList($event)" @blur="handleSaveList($event)">
|
||||
<base-input :class="$style.newListInput" :value="newListName" :placeholder="$t('lists__new_list_input')" @keyup.enter="handleSaveList($event)" @blur="handleSaveList($event)" />
|
||||
</base-btn>
|
||||
<span v-for="i in spaceNum" :key="i" :class="$style.btn" />
|
||||
</div>
|
||||
@@ -213,16 +213,13 @@ export default {
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: 34px;
|
||||
border: none;
|
||||
padding: 0;
|
||||
line-height: 34px;
|
||||
background: none;
|
||||
outline: none;
|
||||
background: none !important;
|
||||
font-size: 14px;
|
||||
text-align: center;
|
||||
font-family: inherit;
|
||||
box-sizing: border-box;
|
||||
padding: 0 10px;
|
||||
border-radius: 0;
|
||||
display: none;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
@input="$emit('update:modelValue', text)"
|
||||
@change="sendEvent('change')"
|
||||
@keyup.enter="handleSearch"
|
||||
@keydown.arrow-down.arrow-up.prevent
|
||||
@keyup.arrow-down.prevent="handleKeyDown"
|
||||
@keyup.arrow-up.prevent="handleKeyUp"
|
||||
@contextmenu="handleContextMenu"
|
||||
|
||||
Reference in New Issue
Block a user