mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-18 15:40:12 +01:00
This commit is contained in:
parent
d11ed21f06
commit
4fe40c9fd5
2 changed files with 17 additions and 10 deletions
|
|
@ -132,10 +132,10 @@ export const initBlockPopover = (app: App) => {
|
||||||
if (tip && !aElement.classList.contains("b3-tooltips")) {
|
if (tip && !aElement.classList.contains("b3-tooltips")) {
|
||||||
// https://github.com/siyuan-note/siyuan/issues/11294
|
// https://github.com/siyuan-note/siyuan/issues/11294
|
||||||
try {
|
try {
|
||||||
showTooltip(decodeURIComponent(tip), aElement, tooltipClass);
|
showTooltip(decodeURIComponent(tip), aElement, tooltipClass, event);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// https://ld246.com/article/1718235737991
|
// https://ld246.com/article/1718235737991
|
||||||
showTooltip(tip, aElement, tooltipClass);
|
showTooltip(tip, aElement, tooltipClass, event);
|
||||||
}
|
}
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,19 @@
|
||||||
import {isMobile} from "../util/functions";
|
import {isMobile} from "../util/functions";
|
||||||
|
|
||||||
export const showTooltip = (message: string, target: Element, tooltipClass?: string) => {
|
export const showTooltip = (message: string, target: Element, tooltipClass?: string, event?: MouseEvent) => {
|
||||||
if (isMobile()) {
|
if (isMobile()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let targetRect = target.getBoundingClientRect();
|
let targetRect = target.getBoundingClientRect();
|
||||||
if (target.getAttribute("data-inline-memo-content") && target.getClientRects().length > 1) {
|
if (target.getAttribute("data-inline-memo-content") && target.getClientRects().length > 1) {
|
||||||
let lastWidth = 0;
|
let lastWidth = 0;
|
||||||
|
if (event) {
|
||||||
|
Array.from(target.getClientRects()).forEach(item => {
|
||||||
|
if (event.clientY >= item.top - 3 && event.clientY <= item.bottom) {
|
||||||
|
targetRect = item;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
Array.from(target.getClientRects()).forEach(item => {
|
Array.from(target.getClientRects()).forEach(item => {
|
||||||
if (item.width > lastWidth) {
|
if (item.width > lastWidth) {
|
||||||
targetRect = item;
|
targetRect = item;
|
||||||
|
|
@ -14,6 +21,7 @@ export const showTooltip = (message: string, target: Element, tooltipClass?: str
|
||||||
lastWidth = item.width;
|
lastWidth = item.width;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (targetRect.height === 0 || !message) {
|
if (targetRect.height === 0 || !message) {
|
||||||
hideTooltip();
|
hideTooltip();
|
||||||
return;
|
return;
|
||||||
|
|
@ -25,7 +33,6 @@ export const showTooltip = (message: string, target: Element, tooltipClass?: str
|
||||||
// 避免原本的 top 和 left 影响计算
|
// 避免原本的 top 和 left 影响计算
|
||||||
messageElement.removeAttribute("style");
|
messageElement.removeAttribute("style");
|
||||||
|
|
||||||
|
|
||||||
const position = target.getAttribute("data-position");
|
const position = target.getAttribute("data-position");
|
||||||
const parentRect = target.parentElement.getBoundingClientRect();
|
const parentRect = target.parentElement.getBoundingClientRect();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue