fix: Left click to copy incomplete content (#2419)
This commit is contained in:
parent
66164e6cde
commit
f65bfbe83c
@ -17,27 +17,41 @@ import { ref, nextTick, onMounted } from 'vue'
|
|||||||
import { t } from '@/locales'
|
import { t } from '@/locales'
|
||||||
const isOpen = ref<boolean>(false)
|
const isOpen = ref<boolean>(false)
|
||||||
const eventVal = ref<any>({})
|
const eventVal = ref<any>({})
|
||||||
|
|
||||||
function getSelection() {
|
function getSelection() {
|
||||||
const selection = window.getSelection()
|
const selection = window.getSelection()
|
||||||
if (selection && selection.anchorNode == null) {
|
if (selection) {
|
||||||
return null
|
if (selection.rangeCount === 0) return undefined
|
||||||
|
const range = selection.getRangeAt(0)
|
||||||
|
const fragment = range.cloneContents() // 克隆选区内容
|
||||||
|
const div = document.createElement('div')
|
||||||
|
div.appendChild(fragment)
|
||||||
|
if (div.textContent) {
|
||||||
|
return div.textContent.trim()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const text = selection?.anchorNode?.textContent
|
return undefined
|
||||||
return text && text.substring(selection.anchorOffset, selection.focusOffset)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 打开控制台
|
* 打开控制台
|
||||||
* @param event
|
* @param event
|
||||||
*/
|
*/
|
||||||
const openControl = (event: any) => {
|
const openControl = (event: any) => {
|
||||||
const c = getSelection()
|
const c = getSelection()
|
||||||
isOpen.value = false
|
|
||||||
if (c) {
|
if (c) {
|
||||||
nextTick(() => {
|
if (!isOpen.value) {
|
||||||
eventVal.value = event
|
nextTick(() => {
|
||||||
isOpen.value = true
|
eventVal.value = event
|
||||||
})
|
isOpen.value = true
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
clearSelectedText()
|
||||||
|
isOpen.value = false
|
||||||
|
}
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
|
} else {
|
||||||
|
isOpen.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user