diff --git a/app/appearance/langs/en_US.json b/app/appearance/langs/en_US.json index 4dd57d922..ebcfb9cc1 100644 --- a/app/appearance/langs/en_US.json +++ b/app/appearance/langs/en_US.json @@ -1,4 +1,5 @@ { + "emptyPlaceholder": "Write something, ' / ' for commands", "publish": "Publish", "publishService": "Publish service", "publishServiceNotStarted": "Publish Service Not Started", diff --git a/app/appearance/langs/es_ES.json b/app/appearance/langs/es_ES.json index 1b173ed21..6df21954b 100644 --- a/app/appearance/langs/es_ES.json +++ b/app/appearance/langs/es_ES.json @@ -1,4 +1,5 @@ { + "emptyPlaceholder": "Escribe algo, ' / ' para los comandos", "publish": "Publicar", "publishService": "Publicar servicio", "publishServiceNotStarted": "Servicio de publicación no iniciado", diff --git a/app/appearance/langs/fr_FR.json b/app/appearance/langs/fr_FR.json index 8e1213085..06152dd98 100644 --- a/app/appearance/langs/fr_FR.json +++ b/app/appearance/langs/fr_FR.json @@ -1,4 +1,5 @@ { + "emptyPlaceholder": "Écrivez quelque chose, ' / ' pour les commandes", "publish": "Publier", "publishService": "Publier le service", "publishServiceNotStarted": "Service de publication non démarré", diff --git a/app/appearance/langs/ja_JP.json b/app/appearance/langs/ja_JP.json index fe21964c6..5df286c76 100644 --- a/app/appearance/langs/ja_JP.json +++ b/app/appearance/langs/ja_JP.json @@ -1,4 +1,5 @@ { + "emptyPlaceholder": "何か書いてください。コマンドの場合は「/」", "publish": "公開する", "publishService": "サービスを公開", "publishServiceNotStarted": "サービスが開始されていません", diff --git a/app/appearance/langs/zh_CHT.json b/app/appearance/langs/zh_CHT.json index 3b3d32d9c..a2a875158 100644 --- a/app/appearance/langs/zh_CHT.json +++ b/app/appearance/langs/zh_CHT.json @@ -1,4 +1,5 @@ { + "emptyPlaceholder": "寫點什麼,或按下 ' / ' 查看指令", "publish": "發布", "publishService": "發布服務", "publishServiceNotStarted": "發布服務未啟動", diff --git a/app/appearance/langs/zh_CN.json b/app/appearance/langs/zh_CN.json index 7229fdcec..15f29f225 100644 --- a/app/appearance/langs/zh_CN.json +++ b/app/appearance/langs/zh_CN.json @@ -1,4 +1,5 @@ { + "emptyPlaceholder": "写点什么,或按下 ' / ' 查看命令", "publish": "发布", "publishService": "发布服务", "publishServiceNotStarted": "发布服务未启动", diff --git a/app/src/assets/scss/mobile.scss b/app/src/assets/scss/mobile.scss index b71ffac0b..f5aa28348 100644 --- a/app/src/assets/scss/mobile.scss +++ b/app/src/assets/scss/mobile.scss @@ -475,15 +475,6 @@ } } -html .protyle-wysiwyg [data-node-id]:last-child [spellcheck][contenteditable="true"]:empty:before { - content: "Enter text"; - color: var(--b3-empty-color); -} - -html[lang="zh_CN"] .protyle-wysiwyg [data-node-id]:last-child [spellcheck][contenteditable="true"]:empty:before { - content: "键入文字"; -} - .av__views .block__icon { opacity: 1; } diff --git a/app/src/assets/scss/protyle/_wysiwyg.scss b/app/src/assets/scss/protyle/_wysiwyg.scss index 6edde22c5..23ddc8823 100644 --- a/app/src/assets/scss/protyle/_wysiwyg.scss +++ b/app/src/assets/scss/protyle/_wysiwyg.scss @@ -5,6 +5,11 @@ user-select: auto; overflow-x: clip; + &--empty:empty:before { + color: var(--b3-empty-color); + content: attr(placeholder); + } + .protyle-breadcrumb__bar { font-size: 14px; } diff --git a/app/src/protyle/header/Title.ts b/app/src/protyle/header/Title.ts index 47f516be3..3d56de7ac 100644 --- a/app/src/protyle/header/Title.ts +++ b/app/src/protyle/header/Title.ts @@ -16,7 +16,7 @@ import {isMac, readText, writeText} from "../util/compatibility"; import * as dayjs from "dayjs"; import {openFileById} from "../../editor/util"; import {setTitle} from "../../dialog/processSystem"; -import {getNoContainerElement} from "../wysiwyg/getBlock"; +import {getContenteditableElement, getNoContainerElement} from "../wysiwyg/getBlock"; import {commonHotkey} from "../wysiwyg/commonHotkey"; import {code160to32} from "../util/code160to32"; import {genEmptyElement} from "../../block/util"; @@ -115,19 +115,25 @@ export class Title { event.stopPropagation(); } } else if (event.key === "Enter") { - const newId = Lute.NewNodeID(); - const newElement = genEmptyElement(false, true, newId); - protyle.wysiwyg.element.insertAdjacentElement("afterbegin", newElement); - focusByWbr(newElement, protyle.toolbar.range || getEditorRange(newElement)); - transaction(protyle, [{ - action: "insert", - data: newElement.outerHTML, - id: newId, - parentID: protyle.block.parentID - }], [{ - action: "delete", - id: newId, - }]); + const editElment = getContenteditableElement(protyle.wysiwyg.element.firstElementChild) + if (editElment && editElment.textContent === "") { + // 配合提示文本使用,避免提示文本挤压到第二个块中 + focusBlock(protyle.wysiwyg.element.firstElementChild, protyle.wysiwyg.element); + } else { + const newId = Lute.NewNodeID(); + const newElement = genEmptyElement(false, true, newId); + protyle.wysiwyg.element.insertAdjacentElement("afterbegin", newElement); + focusByWbr(newElement, protyle.toolbar.range || getEditorRange(newElement)); + transaction(protyle, [{ + action: "insert", + data: newElement.outerHTML, + id: newId, + parentID: protyle.block.parentID + }], [{ + action: "delete", + id: newId, + }]); + } event.preventDefault(); event.stopPropagation(); } else if (matchHotKey(window.siyuan.config.keymap.editor.general.attr.custom, event)) { diff --git a/app/src/protyle/util/onGet.ts b/app/src/protyle/util/onGet.ts index 6bcee1029..38918ef2b 100644 --- a/app/src/protyle/util/onGet.ts +++ b/app/src/protyle/util/onGet.ts @@ -19,6 +19,7 @@ import {avRender} from "../render/av/render"; import {hideTooltip} from "../../dialog/tooltip"; import {stickyRow} from "../render/av/row"; import {updateReadonly as updateReadonlyMethod} from "../breadcrumb/action"; +import {getContenteditableElement} from "../wysiwyg/getBlock"; export const onGet = (options: { data: IWebSocketData, @@ -180,6 +181,15 @@ const setHTML = (options: { } else { protyle.wysiwyg.element.innerHTML = options.content; } + // https://github.com/siyuan-note/siyuan/issues/10528 + if (!protyle.block.showAll && protyle.wysiwyg.element.childElementCount === 1 && protyle.wysiwyg.element.firstElementChild.classList.contains("p")) { + const editElement = getContenteditableElement(protyle.wysiwyg.element.firstElementChild); + if (editElement && editElement.textContent === "") { + editElement.classList.add("protyle-wysiwyg--empty"); + editElement.setAttribute("placeholder", window.siyuan.languages.emptyPlaceholder); + } + } + if (options.action.includes(Constants.CB_GET_BACKLINK)) { foldPassiveType(options.expand, protyle.wysiwyg.element); }