Improve the class name of showTooltip() (#12746)

This commit is contained in:
Jeffrey Chen 2024-10-11 11:45:24 +08:00 committed by GitHub
parent bc53babb85
commit 1139ffddc0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 23 additions and 14 deletions

View file

@ -25,7 +25,8 @@ export const initBlockPopover = (app: App) => {
hasClosestByClassName(event.target, "av__calc--ashow") ||
hasClosestByClassName(event.target, "av__cell");
if (aElement) {
let tip = aElement.getAttribute("aria-label") || aElement.getAttribute("data-inline-memo-content");
let tooltipClass = "";
let tip = aElement.getAttribute("aria-label");
if (aElement.classList.contains("av__cell")) {
if (aElement.classList.contains("av__cell--header")) {
const textElement = aElement.querySelector(".av__celltext");
@ -51,11 +52,18 @@ export const initBlockPopover = (app: App) => {
} else if (aElement.classList.contains("av__calc--ashow") && aElement.clientWidth + 2 < aElement.scrollWidth) {
tip = aElement.lastChild.textContent + " " + aElement.firstElementChild.textContent;
}
if (!tip) {
tip = aElement.getAttribute("data-inline-memo-content");
if (tip) {
tooltipClass = "memo"; // 为行级备注添加 class https://github.com/siyuan-note/siyuan/issues/6161
}
}
if (!tip) {
const href = aElement.getAttribute("data-href") || "";
// 链接地址强制换行 https://github.com/siyuan-note/siyuan/issues/11539
if (href) {
tip = `<span style="word-break: break-all">${href.substring(0, Constants.SIZE_TITLE)}</span>`;
tooltipClass = "href"; // 为超链接添加 class https://github.com/siyuan-note/siyuan/issues/11440#issuecomment-2119080691
}
const title = aElement.getAttribute("data-title");
if (tip && isLocalPath(href) && !aElement.classList.contains("b3-tooltips")) {
@ -78,10 +86,10 @@ export const initBlockPopover = (app: App) => {
if (tip && !aElement.classList.contains("b3-tooltips")) {
// https://github.com/siyuan-note/siyuan/issues/11294
try {
showTooltip(decodeURIComponent(tip), aElement);
showTooltip(decodeURIComponent(tip), aElement, tooltipClass);
} catch (e) {
// https://ld246.com/article/1718235737991
showTooltip(tip, aElement);
showTooltip(tip, aElement, tooltipClass);
}
event.stopPropagation();
} else {