Skip to content

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

:bug: Initialize current block when converting text selection https://github.com/siyuan-note/siyuan/issues/19557

Danielc8dc2e50f0c5
diff --git a/app/src/protyle/util/selection.ts b/app/src/protyle/util/selection.ts
index e50937c4a2..53ea167ad4 100644
--- a/app/src/protyle/util/selection.ts
+++ b/app/src/protyle/util/selection.ts
@@ -28,7 +28,7 @@ import {
getSemanticMarkerPrefixLengthForNode,
stripSemanticMarkersFromRangeText
} from "./inlineElementMarker";
-import {getSelectAllBlockAction} from "../wysiwyg/blockSelection";
+import {getSelectAllBlockAction, setBlockSelectionModeElement} from "../wysiwyg/blockSelection";
const selectIsEditor = (editor: Element, range?: Range) => {
if (!range) {
@@ -175,6 +175,10 @@ export const selectBlocksByRange = (protyle: IProtyle, range: Range) => {
item.classList.remove("protyle-wysiwyg--select");
});
});
+ // 将选区末端所属的已选块设为当前块,使转换后的选择支持块模式按键。
+ const currentElement = selectElements.find(item => item.contains(range.endContainer)) ||
+ selectElements[selectElements.length - 1];
+ setBlockSelectionModeElement(protyle.wysiwyg.element, currentElement);
range.collapse(false);
countBlockWord(selectElements.map(item => item.getAttribute("data-node-id")), protyle);
};