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

Vanessa38673b2b7de1
diff --git a/app/src/protyle/util/selection.ts b/app/src/protyle/util/selection.ts
index 925dab49b8..09a768b362 100644
--- a/app/src/protyle/util/selection.ts
+++ b/app/src/protyle/util/selection.ts
@@ -308,10 +308,14 @@ export const setLastNodeRange = (editElement: Element, range: Range, setStart =
if (!editElement) {
return range;
}
- let lastNode = editElement.lastChild;
+ let lastNode = editElement.lastChild as Element;
while (lastNode && lastNode.nodeType !== 3) {
+ if (lastNode.nodeType !== 3 && lastNode.tagName === "BR") {
+ // 防止单元格中 ⇧↓ 全部选中
+ return range;
+ }
// 最后一个为多种行内元素嵌套
- lastNode = lastNode.lastChild;
+ lastNode = lastNode.lastChild as Element;
}
if (!lastNode) {
range.selectNodeContents(editElement);
diff --git a/app/src/protyle/wysiwyg/commonHotkey.ts b/app/src/protyle/wysiwyg/commonHotkey.ts
index 7b1dee5053..1a519daa1b 100644
--- a/app/src/protyle/wysiwyg/commonHotkey.ts
+++ b/app/src/protyle/wysiwyg/commonHotkey.ts
@@ -4,7 +4,7 @@ import {isMac, writeText} from "../util/compatibility";
import {
focusBlock,
getSelectionOffset,
- setFirstNodeRange,
+ setFirstNodeRange, setLastNodeRange,
} from "../util/selection";
import {getContenteditableElement, hasNextSibling, hasPreviousSibling} from "./getBlock";
import {hasClosestByMatchTag} from "../util/hasClosest";
@@ -95,21 +95,19 @@ export const upSelect = (options: {
options.event.stopPropagation();
options.event.preventDefault();
} else {
- if (isMac() // Windows 中 ⌥⇧↓ 默认无选中功能会导致 https://ld246.com/article/1716635371149
- && getSelectionOffset(options.nodeElement, options.editorElement, options.range).start !== 0) {
- const editElement = getContenteditableElement(options.nodeElement);
- if (editElement.tagName === "TABLE") {
- const cellElement = hasClosestByMatchTag(options.range.startContainer, "TH") || hasClosestByMatchTag(options.range.startContainer, "TD") || editElement.querySelector("th, td");
- if (getSelectionOffset(cellElement, cellElement, options.range).start !== 0) {
- setFirstNodeRange(cellElement, options.range);
- options.event.stopPropagation();
- options.event.preventDefault();
- return;
- }
- } else {
- // 选中上一个节点的处理在 toolbar/index.ts 中 `shift+方向键或三击选中`
- return;
+ const tdElement = hasClosestByMatchTag(options.range.startContainer, "TD") || hasClosestByMatchTag(options.range.startContainer, "TH");
+ const nodeEditableElement = (tdElement || getContenteditableElement(options.nodeElement) || options.nodeElement) as HTMLElement;
+ const startIndex = getSelectionOffset(nodeEditableElement, options.editorElement, options.range).start
+ const innerText = nodeEditableElement.innerText;
+ const isExpandUp = matchHotKey(window.siyuan.config.keymap.editor.general.expandUp.custom, options.event)
+ if (!isMac() && isExpandUp) {
+ // Windows 中 ⌥⇧↑ 默认无选中功能会导致 https://ld246.com/article/1716635371149
+ } else if (startIndex > 0) {
+ // 选中上一个节点的处理在 toolbar/index.ts 中 `shift+方向键或三击选中`
+ if (innerText.substr(0, startIndex).indexOf("\n") === -1) {
+ setFirstNodeRange(nodeEditableElement, options.range);
}
+ return;
}
}
options.range.collapse(true);
@@ -141,9 +139,22 @@ export const downSelect = (options: {
options.event.stopPropagation();
options.event.preventDefault();
} else {
- if (isMac() // Windows 中 ⌥⇧↑ 默认无选中功能会导致 https://ld246.com/article/1716635371149
- && getSelectionOffset(options.nodeElement, options.editorElement, options.range).end < getContenteditableElement(options.nodeElement).textContent.length) {
+ const tdElement = hasClosestByMatchTag(options.range.startContainer, "TD") || hasClosestByMatchTag(options.range.startContainer, "TH");
+ const nodeEditableElement = (tdElement || getContenteditableElement(options.nodeElement) || options.nodeElement) as HTMLElement;
+ const endIndex = getSelectionOffset(nodeEditableElement, options.editorElement, options.range).end
+ const innerText = nodeEditableElement.innerText;
+ const isExpandDown = matchHotKey(window.siyuan.config.keymap.editor.general.expandDown.custom, options.event)
+ if (!isMac() && isExpandDown) {
+ // Windows 中 ⌥⇧↓ 默认无选中功能会导致 https://ld246.com/article/1716635371149
+ } else if (endIndex < innerText.length) {
// 选中下一个节点的处理在 toolbar/index.ts 中 `shift+方向键或三击选中`
+ if (!options.nodeElement.nextElementSibling && innerText.trimRight().substr(endIndex).indexOf("\n") === -1) {
+ // 当为最后一个块时应选中末尾
+ setLastNodeRange(nodeEditableElement, options.range, false);
+ if (options.nodeElement.classList.contains("code-block") && isExpandDown) {
+ options.event.preventDefault();
+ }
+ }
return;
}
}