Skip to content

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

:children_crossing: https://github.com/siyuan-note/siyuan/issues/5955 2

Vanessa4e92981ec692
diff --git a/app/src/protyle/util/table.ts b/app/src/protyle/util/table.ts
index bed607e451..bc12ac4412 100644
--- a/app/src/protyle/util/table.ts
+++ b/app/src/protyle/util/table.ts
@@ -4,6 +4,7 @@ import {hasClosestBlock, hasClosestByMatchTag} from "./hasClosest";
import {matchHotKey} from "./hotKey";
import {isCtrl} from "./compatibility";
import {scrollCenter} from "../../util/highlightById";
+import {insertEmptyBlock} from "../../block/util";
export const getColIndex = (cellElement: HTMLElement) => {
let previousElement = cellElement.previousElementSibling;
@@ -337,7 +338,7 @@ export const fixTable = (protyle: IProtyle, event: KeyboardEvent, range: Range)
return true;
}
// enter 光标跳转到下一行同列
- if (!isCtrl(event) && !event.shiftKey && !event.altKey &&event.key === "Enter") {
+ if (!isCtrl(event) && !event.shiftKey && !event.altKey && event.key === "Enter") {
event.preventDefault();
const trElement = cellElement.parentElement as HTMLTableRowElement;
if ((!trElement.nextElementSibling && trElement.parentElement.tagName === "TBODY") ||
@@ -356,7 +357,15 @@ export const fixTable = (protyle: IProtyle, event: KeyboardEvent, range: Range)
scrollCenter(protyle);
return true;
}
-
+ // 表格后无内容时,按右键需新建空块
+ if (event.key === "ArrowRight" && range.toString() === "" &&
+ !nodeElement.nextElementSibling &&
+ cellElement.isSameNode(nodeElement.querySelector("table").lastElementChild.lastElementChild.lastElementChild) &&
+ getSelectionOffset(cellElement, protyle.wysiwyg.element, range).start === cellElement.textContent.length ) {
+ event.preventDefault();
+ insertEmptyBlock(protyle, "afterend", nodeElement.getAttribute("data-node-id"));
+ return true;
+ }
// tab:光标移向下一个 cell
if (event.key === "Tab" && !event.ctrlKey) {
if (event.shiftKey) {
@@ -393,7 +402,7 @@ export const fixTable = (protyle: IProtyle, event: KeyboardEvent, range: Range)
let previousBrElement;
if (startContainer.nodeType !== 3 && (startContainer.tagName === "TH" || startContainer.tagName === "TD")) {
previousBrElement = (startContainer.childNodes[Math.max(0, range.startOffset - 1)] as HTMLElement)?.previousElementSibling;
- } else if(startContainer.parentElement.tagName=== "SPAN") {
+ } else if (startContainer.parentElement.tagName === "SPAN") {
previousBrElement = startContainer.parentElement.previousElementSibling;
} else {
previousBrElement = startContainer.previousElementSibling;
@@ -424,7 +433,7 @@ export const fixTable = (protyle: IProtyle, event: KeyboardEvent, range: Range)
let nextBrElement;
if (endContainer.nodeType !== 3 && (endContainer.tagName === "TH" || endContainer.tagName === "TD")) {
nextBrElement = (endContainer.childNodes[Math.max(0, range.endOffset - 1)] as HTMLElement)?.nextElementSibling;
- } else if(endContainer.parentElement.tagName=== "SPAN") {
+ } else if (endContainer.parentElement.tagName === "SPAN") {
nextBrElement = endContainer.parentElement.nextElementSibling;
} else {
nextBrElement = endContainer.nextElementSibling;