Vanessa 2025-04-18 01:06:21 +08:00
parent fc558107cf
commit a003837e88
3 changed files with 14 additions and 8 deletions

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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);