siyuan-note / siyuan

A privacy-first, self-hosted, fully open source personal knowledge management software, written in typescript and golang.
https://b3log.org/siyuan
GNU Affero General Public License v3.0
18.39k stars 1.37k forks source link

建议给 showTooltip() 增加一个参数,不同的地方调用时传入不同的类名 #11440

Open TCOTC opened 4 months ago

TCOTC commented 4 months ago

In what scenarios do you need this feature?

https://github.com/siyuan-note/siyuan/blob/61a89f6c46245849035bc10afa17f2f539c7aa57/app/src/dialog/tooltip.ts#L3

使用户可以按需隐藏 Tooltip ,而不是 .tooltip { display: none; } 就全没了

image

Describe the optimal solution

建议给 showTooltip() 增加一个参数,不同的地方调用时传入不同的类名(可以传入一个或多个类名)

Describe the candidate solution

No response

Other information

关联 https://ld246.com/article/1715925792926

Vanessa219 commented 4 months ago

也许这个可以解决问题 https://github.com/siyuan-note/siyuan/issues/11109

TCOTC commented 4 months ago

不一样,那个是右上角的消息弹窗,用的是 showMessage() ;这个 showTooltip() 是悬浮提示:

image

TCOTC commented 4 months ago

https://ld246.com/article/1715069193698

image

Vanessa219 commented 4 months ago

悬浮提示传入不同类名的作用是? 文章已在社区回复。

TCOTC commented 4 months ago

悬浮提示传入不同类名的作用是?

举个例子,比如鼠标悬浮在超链接上的时候,会使用 showTooltip(decodeURIComponent(tip), aElement); ,此时如果能传入一个 .tooltip--url 的类名,就可以用下面这个 CSS 把除了超链接以外的悬浮提示隐藏掉:

.tooltip:not(.tooltip--url) {
    display: none;
}

而且不只是超链接,用户会需要自定义其他各种地方的悬浮提示。

这样的话虽然在 tooltip.ts 里加一堆像下面这种条件判断也不是不行,但条件判断越多效率就越低,所以我建议直接从调用 showTooltip() 的地方把类名传进来

https://github.com/siyuan-note/siyuan/blob/61a89f6c46245849035bc10afa17f2f539c7aa57/app/src/dialog/tooltip.ts#L24-L28

从调用 showTooltip() 的地方传入类名后,在 tooltip.ts 里大概像这样处理:(不知道这段代码逻辑对不对哈)

if (toolTipClass !== "") {
    messageElement.classList.add(toolTipClass);
} else {
    // 获取所有其他的类名
    const otherClasses = Array.from(messageElement.classList).filter(className => className !== 'tooltip');
    // 移除所有其他的类名
    otherClasses.forEach(className => messageElement.classList.remove(className));
}
Vanessa219 commented 3 months ago

单独增加参数可能还不够,需要去对每一项有提示的地方进行配置。

TCOTC commented 3 months ago

单独增加参数可能还不够,需要去对每一项有提示的地方进行配置。

默认不需要参数,需要加的时候再加就可以了。

p.s. 先把链接(和备注)的加上,有个用户的需求是隐藏除了链接和备注以外的悬浮提示

Vanessa219 commented 3 months ago

加的时候也需要去配置,否则用法太隐秘了,没人知道这个特性。 后期维护也会很麻烦,比如增加一个类型,是不是需要去更新插件,插件不维护了怎么办?

TCOTC commented 3 months ago

我感觉这个更容易维护,否则每增加一个类名就要像下面的代码这样写一种判断。

与其弄一堆 if else ,不如直接在调用函数的时候传入类名。

另外这个跟插件维不维护好像没什么关系?增加类型之后插件按需使用已有的类型就好了(如果不需要的话就用不着新增了)

https://github.com/siyuan-note/siyuan/blob/61a89f6c46245849035bc10afa17f2f539c7aa57/app/src/dialog/tooltip.ts#L24-L28

TCOTC commented 3 months ago

想了想,传入类名之前也要判断,具体怎么实现还是要研究一下调用 showTooltip() 的相关代码。

这个需求也没那么迫切,暂时放着好了,等我有空研究一下再说。