Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Consolidate tooltip hover checks while preserving errors https://github.com/siyuan-note/siyuan/issues/20517

Liang Ding4c8203bed9e3
diff --git a/app/src/dialog/tooltip.ts b/app/src/dialog/tooltip.ts
index cbf05d45e7..3701b7bc9c 100644
--- a/app/src/dialog/tooltip.ts
+++ b/app/src/dialog/tooltip.ts
@@ -50,7 +50,8 @@ export const showTooltip = (
if (isMobile() || !message) {
return;
}
- if (isTouchHoverInput() && event && tooltipClass !== "error") {
+ const isHoverTooltip = !!event && tooltipClass !== "error";
+ if (isTouchHoverInput() && isHoverTooltip) {
const content = document.createElement("div");
content.innerHTML = window.DOMPurify.sanitize(message);
if (!content.querySelector(INTERACTIVE_TOOLTIP_SELECTOR)) {
@@ -99,7 +100,7 @@ export const showTooltip = (
messageElement.innerHTML = window.DOMPurify.sanitize(message);
const interactive = Boolean(messageElement.querySelector(INTERACTIVE_TOOLTIP_SELECTOR));
messageElement.classList.toggle("tooltip--interactive", interactive);
- messageElement.classList.toggle("tooltip--hover", !!event && tooltipClass !== "error" && !interactive);
+ messageElement.classList.toggle("tooltip--hover", isHoverTooltip && !interactive);
// 避免原本的 top 和 left 影响计算
messageElement.removeAttribute("style");
// 普通提示不拦截目标点击,包含链接或控件的提示仍可交互。
diff --git a/app/src/dialog/tooltipInput.test.ts b/app/src/dialog/tooltipInput.test.ts
index 37f1aa928f..b31acb6045 100644
--- a/app/src/dialog/tooltipInput.test.ts
+++ b/app/src/dialog/tooltipInput.test.ts
@@ -114,6 +114,30 @@ body {margin:0}.file-tree {position:absolute;top:40px;left:40px;width:232px}
check.equal(tip.classList.contains("tooltip--interactive"), false, "plain content clears the interactive state");
touch("pointermove", "touch");
assertTouch();
+ for (const pointerType of ["touch", "mouse"]) {
+ touch("pointerover", pointerType);
+ for (const tooltipClass of [undefined, "memo", "error"]) {
+ for (const event of [undefined, new MouseEvent("mouseover")]) {
+ for (const interactive of [false, true]) {
+ tooltip.hideTooltip();
+ const showsBefore = pluginShows;
+ const message = interactive ? '<a href="#test">Interactive</a>' : "Plain";
+ const context = JSON.stringify({pointerType, tooltipClass, event: !!event, interactive});
+ tooltip.showTooltip(message, more, tooltipClass, event);
+ const suppressed = pointerType === "touch" && !!event && tooltipClass !== "error" && !interactive;
+ check.equal(pluginShows - showsBefore, suppressed ? 0 : 1, context);
+ check.equal(tip.classList.contains("fn__none"), suppressed, context);
+ if (!suppressed) {
+ check.equal(tip.innerHTML, message, context);
+ check.equal(tip.classList.contains("tooltip--error"), tooltipClass === "error", context);
+ check.equal(tip.classList.contains("tooltip--interactive"), interactive, context);
+ check.equal(tip.classList.contains("tooltip--hover"),
+ !!event && tooltipClass !== "error" && !interactive, context);
+ }
+ }
+ }
+ }
+ }
return "Touch hover input cases passed";
};