Skip to content

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

:art: https://github.com/siyuan-note/siyuan/issues/14635

Vanessaa003837e8805
diff --git a/app/src/protyle/util/selection.ts b/app/src/protyle/util/selection.ts
index 9fedb55ed9..b05e0571b7 100644
--- a/app/src/protyle/util/selection.ts
+++ b/app/src/protyle/util/selection.ts
@@ -351,10 +351,6 @@ export const setLastNodeRange = (editElement: Element, range: Range, setStart =
}
let lastNode = editElement.lastChild as Element;
while (lastNode && lastNode.nodeType !== 3) {
- if (lastNode.nodeType !== 3 && lastNode.tagName === "BR") {
- // 防止单元格中 ⇧↓ 全部选中
- return range;
- }
// https://github.com/siyuan-note/siyuan/issues/12792
if (!lastNode.lastChild) {
break;
@@ -367,14 +363,14 @@ export const setLastNodeRange = (editElement: Element, range: Range, setStart =
lastNode = editElement;
}
if (setStart) {
- if (lastNode.nodeType !== 3 && lastNode.classList.contains("render-node") && lastNode.innerHTML === "") {
+ if (lastNode.nodeType !== 3 && (lastNode.classList.contains("render-node") || lastNode.tagName === "BR") && lastNode.innerHTML === "") {
range.setStartAfter(lastNode);
} else {
range.setStart(lastNode, lastNode.textContent.length);
}
} else {
- if (lastNode.nodeType !== 3 && lastNode.classList.contains("render-node") && lastNode.innerHTML === "") {
- range.setStartAfter(lastNode);
+ if (lastNode.nodeType !== 3 && (lastNode.classList.contains("render-node") || lastNode.tagName === "BR") && lastNode.innerHTML === "") {
+ range.setEndAfter(lastNode);
} else {
range.setEnd(lastNode, lastNode.textContent.length);
}
diff --git a/app/src/protyle/wysiwyg/commonHotkey.ts b/app/src/protyle/wysiwyg/commonHotkey.ts
index e538140d29..b8cd0d10d3 100644
--- a/app/src/protyle/wysiwyg/commonHotkey.ts
+++ b/app/src/protyle/wysiwyg/commonHotkey.ts
@@ -205,6 +205,9 @@ export const downSelect = (options: {
// 代码块中 shift+alt 向下选中到末尾时,最后一个字符无法选中
options.event.preventDefault();
}
+ } else if (tdElement) {
+ setLastNodeRange(tdElement, options.range, false);
+ options.event.preventDefault();
}
return;
}
diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts
index ac849f521d..5e01c180bd 100644
--- a/app/src/protyle/wysiwyg/index.ts
+++ b/app/src/protyle/wysiwyg/index.ts
@@ -1379,6 +1379,8 @@ export class WYSIWYG {
}).element);
}
window.siyuan.menus.menu.popup({x: mouseUpEvent.clientX - 8, y: mouseUpEvent.clientY - 16});
+ // 多选表格单元格后,选择菜单中的居左,然后 shift+左 选中的文字无法显示选中背景,因此需移除
+ protyle.wysiwyg.element.classList.remove("protyle-wysiwyg--hiderange");
}
}
@@ -1417,12 +1419,17 @@ export class WYSIWYG {
}
const startBlockElement = hasClosestBlock(range.startContainer);
let endBlockElement: false | HTMLElement;
- if (mouseUpEvent.detail > 2 && range.endContainer.nodeType !== 3 && (range.endContainer as HTMLElement).tagName === "DIV" && range.endOffset === 0) {
+ if (mouseUpEvent.detail > 2 && range.endContainer.nodeType !== 3 && ["DIV", "TD", "TH"].includes((range.endContainer as HTMLElement).tagName) && range.endOffset === 0) {
// 三击选中段落块时,rangeEnd 会在下一个块
if ((range.endContainer as HTMLElement).classList.contains("protyle-attr") && startBlockElement) {
// 三击在悬浮层中会选择到 attr https://github.com/siyuan-note/siyuan/issues/4636
// 需要获取可编辑元素,使用 previousElementSibling 的话会 https://github.com/siyuan-note/siyuan/issues/9714
setLastNodeRange(getContenteditableElement(startBlockElement), range, false);
+ } else if (["TD", "TH"].includes((range.endContainer as HTMLElement).tagName)) {
+ const cellElement = hasClosestByTag(range.startContainer, "TH") || hasClosestByTag(range.startContainer, "TD")
+ if (cellElement) {
+ setLastNodeRange(cellElement, range, false);
+ }
}
} else {
endBlockElement = hasClosestBlock(range.endContainer);