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/11577

Vanessaa5a9c1587422
diff --git a/app/src/protyle/wysiwyg/enter.ts b/app/src/protyle/wysiwyg/enter.ts
index 403c663812..4244b17ad1 100644
--- a/app/src/protyle/wysiwyg/enter.ts
+++ b/app/src/protyle/wysiwyg/enter.ts
@@ -296,7 +296,6 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtyle
const listEnter = (protyle: IProtyle, blockElement: HTMLElement, range: Range) => {
const listItemElement = blockElement.parentElement;
-
const editableElement = getContenteditableElement(blockElement);
if (// \n 是因为 https://github.com/siyuan-note/siyuan/issues/3846
["", "\n"].includes(editableElement.textContent) &&
@@ -451,6 +450,10 @@ const listEnter = (protyle: IProtyle, blockElement: HTMLElement, range: Range) =
!hasNextSibling(editableElement?.lastElementChild)) {
editableElement.insertAdjacentText("beforeend", "\n");
}
+ // img 后有文字,在 img 后换行
+ if (editableElement?.lastElementChild?.classList.contains("img") && !hasNextSibling(editableElement?.lastElementChild)) {
+ editableElement.insertAdjacentText("beforeend", Constants.ZWSP);
+ }
getContenteditableElement(newElement).appendChild(selectNode);
listItemElement.insertAdjacentElement("afterend", newElement);
if (listItemElement.getAttribute("data-subtype") === "o") {
diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts
index b06a9d5774..9641ca60af 100644
--- a/app/src/protyle/wysiwyg/index.ts
+++ b/app/src/protyle/wysiwyg/index.ts
@@ -2400,12 +2400,19 @@ export class WYSIWYG {
const imgElement = hasTopClosestByClassName(event.target, "img");
if (!event.shiftKey && !ctrlIsPressed && imgElement) {
imgElement.classList.add("img--select");
- range.setStartAfter(imgElement);
- range.collapse(true);
- focusByRange(range);
- // 需等待 range 更新再次进行渲染
- if (protyle.options.render.breadcrumb) {
- protyle.breadcrumb.render(protyle);
+ const nextSibling = hasNextSibling(imgElement)
+ if (nextSibling) {
+ if (nextSibling.textContent.startsWith(Constants.ZWSP)) {
+ range.setStart(nextSibling, 1);
+ } else {
+ range.setStart(nextSibling, 0);
+ }
+ range.collapse(true);
+ focusByRange(range);
+ // 需等待 range 更新再次进行渲染
+ if (protyle.options.render.breadcrumb) {
+ protyle.breadcrumb.render(protyle);
+ }
}
return;
}