Skip to content

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

:art: fix https://github.com/siyuan-note/siyuan/issues/6516

Vanessa7ba98f2ee07b
diff --git a/app/src/assets/scss/_tooltips.scss b/app/src/assets/scss/_tooltips.scss
index 9742f6b6ac..14e106c67f 100644
--- a/app/src/assets/scss/_tooltips.scss
+++ b/app/src/assets/scss/_tooltips.scss
@@ -15,6 +15,10 @@
animation-duration: 150ms;
animation-fill-mode: both;
animation-name: zoomIn;
+
+ &--error {
+ background: var(--b3-theme-error);
+ }
}
.b3-tooltips {
diff --git a/app/src/dialog/tooltip.ts b/app/src/dialog/tooltip.ts
index 7af933c8a8..3ace549938 100644
--- a/app/src/dialog/tooltip.ts
+++ b/app/src/dialog/tooltip.ts
@@ -1,7 +1,7 @@
import {setPosition} from "../util/setPosition";
import {isMobile} from "../util/functions";
-export const showTooltip = (message: string, target: Element) => {
+export const showTooltip = (message: string, target: Element, error = false) => {
if (isMobile()) {
return;
}
@@ -17,7 +17,12 @@ export const showTooltip = (message: string, target: Element) => {
} else {
messageElement.innerHTML = message;
}
- if(target.getAttribute("data-inline-memo-content")) {
+ if (error) {
+ messageElement.classList.add("tooltip--error");
+ } else {
+ messageElement.classList.remove("tooltip--error");
+ }
+ if (target.getAttribute("data-inline-memo-content")) {
messageElement.classList.add("tooltip--memo"); // 为行级备注添加 class https://github.com/siyuan-note/siyuan/issues/6161
}
let left = targetRect.left;
diff --git a/app/src/editor/rename.ts b/app/src/editor/rename.ts
index 490259b4cf..d2b95e149a 100644
--- a/app/src/editor/rename.ts
+++ b/app/src/editor/rename.ts
@@ -9,14 +9,23 @@ import {getAssetName, getDisplayName, pathPosix, setNotebookName} from "../util/
import {fetchPost} from "../util/fetch";
import {escapeHtml} from "../util/escape";
import {Constants} from "../constants";
+import {showTooltip} from "../dialog/tooltip";
-export const validateName = (name: string) => {
+export const validateName = (name: string, targetElement?: HTMLElement) => {
if (/\r\n|\r|\n|\u2028|\u2029|\t|\//.test(name)) {
- showMessage(window.siyuan.languages.fileNameRule);
+ if (targetElement) {
+ showTooltip(window.siyuan.languages.fileNameRule, targetElement, true);
+ } else {
+ showMessage(window.siyuan.languages.fileNameRule);
+ }
return false;
}
if (name.length > Constants.SIZE_TITLE) {
- showMessage(window.siyuan.languages["_kernel"]["106"]);
+ if (targetElement) {
+ showTooltip(window.siyuan.languages["_kernel"]["106"], targetElement, true);
+ } else {
+ showMessage(window.siyuan.languages["_kernel"]["106"]);
+ }
return false;
}
return true;
diff --git a/app/src/protyle/header/Title.ts b/app/src/protyle/header/Title.ts
index 32bae06ce6..139a6121dd 100644
--- a/app/src/protyle/header/Title.ts
+++ b/app/src/protyle/header/Title.ts
@@ -28,6 +28,7 @@ import {code160to32} from "../util/code160to32";
import {deleteFile} from "../../editor/deleteFile";
import {genEmptyElement} from "../../block/util";
import {transaction} from "../wysiwyg/transaction";
+import {hideTooltip} from "../../dialog/tooltip";
export class Title {
public element: HTMLElement;
@@ -41,7 +42,7 @@ export class Title {
this.element.classList.add("protyle-wysiwyg--attr");
}
this.element.innerHTML = `<span aria-label="${window.siyuan.languages.gutterTip2}" class="protyle-title__icon" data-type="a" data-position="right"><svg><use xlink:href="#iconFile"></use></svg></span>
-<div contenteditable="true" spellcheck="false" class="protyle-title__input" data-tip="${window.siyuan.languages._kernel[16]}"></div><div class="protyle-attr"></div>`;
+<div contenteditable="true" data-position="center" spellcheck="false" class="protyle-title__input" data-tip="${window.siyuan.languages._kernel[16]}"></div><div class="protyle-attr"></div>`;
this.editElement = this.element.querySelector(".protyle-title__input");
this.editElement.addEventListener("paste", (event: ClipboardEvent) => {
event.stopPropagation();
@@ -251,13 +252,14 @@ export class Title {
private rename(protyle: IProtyle) {
clearTimeout(this.timeout);
- if (!validateName(this.editElement.textContent)) {
+ if (!validateName(this.editElement.textContent, this.editElement)) {
// 字数过长会导致滚动
const offset = getSelectionOffset(this.editElement);
this.setTitle(this.editElement.textContent.substring(0, Constants.SIZE_TITLE));
focusByOffset(this.editElement, offset.start, offset.end);
return false;
}
+ hideTooltip();
this.timeout = window.setTimeout(() => {
const fileName = replaceFileName(this.editElement.textContent);
fetchPost("/api/filetree/renameDoc", {