Show default menu when right click on text (#5826)

Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
Kristina 2024-06-14 19:12:34 +04:00 committed by GitHub
parent 3090ae6032
commit 11904d4138
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 39 additions and 6 deletions

View File

@ -109,6 +109,7 @@ li {
p {
user-select: text;
cursor: auto;
a {
word-break: break-all;

View File

@ -359,6 +359,7 @@ table.proseTable {
border-radius: .25rem;
padding: .5rem;
user-select: text;
cursor: auto;
pre { white-space: pre-wrap; }
}

View File

@ -104,6 +104,42 @@
}
$: isShort = canDisplayShort(type, isSaved)
function isInside (x: number, y: number, rect: DOMRect): boolean {
return x >= rect.left && y >= rect.top && x <= rect.right && y <= rect.bottom
}
function isTextClicked (element: HTMLElement | null, x: number, y: number): boolean {
if (element == null) {
return false
}
const nodes = element.childNodes
const range = document.createRange()
for (let i = 0; i < nodes.length; i++) {
const node = nodes[i]
if (node.nodeType !== Node.TEXT_NODE) continue
range.selectNodeContents(node)
if (isInside(x, y, range.getBoundingClientRect())) {
return true
}
}
return false
}
function handleContextMenu (event: MouseEvent): void {
const showCustomPopup = !isTextClicked(event.target as HTMLElement, event.clientX, event.clientY)
if (showCustomPopup) {
showMenu(event, { object: message, baseMenuClass: activity.class.ActivityMessage }, () => {
isActionsOpened = false
})
isActionsOpened = true
}
}
</script>
{#if !isHidden}
@ -123,12 +159,7 @@
class:borderedHover={hoverStyles === 'borderedHover'}
class:filledHover={hoverStyles === 'filledHover'}
on:click={onClick}
on:contextmenu={(evt) => {
showMenu(evt, { object: message, baseMenuClass: activity.class.ActivityMessage }, () => {
isActionsOpened = false
})
isActionsOpened = true
}}
on:contextmenu={handleContextMenu}
>
{#if showNotify && !embedded && !isShort}
<div class="notify" />