Skip to content

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

:zap: Improve rich text input in table cells https://github.com/siyuan-note/siyuan/issues/20253

Daniel87f2ab105d62
diff --git a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-h361q1i/20200924093441-ft2rhps.sy b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-h361q1i/20200924093441-ft2rhps.sy
index bd90b98153..64fa373f72 100644
--- a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-h361q1i/20200924093441-ft2rhps.sy
+++ b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-h361q1i/20200924093441-ft2rhps.sy
@@ -8,7 +8,7 @@
"title": "Formatting elements",
"title-img": "background-color:#269;background-image: linear-gradient(white 2px, transparent 2px),linear-gradient(90deg, white 2px, transparent 2px),linear-gradient(rgba(255,255,255,.3) 1px, transparent 1px),linear-gradient(90deg, rgba(255,255,255,.3) 1px, transparent 1px);background-size: 100px 100px, 100px 100px, 20px 20px, 20px 20px;background-position:-2px -2px, -2px -2px, -1px -1px, -1px -1px;",
"type": "doc",
- "updated": "20261003234156"
+ "updated": "20261008221006"
},
"Children": [
{
@@ -3801,7 +3801,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20210104091509-qr9enpx",
- "updated": "20260910080119"
+ "updated": "20261008221006"
},
"Children": [
{
@@ -3829,12 +3829,12 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20260908091355-rch0008",
- "updated": "20260910080119"
+ "updated": "20261008221006"
},
"Children": [
{
"Type": "NodeText",
- "Data": "Click a cell to edit it. After creating a table, type directly without clicking again. When the cell contains only one ordinary paragraph, "
+ "Data": "Click a cell to edit it. After creating a table, type directly without clicking again. "
},
{
"Type": "NodeTextMark",
@@ -3843,7 +3843,16 @@
},
{
"Type": "NodeText",
- "Data": " moves to the same column in the next row, or inserts a paragraph after the table when on the last row. "
+ "Data": " creates a new paragraph, continues a list item, or inserts a line break in code according to the normal editor rules. "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "Shift+Enter"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " inserts a soft line break within a paragraph. "
},
{
"Type": "NodeTextMark",
@@ -3852,16 +3861,16 @@
},
{
"Type": "NodeText",
- "Data": " switches cells, and "
+ "Data": " and "
},
{
"Type": "NodeTextMark",
"TextMarkType": "kbd",
- "TextMarkTextContent": "Shift+Enter"
+ "TextMarkTextContent": "Shift+Tab"
},
{
"Type": "NodeText",
- "Data": " inserts a line break within the cell. With headings, multiple paragraphs, or other block content, Enter edits within the cell according to the current content type. Lists and code blocks use their own line-break and indentation behavior. Close suggestions, then press "
+ "Data": " switch cells; lists and code blocks retain their indentation and outdent behavior. Close suggestions, then press "
},
{
"Type": "NodeTextMark",
@@ -3870,7 +3879,7 @@
},
{
"Type": "NodeText",
- "Data": " or click outside the cell to finish editing and save automatically."
+ "Data": " or click outside the cell to finish editing and save automatically. Copying a table as plain text preserves blank lines between paragraphs within a cell."
}
]
},
diff --git a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100950-9op5xi1.sy b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100950-9op5xi1.sy
index 17b1c4321b..3383170ffc 100644
--- a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100950-9op5xi1.sy
+++ b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100950-9op5xi1.sy
@@ -7,7 +7,7 @@
"id": "20200924100950-9op5xi1",
"title": "Shortcuts",
"type": "doc",
- "updated": "20261008101123"
+ "updated": "20261008221006"
},
"Children": [
{
@@ -4274,7 +4274,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20210106154056-koo4wdj",
- "updated": "20261002230606"
+ "updated": "20261008221006"
},
"Children": [
{
@@ -13602,7 +13602,7 @@
"HeadingLevel": 3,
"Properties": {
"id": "20210106154319-jeh8w1g",
- "updated": "20260910080119"
+ "updated": "20261008221006"
},
"Children": [
{
@@ -13648,7 +13648,7 @@
"Properties": {
"colgroup": "|",
"id": "20210106154319-otreidg",
- "updated": "20260910080119"
+ "updated": "20261008221006"
},
"Children": [
{
@@ -14351,7 +14351,7 @@
"Children": [
{
"Type": "NodeText",
- "Data": "A single ordinary paragraph: next row in the same column, or a paragraph after the last row; other content follows its block type"
+ "Data": "Edit within the cell: create a paragraph, continue a list item, or insert a line break in code"
}
]
},
@@ -14390,6 +14390,30 @@
]
}
]
+ },
+ {
+ "Type": "NodeTableRow",
+ "Children": [
+ {
+ "Type": "NodeTableCell",
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "Insert a soft line break within a paragraph in the cell"
+ }
+ ]
+ },
+ {
+ "Type": "NodeTableCell",
+ "Children": [
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "Shift+Enter"
+ }
+ ]
+ }
+ ]
}
]
},
diff --git a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-abz7w6k/20200825162036-4dx365o.sy b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-abz7w6k/20200825162036-4dx365o.sy
index 842400e0ae..040e7f5725 100644
--- a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-abz7w6k/20200825162036-4dx365o.sy
+++ b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-abz7w6k/20200825162036-4dx365o.sy
@@ -8,7 +8,7 @@
"title": "排版元素",
"title-img": "background-color: hsl(2, 57%, 40%);background-image: repeating-linear-gradient(transparent, transparent 50px, rgba(0,0,0,.4) 50px, rgba(0,0,0,.4) 53px, transparent 53px, transparent 63px, rgba(0,0,0,.4) 63px, rgba(0,0,0,.4) 66px, transparent 66px, transparent 116px, rgba(0,0,0,.5) 116px, rgba(0,0,0,.5) 166px, rgba(255,255,255,.2) 166px, rgba(255,255,255,.2) 169px, rgba(0,0,0,.5) 169px, rgba(0,0,0,.5) 179px, rgba(255,255,255,.2) 179px, rgba(255,255,255,.2) 182px, rgba(0,0,0,.5) 182px, rgba(0,0,0,.5) 232px, transparent 232px),repeating-linear-gradient(270deg, transparent, transparent 50px, rgba(0,0,0,.4) 50px, rgba(0,0,0,.4) 53px, transparent 53px, transparent 63px, rgba(0,0,0,.4) 63px, rgba(0,0,0,.4) 66px, transparent 66px, transparent 116px, rgba(0,0,0,.5) 116px, rgba(0,0,0,.5) 166px, rgba(255,255,255,.2) 166px, rgba(255,255,255,.2) 169px, rgba(0,0,0,.5) 169px, rgba(0,0,0,.5) 179px, rgba(255,255,255,.2) 179px, rgba(255,255,255,.2) 182px, rgba(0,0,0,.5) 182px, rgba(0,0,0,.5) 232px, transparent 232px),repeating-linear-gradient(125deg, transparent, transparent 2px, rgba(0,0,0,.2) 2px, rgba(0,0,0,.2) 3px, transparent 3px, transparent 5px, rgba(0,0,0,.2) 5px);",
"type": "doc",
- "updated": "20261003234156"
+ "updated": "20261008221006"
},
"Children": [
{
@@ -3793,7 +3793,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20210104091228-1bq55o9",
- "updated": "20260910080119"
+ "updated": "20261008221006"
},
"Children": [
{
@@ -3821,12 +3821,12 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20260908091355-rch0005",
- "updated": "20260910080119"
+ "updated": "20261008221006"
},
"Children": [
{
"Type": "NodeText",
- "Data": "点击单元格即可编辑;新建表格后可直接输入,无需再次点击。单元格仅含一个普通段落时,"
+ "Data": "点击单元格即可编辑;新建表格后可直接输入,无需再次点击。"
},
{
"Type": "NodeTextMark",
@@ -3835,7 +3835,16 @@
},
{
"Type": "NodeText",
- "Data": " 移到下一行同列;表格末行则在表格后插入段落。"
+ "Data": " 按正文编辑规则创建新段落、继续列表项或在代码块内换行。"
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "Shift+Enter"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " 在段落内插入软换行。"
},
{
"Type": "NodeTextMark",
@@ -3844,16 +3853,16 @@
},
{
"Type": "NodeText",
- "Data": " 切换单元格,"
+ "Data": " 和 "
},
{
"Type": "NodeTextMark",
"TextMarkType": "kbd",
- "TextMarkTextContent": "Shift+Enter"
+ "TextMarkTextContent": "Shift+Tab"
},
{
"Type": "NodeText",
- "Data": " 在单元格内换行。包含标题、多个段落等内容时,Enter 按当前内容类型在单元格内编辑;列表和代码块使用对应的换行和缩进操作。关闭提示后按 "
+ "Data": " 切换单元格;列表和代码块保留对应的缩进与取消缩进操作。关闭提示后按 "
},
{
"Type": "NodeTextMark",
@@ -3862,7 +3871,7 @@
},
{
"Type": "NodeText",
- "Data": " 或点击单元格外结束编辑,内容自动保存。"
+ "Data": " 或点击单元格外结束编辑,内容自动保存。将表格复制为文本时,会保留单元格内段落之间的空行。"
}
]
},
diff --git a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200813004551-gm0pbn1.sy b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200813004551-gm0pbn1.sy
index ef47761b90..510fabf39c 100644
--- a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200813004551-gm0pbn1.sy
+++ b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200813004551-gm0pbn1.sy
@@ -7,7 +7,7 @@
"id": "20200813004551-gm0pbn1",
"title": "快捷键",
"type": "doc",
- "updated": "20261008101123"
+ "updated": "20261008221006"
},
"Children": [
{
@@ -4272,7 +4272,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20201227133317-rkh4bji",
- "updated": "20261002230606"
+ "updated": "20261008221006"
},
"Children": [
{
@@ -13672,7 +13672,7 @@
"HeadingLevel": 3,
"Properties": {
"id": "20201227133317-xpgtzbg",
- "updated": "20260910080119"
+ "updated": "20261008221006"
},
"Children": [
{
@@ -13718,7 +13718,7 @@
"Properties": {
"colgroup": "|",
"id": "20201227133317-v7clw0j",
- "updated": "20260910080119"
+ "updated": "20261008221006"
},
"Children": [
{
@@ -14421,7 +14421,7 @@
"Children": [
{
"Type": "NodeText",
- "Data": "单元格仅含一个普通段落:移到下一行同列,末行则在表格后插入段落;其他内容按当前类型编辑"
+ "Data": "在单元格内编辑:创建新段落、继续列表项或在代码块内换行"
}
]
},
@@ -14460,6 +14460,30 @@
]
}
]
+ },
+ {
+ "Type": "NodeTableRow",
+ "Children": [
+ {
+ "Type": "NodeTableCell",
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "在单元格内的段落中插入软换行"
+ }
+ ]
+ },
+ {
+ "Type": "NodeTableCell",
+ "Children": [
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "Shift+Enter"
+ }
+ ]
+ }
+ ]
}
]
},
diff --git a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226120854-dr1jfx2/20211226121319-emrk2yy.sy b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226120854-dr1jfx2/20211226121319-emrk2yy.sy
index 36f5a7fdec..327e05c76d 100644
--- a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226120854-dr1jfx2/20211226121319-emrk2yy.sy
+++ b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226120854-dr1jfx2/20211226121319-emrk2yy.sy
@@ -8,7 +8,7 @@
"title": "排版元素",
"title-img": "background-color: hsl(2, 57%, 40%);background-image: repeating-linear-gradient(transparent, transparent 50px, rgba(0,0,0,.4) 50px, rgba(0,0,0,.4) 53px, transparent 53px, transparent 63px, rgba(0,0,0,.4) 63px, rgba(0,0,0,.4) 66px, transparent 66px, transparent 116px, rgba(0,0,0,.5) 116px, rgba(0,0,0,.5) 166px, rgba(255,255,255,.2) 166px, rgba(255,255,255,.2) 169px, rgba(0,0,0,.5) 169px, rgba(0,0,0,.5) 179px, rgba(255,255,255,.2) 179px, rgba(255,255,255,.2) 182px, rgba(0,0,0,.5) 182px, rgba(0,0,0,.5) 232px, transparent 232px),repeating-linear-gradient(270deg, transparent, transparent 50px, rgba(0,0,0,.4) 50px, rgba(0,0,0,.4) 53px, transparent 53px, transparent 63px, rgba(0,0,0,.4) 63px, rgba(0,0,0,.4) 66px, transparent 66px, transparent 116px, rgba(0,0,0,.5) 116px, rgba(0,0,0,.5) 166px, rgba(255,255,255,.2) 166px, rgba(255,255,255,.2) 169px, rgba(0,0,0,.5) 169px, rgba(0,0,0,.5) 179px, rgba(255,255,255,.2) 179px, rgba(255,255,255,.2) 182px, rgba(0,0,0,.5) 182px, rgba(0,0,0,.5) 232px, transparent 232px),repeating-linear-gradient(125deg, transparent, transparent 2px, rgba(0,0,0,.2) 2px, rgba(0,0,0,.2) 3px, transparent 3px, transparent 5px, rgba(0,0,0,.2) 5px);",
"type": "doc",
- "updated": "20261003234156"
+ "updated": "20261008221006"
},
"Children": [
{
@@ -3791,7 +3791,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20211226122008-8glkpvq",
- "updated": "20260910080119"
+ "updated": "20261008221006"
},
"Children": [
{
@@ -3819,12 +3819,12 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20260908091355-rch0002",
- "updated": "20260910080119"
+ "updated": "20261008221006"
},
"Children": [
{
"Type": "NodeText",
- "Data": "點擊儲存格即可編輯;新增表格後可直接輸入,無需再次點擊。儲存格僅含一個普通段落時,"
+ "Data": "點擊儲存格即可編輯;新增表格後可直接輸入,無需再次點擊。"
},
{
"Type": "NodeTextMark",
@@ -3833,7 +3833,16 @@
},
{
"Type": "NodeText",
- "Data": " 移到下一列的同欄;表格末列則在表格後插入段落。"
+ "Data": " 依正文編輯規則建立新段落、繼續列表項目或在程式碼區塊內換行。"
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "Shift+Enter"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " 在段落內插入軟換行。"
},
{
"Type": "NodeTextMark",
@@ -3842,16 +3851,16 @@
},
{
"Type": "NodeText",
- "Data": " 切換儲存格,"
+ "Data": " 和 "
},
{
"Type": "NodeTextMark",
"TextMarkType": "kbd",
- "TextMarkTextContent": "Shift+Enter"
+ "TextMarkTextContent": "Shift+Tab"
},
{
"Type": "NodeText",
- "Data": " 在儲存格內換行。包含標題、多個段落等內容時,Enter 依目前內容類型在儲存格內編輯;列表和程式碼區塊使用對應的換行與縮排操作。關閉提示後按 "
+ "Data": " 切換儲存格;列表和程式碼區塊保留對應的縮排與取消縮排操作。關閉提示後按 "
},
{
"Type": "NodeTextMark",
@@ -3860,7 +3869,7 @@
},
{
"Type": "NodeText",
- "Data": " 或點擊儲存格外結束編輯,內容自動儲存。"
+ "Data": " 或點擊儲存格外結束編輯,內容自動儲存。將表格複製為文字時,會保留儲存格內段落之間的空行。"
}
]
},
diff --git a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226122549-jktxego.sy b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226122549-jktxego.sy
index 04e451ee33..e0685970ef 100644
--- a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226122549-jktxego.sy
+++ b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226122549-jktxego.sy
@@ -7,7 +7,7 @@
"id": "20211226122549-jktxego",
"title": "快捷鍵",
"type": "doc",
- "updated": "20261008101123"
+ "updated": "20261008221006"
},
"Children": [
{
@@ -4266,7 +4266,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20211226122652-htptsmh",
- "updated": "20261002230606"
+ "updated": "20261008221006"
},
"Children": [
{
@@ -13590,7 +13590,7 @@
"HeadingLevel": 3,
"Properties": {
"id": "20211226122652-x2dmpab",
- "updated": "20260910080119"
+ "updated": "20261008221006"
},
"Children": [
{
@@ -13636,7 +13636,7 @@
"Properties": {
"colgroup": "|",
"id": "20211226122652-n2r88dm",
- "updated": "20260910080119"
+ "updated": "20261008221006"
},
"Children": [
{
@@ -14339,7 +14339,7 @@
"Children": [
{
"Type": "NodeText",
- "Data": "儲存格僅含一個普通段落:移到下一列的同欄,末列則在表格後插入段落;其他內容依目前類型編輯"
+ "Data": "在儲存格內編輯:建立新段落、繼續列表項目或在程式碼區塊內換行"
}
]
},
@@ -14378,6 +14378,30 @@
]
}
]
+ },
+ {
+ "Type": "NodeTableRow",
+ "Children": [
+ {
+ "Type": "NodeTableCell",
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "在儲存格內的段落中插入軟換行"
+ }
+ ]
+ },
+ {
+ "Type": "NodeTableCell",
+ "Children": [
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "Shift+Enter"
+ }
+ ]
+ }
+ ]
}
]
},
diff --git a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-xsbxokr.sy b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-xsbxokr.sy
index 93fa809a2e..30207ca6d4 100644
--- a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-xsbxokr.sy
+++ b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-xsbxokr.sy
@@ -9,7 +9,7 @@
"id": "20240530101000-xsbxokr",
"title": "ショートカット",
"type": "doc",
- "updated": "20261008101123"
+ "updated": "20261008221006"
},
"Children": [
{
@@ -4228,7 +4228,7 @@
"Properties": {
"ID": "20240530101000-twmuxke",
"id": "20240530101000-675gu9g",
- "updated": "20261002230607"
+ "updated": "20261008221006"
},
"Children": [
{
@@ -13549,7 +13549,7 @@
"Properties": {
"ID": "20240530101000-uqhtil9",
"id": "20240530101000-9x0xqew",
- "updated": "20260811122156"
+ "updated": "20261008221006"
},
"Children": [
{
@@ -13617,7 +13617,7 @@
"Properties": {
"colgroup": "|",
"id": "20240530101000-prxsqyv",
- "updated": "20260811122156"
+ "updated": "20261008221006"
},
"Children": [
{
@@ -14283,6 +14283,54 @@
]
}
]
+ },
+ {
+ "Type": "NodeTableRow",
+ "Children": [
+ {
+ "Type": "NodeTableCell",
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "セル内で編集:段落の作成、リスト項目の追加、コードブロック内の改行"
+ }
+ ]
+ },
+ {
+ "Type": "NodeTableCell",
+ "Children": [
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "Enter"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "Type": "NodeTableRow",
+ "Children": [
+ {
+ "Type": "NodeTableCell",
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "セル内の段落にソフト改行を挿入"
+ }
+ ]
+ },
+ {
+ "Type": "NodeTableCell",
+ "Children": [
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "Shift+Enter"
+ }
+ ]
+ }
+ ]
}
]
},
diff --git a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-hnu6o79/20240530101000-3qhz7br.sy b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-hnu6o79/20240530101000-3qhz7br.sy
index 7e3c7b4956..e31e5eb351 100644
--- a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-hnu6o79/20240530101000-3qhz7br.sy
+++ b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-hnu6o79/20240530101000-3qhz7br.sy
@@ -9,7 +9,7 @@
"title": "書式要素",
"title-img": "background-color:#269;background-image: linear-gradient(white 2px, transparent 2px),linear-gradient(90deg, white 2px, transparent 2px),linear-gradient(rgba(255,255,255,.3) 1px, transparent 1px),linear-gradient(90deg, rgba(255,255,255,.3) 1px, transparent 1px);background-size: 100px 100px, 100px 100px, 20px 20px, 20px 20px;background-position:-2px -2px, -2px -2px, -1px -1px, -1px -1px;",
"type": "doc",
- "updated": "20261003234156"
+ "updated": "20261008221006"
},
"Children": [
{
@@ -3955,7 +3955,7 @@
"Properties": {
"ID": "20240530101000-grqaq7u",
"id": "20240530101000-hen4g1y",
- "updated": "20260910080119"
+ "updated": "20261008221006"
},
"Children": [
{
@@ -3983,12 +3983,12 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20260909090723-or0hf4r",
- "updated": "20260910080119"
+ "updated": "20261008221006"
},
"Children": [
{
"Type": "NodeText",
- "Data": "セルをクリックすると編集できます。テーブルの作成直後は、再度クリックせずに入力できます。セルに通常の段落が一つだけ含まれる場合、"
+ "Data": "セルをクリックすると編集できます。テーブルの作成直後は、再度クリックせずに入力できます。"
},
{
"Type": "NodeTextMark",
@@ -3997,7 +3997,16 @@
},
{
"Type": "NodeText",
- "Data": " で次の行の同じ列に移動します。最終行ではテーブルの後に段落を挿入します。"
+ "Data": " は通常のエディタと同じ規則で、新しい段落の作成、リスト項目の追加、コードブロック内の改行を行います。"
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "Shift+Enter"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " は段落内にソフト改行を挿入します。"
},
{
"Type": "NodeTextMark",
@@ -4006,16 +4015,16 @@
},
{
"Type": "NodeText",
- "Data": " でセルを切り替え、"
+ "Data": " と "
},
{
"Type": "NodeTextMark",
"TextMarkType": "kbd",
- "TextMarkTextContent": "Shift+Enter"
+ "TextMarkTextContent": "Shift+Tab"
},
{
"Type": "NodeText",
- "Data": " でセル内を改行します。見出しや複数の段落などを含む場合、Enter は現在の内容の種類に応じてセル内を編集します。リストとコードブロックでは、それぞれの改行とインデント操作が適用されます。候補を閉じてから "
+ "Data": " でセルを切り替えます。リストとコードブロックでは、インデントとアウトデントの操作が維持されます。候補を閉じてから "
},
{
"Type": "NodeTextMark",
@@ -4024,7 +4033,7 @@
},
{
"Type": "NodeText",
- "Data": " を押すか、セルの外をクリックすると編集が終了し、内容が自動保存されます。"
+ "Data": " を押すか、セルの外をクリックすると編集が終了し、内容が自動保存されます。テーブルをテキストとしてコピーすると、セル内の段落間の空行が保持されます。"
}
]
},
diff --git a/app/src/protyle/render/tableCellInput.test.ts b/app/src/protyle/render/tableCellInput.test.ts
index d34caad372..19cf7433be 100644
--- a/app/src/protyle/render/tableCellInput.test.ts
+++ b/app/src/protyle/render/tableCellInput.test.ts
@@ -7,11 +7,13 @@ import {test} from "node:test";
import {promisify} from "node:util";
import {createSourceFile, isClassDeclaration, isVariableStatement, ScriptTarget, transpileModule} from "typescript";
-const browserCases = async (source: string, queueSource: string, editorSource: string, menuSource: string, transactionSource: string) => {
+const browserCases = async (source: string, queueSource: string, editorSource: string, menuSource: string,
+ transactionSource: string, copyPlainSource: string) => {
const check: typeof assert = require("node:assert/strict");
const noop = () => {};
const tick = () => new Promise(resolve => setTimeout(resolve, 0));
const changes: {doOperations: IOperation[], undoOperations: IOperation[]}[] = [];
+ const enteredCells: Element[] = [];
const focusByRange = (range: Range) => {
getSelection().removeAllRanges();
getSelection().addRange(range);
@@ -42,7 +44,7 @@ const browserCases = async (source: string, queueSource: string, editorSource: s
const api = new Function(...Object.keys(dependencies), source + "\nreturn {input, insertRow, insertRowAbove, insertColumn, " +
"getAgentLute, configureAVRichTextLute, getTableCellEditorLute, getAVRichTextLute, " +
"getTableCellRichBlockDOM, serializeTableCellRich, cleanTableCellRichHTML, renderTableCellRich, " +
- "setTableCellRich, getTableCellInlineHTML, getSelectionOffset, focusByOffset, getTableBlockHTML, updateTableCellEditingValue, " +
+ "setTableCellRich, getTableCellInlineHTML, getTableCellPlainText, getSelectionOffset, focusByOffset, getTableBlockHTML, updateTableCellEditingValue, " +
"updateTableCellContentLayout, captureRichCellSelection, captureRichCellSelectionAtPoint, restoreRichCellSelection, setTableCellRichEventTarget, " +
"LargeTableVirtualizer, getTableVirtualCellIndex, getTableVirtualRowIndex, restoreTableVirtualizationDOM};")(...Object.values(dependencies)) as
typeof import("../wysiwyg/input") & typeof import("../util/table") & typeof import("./setLute") &
@@ -120,6 +122,12 @@ const browserCases = async (source: string, queueSource: string, editorSource: s
'<div class="protyle-toolbar"><svg><use href="#iconBold"></use></svg>Font family Font Size</div>' +
"<style>.protyle-content::highlight(search-mark-regression) {color: red;}</style>";
const wysiwyg = host.querySelector<HTMLElement>(".protyle-wysiwyg");
+ wysiwyg.addEventListener("keydown", event => {
+ if (event.key === "Enter") {
+ enteredCells.push(host.closest("th, td"));
+ event.preventDefault();
+ }
+ });
const hidden = document.createElement("div");
hidden.className = "fn__none";
api.updateTableCellContentLayout(host, options.initialBlockHTML);
@@ -154,8 +162,9 @@ const browserCases = async (source: string, queueSource: string, editorSource: s
const transactionAPI = new Function(...Object.keys(transactionDependencies),
transactionSource + "\nreturn {updateTransaction, promiseTransaction};")(...Object.values(transactionDependencies));
editorDependencies.updateTransaction = transactionAPI.updateTransaction;
- const open = new Function(...Object.keys(editorDependencies), editorSource + "\nreturn openTableCellRichEditor;")(
- ...Object.values(editorDependencies)) as typeof import("./tableCellRichEditor").openTableCellRichEditor;
+ const {openTableCellRichEditor: open, enterTableCellRichEditor: enterCell} = new Function(...Object.keys(editorDependencies),
+ editorSource + "\nreturn {openTableCellRichEditor, enterTableCellRichEditor};")(
+ ...Object.values(editorDependencies)) as typeof import("./tableCellRichEditor");
const noUI = (html: string) => check.doesNotMatch(html, /DesktopTabletMobile|Font family|Font Size|search-mark-regression|table__cell-editor/);
const operationHTML = (operation: IOperation) => {
check.ok(typeof operation.data === "string");
@@ -167,6 +176,54 @@ const browserCases = async (source: string, queueSource: string, editorSource: s
await tick();
};
+ {
+ const {element, table} = fixture();
+ const cells = Array.from(table.querySelectorAll("th"));
+ api.setTableCellRich(cells[0], "first\n\nsecond");
+ cells[1].innerHTML = "third<br>fourth";
+ let copied = "";
+ new Function("selectedCellElements", "getTableCellPlainText", "copyPlainText", copyPlainSource)(
+ cells.slice(0, 2), api.getTableCellPlainText, (text: string) => { copied = text; });
+ check.equal(copied, "first\n\nsecond\tthird\nfourth", "the cell menu copies paragraph boundaries and ordinary soft breaks");
+ await finish(element);
+ }
+
+ // 未挂载的单元格等待外层输入完成后处理回车,表格替换后仍定位到当前单元格。
+ for (const replaceTable of [false, true]) {
+ const {owner, queue, element, table} = fixture();
+ const cell = table.querySelector("th");
+ let release: () => void;
+ queue.scheduleInput(async () => {
+ await new Promise<void>(resolve => { release = resolve; });
+ if (replaceTable) {
+ table.replaceWith(table.cloneNode(true));
+ }
+ });
+ enteredCells.length = 0;
+ const entering = enterCell(owner, cell);
+ check.equal(enteredCells.length, 0);
+ release();
+ await entering;
+ const current = owner.wysiwyg.element.querySelector("th");
+ check.deepEqual(enteredCells, [current]);
+ check.ok(current.querySelector(".table__cell-editor"));
+ await finish(element);
+ }
+ {
+ const {owner, queue, element, table} = fixture();
+ const releases: Array<() => void> = [];
+ queue.flushPendingInput = () => new Promise<void>(resolve => { releases.push(resolve); });
+ enteredCells.length = 0;
+ const entering = enterCell(owner, table.querySelector("th"));
+ const switching = open(owner, table.querySelectorAll("th")[1]);
+ releases[0]();
+ await entering;
+ releases[1]();
+ await switching;
+ check.equal(enteredCells.length, 0, "a cancelled Enter must not edit another cell");
+ await finish(element);
+ }
+
let tableImageOwner: IProtyle;
let imageMenus = 0;
{
@@ -547,6 +604,10 @@ test("table cell editors wait for outer input and table menu Enter is consumed",
statement.declarationList.declarations.some(declaration =>
["updateTransaction", "promiseTransaction"].includes(declaration.name.getText(transactionFile))))
.map(statement => statement.getText(transactionFile)).join("\n"));
+ const wysiwygSource = read("../wysiwyg/index.ts");
+ const copyEnd = wysiwygSource.indexOf("copyPlainText(textPlain.slice(0, -1));") + "copyPlainText(textPlain.slice(0, -1));".length;
+ const copyStart = wysiwygSource.lastIndexOf('let textPlain = "";', copyEnd);
+ const copyPlainSource = compile(wysiwygSource.substring(copyStart, copyEnd));
const temporary = mkdtempSync(path.join(tmpdir(), "siyuan-table-cell-input-test-"));
const script = path.join(temporary, "run.cjs");
const lutePath = path.resolve(__dirname, "../../../stage/protyle/js/lute/lute.min.js");
@@ -561,7 +622,7 @@ app.whenReady().then(async () => {
await win.loadURL("data:text/html,<html><body></body></html>");
await win.webContents.executeJavaScript(require("node:fs").readFileSync(${JSON.stringify(lutePath)}, "utf8"));
console.log(await win.webContents.executeJavaScript(${JSON.stringify("const __name = value => value; (" +
- browserCases.toString() + ")(" + [source, queue, compile(read("tableCellRichEditor.ts")), menuSource, transactionSource]
+ browserCases.toString() + ")(" + [source, queue, compile(read("tableCellRichEditor.ts")), menuSource, transactionSource, copyPlainSource]
.map(value => JSON.stringify(value)).join(",") + ")")}));
win.destroy();
app.exit(0);
diff --git a/app/src/protyle/render/tableCellRichEditor.ts b/app/src/protyle/render/tableCellRichEditor.ts
index e74f280db4..35d52418d6 100644
--- a/app/src/protyle/render/tableCellRichEditor.ts
+++ b/app/src/protyle/render/tableCellRichEditor.ts
@@ -27,13 +27,24 @@ import {bindTableCellRichDrag} from "../util/tableCellRichDrag";
import {getTableCellEditorLute} from "../util/tableCellRichLute";
import {setTableCellRichContext, setTableCellRichEventTarget} from "../util/tableCellRichContext";
import {updateOutlineCurrentBlock} from "../util/outlineBlock";
-import {canEnterCodeBlock} from "../wysiwyg/codeBlockEnter";
import {bindLiteCodeActions} from "../lite/codeActions";
import {getTableVirtualCellIndex, getTableVirtualRowIndex, restoreTableVirtualizationDOM} from "../util/tableVirtualizationDOM";
let activeEditor: {cell: Element, finish: () => void, prepareSwitch: () => boolean} | undefined;
let openingEditor: object | undefined;
+export const enterTableCellRichEditor = async (owner: IProtyle, cell: HTMLTableCellElement) => {
+ const currentCell = await openTableCellRichEditor(owner, cell);
+ const editor = currentCell?.querySelector(".table__cell-editor .protyle-wysiwyg");
+ const selection = getSelection();
+ if (!currentCell || owner.disabled || activeEditor?.cell !== currentCell || !editor?.contains(selection?.anchorNode) ||
+ !editor.contains(selection.focusNode)) {
+ return;
+ }
+ // 单元格挂载完成后,由内部编辑器处理回车和对应的内容结构。
+ editor.dispatchEvent(new KeyboardEvent("keydown", {key: "Enter", code: "Enter", bubbles: true, cancelable: true}));
+};
+
export const applyTableCellRichInlineMark = (owner: IProtyle, cells: HTMLTableCellElement[], type: string,
textObj?: ITextOption) => {
if (owner.disabled) {
@@ -94,7 +105,7 @@ export const openTableCellRichEditor = async (owner: IProtyle, cell: HTMLTableCe
}
if (activeEditor?.cell === cell) {
openingEditor = undefined;
- return;
+ return cell;
}
const previousEditor = activeEditor;
const preserveFocus = isMobile() && previousEditor?.cell.contains(document.activeElement) &&
@@ -113,6 +124,7 @@ export const openTableCellRichEditor = async (owner: IProtyle, cell: HTMLTableCe
openingEditor = request;
try {
await mountTableCellRichEditor(request, retainedEditor, owner, cell, navigation, point, restoredSelection);
+ return openingEditor === request ? activeEditor?.cell : undefined;
} finally {
if (retainedEditor && openingEditor === request) {
retainedEditor.finish();
@@ -514,16 +526,7 @@ const mountTableCellRichEditor = async (request: object, previousEditor: typeof
}
const target = range?.startContainer instanceof Element ? range.startContainer : range?.startContainer.parentElement;
const inListOrCode = target?.closest('[data-type="NodeList"], [data-type="NodeCodeBlock"]');
- const editable = target?.closest<HTMLElement>('[contenteditable="true"]');
- const enterCode = event.key === "Enter" && !event.shiftKey &&
- editable?.parentElement.getAttribute("data-type") === "NodeParagraph" &&
- canEnterCodeBlock(editable,
- getSelectionOffset(editable, fragment.wysiwyg, range).start,
- window.siyuan.config.editor.markdown.codeBlockMiddleDot !== false);
- const navigate = !inListOrCode && (event.key === "Tab" ||
- (event.key === "Enter" && !event.shiftKey && !enterCode &&
- getTableCellInlineHTML(fragment.getBlockHTML()) !== null));
- if (navigate) {
+ if (!inListOrCode && event.key === "Tab") {
event.preventDefault();
event.stopImmediatePropagation();
finish();
diff --git a/app/src/protyle/util/table.ts b/app/src/protyle/util/table.ts
index f953018fab..a22ec4c572 100644
--- a/app/src/protyle/util/table.ts
+++ b/app/src/protyle/util/table.ts
@@ -454,25 +454,10 @@ export const fixTable = (protyle: IProtyle, event: KeyboardEvent, range: Range)
}
if (!nodeElement.classList.contains("protyle-wysiwyg--select") && !hasClosestByClassName(nodeElement, "protyle-wysiwyg--select")) {
- // enter 光标跳转到下一行同列
+ // 未进入编辑状态的单元格先挂载内部编辑器,再按正文规则处理回车。
if (isNotCtrl(event) && !event.shiftKey && !event.altKey && event.key === "Enter") {
event.preventDefault();
- const trElement = cellElement.parentElement as HTMLTableRowElement;
- if ((!trElement.nextElementSibling && trElement.parentElement.tagName === "TBODY") ||
- (trElement.parentElement.tagName === "THEAD" && !trElement.parentElement.nextElementSibling)) {
- insertEmptyBlock(protyle, "afterend", nodeElement.getAttribute("data-node-id"));
- return true;
- }
- let nextElement = trElement.nextElementSibling as HTMLTableRowElement;
- if (!nextElement) {
- nextElement = trElement.parentElement.nextElementSibling.firstChild as HTMLTableRowElement;
- }
- if (!nextElement) {
- return true;
- }
- range.selectNodeContents(nextElement.cells[getColIndex(cellElement)]);
- range.collapse(true);
- scrollCenter(protyle);
+ void import("../render/tableCellRichEditor").then(module => module.enterTableCellRichEditor(protyle, cellElement));
return true;
}
// 表格后无内容时,按右键需新建空块
diff --git a/app/src/protyle/util/tableCellRich.ts b/app/src/protyle/util/tableCellRich.ts
index f2583836ae..4dcc262e1f 100644
--- a/app/src/protyle/util/tableCellRich.ts
+++ b/app/src/protyle/util/tableCellRich.ts
@@ -155,9 +155,27 @@ export const getTableCellRichInline = (cell: Element) => {
export const getTableCellRichPlainText = (cell: Element) => {
const template = document.createElement("template");
- template.innerHTML = getTableCellRichInline(cell);
- template.content.querySelectorAll("br").forEach(br => br.replaceWith("\n"));
- return getTextWithoutSemanticMarkers(template.content).replace(/\u200b/g, "").trim();
+ template.innerHTML = getTableCellRichBlockDOM(cell);
+ // 从源内容逐块投影文本,段落分隔保留空行,块内软换行和列表标记保持原样。
+ const projectedCell = document.createElement("td");
+ const projection = document.createElement("template");
+ let boundaryToken = "SYTABLECELLPARAGRAPHBOUNDARY";
+ while (template.innerHTML.includes(boundaryToken)) {
+ boundaryToken += "X";
+ }
+ // 嵌套段落的边界使用临时占位符补足空行,投影时仍保留完整列表结构。
+ template.content.querySelectorAll('[data-type="NodeListItem"] > [data-type="NodeParagraph"], ' +
+ '[data-type="NodeBlockquote"] > [data-type="NodeParagraph"]').forEach(block => {
+ if (block.nextElementSibling?.getAttribute("data-type")?.startsWith("Node")) {
+ block.querySelector('[contenteditable="true"]')?.appendChild(document.createTextNode(boundaryToken));
+ }
+ });
+ return Array.from(template.content.children).map(block => {
+ projectedCell.setAttribute(TABLE_CELL_RICH_ATTRIBUTE, encodeTableCellRich(serializeTableCellRich(block.outerHTML).markdown));
+ projection.innerHTML = getTableCellRichInline(projectedCell);
+ projection.content.querySelectorAll("br").forEach(br => br.replaceWith("\n"));
+ return getTextWithoutSemanticMarkers(projection.content).replace(/\u200b/g, "").split(boundaryToken).join("\n").trim();
+ }).join("\n\n").trim();
};
export const getTableCellPlainText = (cell: Element) => {
diff --git a/app/src/protyle/util/tableCellRichLute.test.ts b/app/src/protyle/util/tableCellRichLute.test.ts
index b33b7f56d5..f6b44dbfc0 100644
--- a/app/src/protyle/util/tableCellRichLute.test.ts
+++ b/app/src/protyle/util/tableCellRichLute.test.ts
@@ -5,25 +5,44 @@ import {tmpdir} from "node:os";
import * as path from "node:path";
import {test} from "node:test";
import {promisify} from "node:util";
-import {createSourceFile, isClassDeclaration, isMethodDeclaration, ScriptTarget, transpileModule} from "typescript";
+import {createSourceFile, isClassDeclaration, isMethodDeclaration, isVariableStatement, ScriptTarget, transpileModule} from "typescript";
const browserCases = async (source: string, enterSource: string, hintSource: string, keydownSource: string,
- copySource: string, selectionSource: string, highlightSource: string) => {
+ copySource: string, selectionSource: string, highlightSource: string, blockSource: string) => {
const check: typeof assert = require("node:assert/strict");
const codeTabAttribute = "custom-sy-code-tab-spaces";
const api = new Function("Constants", source + "\nreturn {getAgentLute, configureAVRichTextLute, getTableCellEditorLute, " +
"canEnterCodeBlock, hasCodeBlockFence, getTableCellInlineHTML, serializeTableCellRich, " +
"updateTableCellEditingValue, getTableCellRichBlockDOM, sanitizeAVRichTextBlockDOM, restoreTableVirtualizationDOM, " +
- "copyTableCellContent, renderTableCellRich, prepareInlineElementBoundaryMutation};")({
+ "copyTableCellContent, renderTableCellRich, getTableCellPlainText, encodeTableCellRich, getTextWithoutSemanticMarkers, prepareInlineElementBoundaryMutation};")({
CUSTOM_SY_CODE_TAB_SPACES: codeTabAttribute,
}) as
typeof import("../render/setLute") & typeof import("../render/av/richTextValue") &
typeof import("./tableCellRichLute") & typeof import("../wysiwyg/codeBlockEnter") &
typeof import("./tableCellRich") & typeof import("../render/av/richText") & typeof import("./tableVirtualizationDOM") &
- typeof import("./inlineElementBoundary");
+ typeof import("./inlineElementBoundary") & typeof import("./tableCellRichValue") & typeof import("./inlineElementMarker");
const base = api.configureAVRichTextLute(api.getAgentLute({emojiSite: "/emojis", emojis: {},
headingAnchor: false, listStyle: false, paragraphBeginningSpace: true, sanitize: true}));
const lute = api.getTableCellEditorLute(base);
+ for (const [markdown, expected, blockCount] of [
+ ["first\n\nsecond", "first\n\nsecond", 2],
+ ["first<br />second\n\nlast", "first\nsecond\n\nlast", 2],
+ ["**first**\n\n[second](https://example.com)", "first\n\nsecond", 2],
+ ["first\n\n- one\n- two\n\nlast", "first\n\n- one\n- two\n\nlast", 3],
+ ["first\n\n```go\na\nb\n```\n\nlast", "first\n\na\nb\n\nlast", 3],
+ ["> first\n>\n> second", "first\n\nsecond", 2],
+ ["- first\n\n second\n- third", "- first\n\nsecond\n- third", 3],
+ ] as const) {
+ const cell = document.createElement("td");
+ cell.setAttribute("data-sy-table-cell-rich", api.encodeTableCellRich(markdown));
+ const plainText = api.getTableCellPlainText(cell);
+ check.equal(plainText, expected);
+ const pasted = document.createElement("div");
+ pasted.innerHTML = base.Md2BlockDOM(plainText);
+ check.equal(pasted.children.length, blockCount);
+ check.equal(cell.getAttribute("data-sy-table-cell-rich"),
+ api.encodeTableCellRich(markdown), "copying never changes the source");
+ }
for (const target of [
"D:\\基线测试\\测试文档1.docx", "D:/基线测试/测试文档1.docx", "D:\\目录\\",
"file:///D:\\基线测试\\测试文档1.docx", "file:///D:/基线测试/测试文档1.docx",
@@ -176,13 +195,16 @@ const browserCases = async (source: string, enterSource: string, hintSource: str
const subElement = hintElement.cloneNode() as HTMLElement;
const calls: {rendered?: Element, transaction?: {element: Element, oldHTML: string,
additional?: {doOperations: IOperation[], undoOperations: IOperation[]}}, navigated: number} = {navigated: 0};
+ const editTransactions: {doOperations: IOperation[], undoOperations: IOperation[]}[] = [];
const protyle = {lute, lite: true, wysiwyg: {element: wysiwyg}, toolbar: {range: document.createRange(), subElement},
options: {hint: {extend: [{key: "/", hint: (): IHintData[] => []}]}}};
const getSelectionOffset = (editable: Node, _editor: Element, range: Range) => {
const prefix = document.createRange();
prefix.selectNodeContents(editable);
prefix.setEnd(range.startContainer, range.startOffset);
- return {start: prefix.toString().length};
+ const start = prefix.toString().length;
+ prefix.setEnd(range.endContainer, range.endOffset);
+ return {start, end: prefix.toString().length};
};
const getContenteditableElement = (element: Element) => element.querySelector('[contenteditable="true"]');
const focusByWbr = (element: Element, range: Range) => {
@@ -203,24 +225,33 @@ const browserCases = async (source: string, enterSource: string, hintSource: str
Object.assign(window, {siyuan: {storage: {codeLanguage: ""}, config: {
editor: {markdown: {codeBlockMiddleDot: true}}, keymap: {editor: {table: {}, general: {}}},
}}});
+ const blockAPI = new Function("Constants", blockSource + "\nreturn {genEmptyElement, genEmptyBlock, genListItemElement};")(constants);
const dependencies = {
- ...api, Constants: constants, BLOCK_SELECTION_CLASS: "protyle-wysiwyg--select",
+ ...api, ...blockAPI, Constants: constants, BLOCK_SELECTION_CLASS: "protyle-wysiwyg--select",
getBlockSelectionModeElement: (): undefined => undefined, getEmbedChildOperationContext: (): undefined => undefined,
hasClosestByClassName: (element: Element, className: string) => element.closest("." + className),
isNotEditBlock: () => false, getContenteditableElement, getSelectionOffset,
+ getUndoFocusContext: () => ({}), getParentBlock: (element: Element) => element.parentElement,
+ getPreviousBlockSibling: (element: Element) => element.previousElementSibling,
+ isEmptyListItemBlock: () => false, shouldCreateListItemChildOnEnter: () => false,
+ updateListOrder: () => {}, blockRender: () => {}, mathRender: () => {}, scrollCenter: () => {},
activateTrackedRangeInsertion: () => {}, setStorageVal: () => {},
highlightRender: (element: Element) => {
calls.rendered = element;
focusByWbr(element, protyle.toolbar.range);
},
- processRender: () => { throw new Error("ordinary code must not use the render editor"); },
+ processRender: (element: Element) => {
+ check.equal(element.classList.contains("render-node"), false, "ordinary content must not use the render editor");
+ },
updateTransaction, focusByWbr, focusByRange: () => {}, hideElements: () => {},
hasClosestBlock: (node: Node) => (node instanceof Element ? node : node.parentElement).closest("[data-node-id]"),
shouldCaptureHintUndoFocus: () => false, isBuiltinSlashHint: () => true,
- transaction: () => {},
+ transaction: (_protyle: IProtyle, doOperations: IOperation[], undoOperations: IOperation[]) => {
+ editTransactions.push({doOperations, undoOperations});
+ },
};
- const enter = new Function(...Object.keys(dependencies), enterSource + "\nreturn enter;")(...Object.values(dependencies)) as
- typeof import("../wysiwyg/enter").enter;
+ const enter = new Function(...Object.keys(dependencies), enterSource + "\nreturn enter;")(
+ ...Object.values(dependencies)) as typeof import("../wysiwyg/enter").enter;
const fill = new Function(...Object.keys(dependencies), hintSource + "\nreturn Hint.prototype.fill;")(...Object.values(dependencies));
const fragment = {wysiwyg, protyle, hintElement, getBlockHTML: () => wysiwyg.innerHTML};
const keyDependencies = {...dependencies, host, cell, table: cell.closest("table"), fragment, owner: protyle, signal: new AbortController().signal,
@@ -237,13 +268,16 @@ const browserCases = async (source: string, enterSource: string, hintSource: str
protyle.toolbar.range = range;
calls.rendered = undefined;
calls.transaction = undefined;
+ editTransactions.length = 0;
return range;
};
let entered: Promise<unknown>;
wysiwyg.addEventListener("keydown", event => {
if (event.key === "Enter" && !event.shiftKey) {
const range = getSelection().getRangeAt(0);
- entered = enter(wysiwyg.firstElementChild as HTMLElement, range, protyle as unknown as IProtyle);
+ const block = (range.startContainer instanceof Element ? range.startContainer : range.startContainer.parentElement)
+ .closest<HTMLElement>('[data-type="NodeParagraph"], [data-type="NodeCodeBlock"]');
+ entered = enter(block, range, protyle as unknown as IProtyle);
}
});
const replay = (operations: IOperation[]) => operations.forEach(operation => {
@@ -304,8 +338,23 @@ const browserCases = async (source: string, enterSource: string, hintSource: str
const previous = calls.navigated;
entered = undefined;
getContenteditableElement(wysiwyg).dispatchEvent(new KeyboardEvent("keydown", {key: "Enter", bubbles: true, cancelable: true}));
- check.equal(calls.navigated, previous + 1, text);
- check.equal(entered, undefined);
+ await entered;
+ check.equal(calls.navigated, previous, text);
+ check.equal(wysiwyg.children.length, 2, text);
+ check.equal(wysiwyg.firstElementChild.querySelector('[contenteditable="true"]').textContent.replace(/\u200b/g, ""),
+ text.substring(0, offset));
+ const stored = document.createElement("td");
+ api.updateTableCellEditingValue(stored, api.serializeTableCellRich(wysiwyg.innerHTML));
+ check.ok(stored.hasAttribute("data-sy-table-cell-rich"));
+ const reopened = document.createElement("div");
+ reopened.innerHTML = api.getTableCellRichBlockDOM(stored);
+ check.equal(reopened.children.length, 2, "saving and reopening retains the paragraph split");
+ }
+ for (const shiftKey of [false, true]) {
+ prepare("ordinary");
+ const previous = calls.navigated;
+ getContenteditableElement(wysiwyg).dispatchEvent(new KeyboardEvent("keydown", {key: "Tab", shiftKey, bubbles: true, cancelable: true}));
+ check.equal(calls.navigated, previous + 1);
}
prepare("```go");
const previous = calls.navigated;
@@ -320,7 +369,71 @@ const browserCases = async (source: string, enterSource: string, hintSource: str
window.siyuan.config.editor.markdown.codeBlockMiddleDot = false;
prepare("···go");
getContenteditableElement(wysiwyg).dispatchEvent(new KeyboardEvent("keydown", {key: "Enter", bubbles: true, cancelable: true}));
- check.equal(calls.navigated, beforeSoftEnter + 1);
+ await entered;
+ check.equal(calls.navigated, beforeSoftEnter);
+ check.equal(wysiwyg.querySelector('[data-type="NodeCodeBlock"]'), null);
+ prepare("firstsecond", 5);
+ getContenteditableElement(wysiwyg).dispatchEvent(new KeyboardEvent("keydown", {key: "Enter", bubbles: true, cancelable: true}));
+ await entered;
+ check.deepEqual(Array.from(wysiwyg.children).map(block =>
+ block.querySelector('[contenteditable="true"]').textContent.replace(/\u200b/g, "")), ["first", "second"]);
+ check.equal(editTransactions.length, 1);
+ const splitTransaction = editTransactions[0];
+ replay(splitTransaction.undoOperations);
+ check.equal(wysiwyg.children.length, 1);
+ check.equal(getContenteditableElement(wysiwyg).textContent.replace(/\u200b/g, ""), "firstsecond");
+ replay(splitTransaction.doOperations);
+ check.deepEqual(Array.from(wysiwyg.children).map(block =>
+ block.querySelector('[contenteditable="true"]').textContent.replace(/\u200b/g, "")), ["first", "second"]);
+ prepare("firstsecond", 0);
+ getContenteditableElement(wysiwyg).dispatchEvent(new KeyboardEvent("keydown", {key: "Enter", bubbles: true, cancelable: true}));
+ await entered;
+ check.equal(wysiwyg.children.length, 2);
+ check.equal(wysiwyg.lastElementChild.querySelector('[contenteditable="true"]').textContent.replace(/\u200b/g, ""), "firstsecond");
+ {
+ const range = prepare("firstsecond", 5);
+ const block = wysiwyg.firstElementChild as HTMLElement;
+ const mobileDependencies = {...dependencies, isMobile: () => true, isIPad: () => false,
+ hasNextSibling: (node: Node) => node.nextSibling, setTrackedRangeInsertionResult: () => {}};
+ const mobileSoftEnter = new Function(...Object.keys(mobileDependencies), enterSource + "\nreturn softEnter;")(
+ ...Object.values(mobileDependencies)) as typeof import("../wysiwyg/enter").softEnter;
+ check.equal(mobileSoftEnter(range, block, {...protyle, toolbar: {...protyle.toolbar, getCurrentType: (): string[] => []}} as unknown as IProtyle), true);
+ check.equal(wysiwyg.children.length, 1);
+ check.match(api.serializeTableCellRich(wysiwyg.innerHTML).markdown, /first<br \/>second/);
+ }
+ for (const markdown of ["- first", "1. first"]) {
+ wysiwyg.innerHTML = base.Md2BlockDOM(markdown);
+ const editable = getContenteditableElement(wysiwyg);
+ const range = document.createRange();
+ range.selectNodeContents(editable);
+ range.collapse(false);
+ getSelection().removeAllRanges();
+ getSelection().addRange(range);
+ const previous = calls.navigated;
+ editable.dispatchEvent(new KeyboardEvent("keydown", {key: "Enter", bubbles: true, cancelable: true}));
+ await entered;
+ check.equal(calls.navigated, previous);
+ check.equal(wysiwyg.querySelectorAll('[data-type="NodeListItem"]').length, 2, markdown);
+ editable.dispatchEvent(new KeyboardEvent("keydown", {key: "Tab", bubbles: true, cancelable: true}));
+ check.equal(calls.navigated, previous, "list Tab retains its indentation behavior");
+ }
+ wysiwyg.innerHTML = base.Md2BlockDOM("```go\nab\n```");
+ {
+ const editable = getContenteditableElement(wysiwyg);
+ const range = document.createRange();
+ range.setStart(editable.firstChild, 1);
+ range.collapse(true);
+ getSelection().removeAllRanges();
+ getSelection().addRange(range);
+ const previous = calls.navigated;
+ editable.dispatchEvent(new KeyboardEvent("keydown", {key: "Enter", bubbles: true, cancelable: true}));
+ await entered;
+ check.equal(calls.navigated, previous);
+ check.equal(wysiwyg.children.length, 1);
+ check.equal(getContenteditableElement(wysiwyg).textContent, "a\nb\n");
+ getContenteditableElement(wysiwyg).dispatchEvent(new KeyboardEvent("keydown", {key: "Tab", bubbles: true, cancelable: true}));
+ check.equal(calls.navigated, previous, "code Tab retains its indentation behavior");
+ }
for (const prefix of ["", "existing "]) {
const range = prepare(prefix + "/");
range.setStart(range.startContainer, prefix.length);
@@ -627,7 +740,9 @@ test("table cells insert code through slash and Enter without losing soft breaks
const source = ["longTextWrap.ts", "inlineElementBoundary.ts", "../toolbar/fontFamilyCore.ts", "../../util/escape.ts",
"tableVirtualizationDOM.ts", "../render/setLute.ts", "../wysiwyg/codeBlockUtil.ts", "../render/av/richTextValue.ts", "../render/av/richText.ts",
"../wysiwyg/taskListMarker.ts", "../wysiwyg/codeBlockEnter.ts", "tableCellRichLute.ts", "tableCellRichValue.ts",
- "tableCellRich.ts"].map(file => compile(read(file))).join("\n");
+ "tableCellRich.ts"].map(file => compile(read(file))).join("\n") +
+ "\nconst getTextWithoutSemanticMarkers = (() => {" + compile(read("inlineElementMarker.ts")) +
+ "\nreturn getTextWithoutSemanticMarkers;})();";
const hint = createSourceFile("hint.ts", read("../hint/index.ts"), ScriptTarget.Latest, true);
const hintClass = hint.statements.find(isClassDeclaration);
const fill = hintClass.members.find(member => isMethodDeclaration(member) && member.name.getText(hint) === "fill");
@@ -642,6 +757,14 @@ test("table cells insert code through slash and Enter without losing soft breaks
"\nbindLiteCodeActions(host, fragment.protyle, {signal, canEdit, beforeChange, onChange: commit});";
const selectionSource = compile(read("selectionOffsets.ts")) + "\n" + compile(read("selection.ts")) + "\n" + compile(read("tableCellRichSelection.ts"));
const highlightSource = compile(read("../render/highlightRender.ts"));
+ const extract = (file: string, names: string[]) => {
+ const parsed = createSourceFile(file, read(file), ScriptTarget.Latest, true);
+ return parsed.statements.filter(isVariableStatement).filter(statement =>
+ statement.declarationList.declarations.some(declaration => names.includes(declaration.name.getText(parsed))))
+ .map(statement => statement.getText(parsed)).join("\n");
+ };
+ const blockSource = compile(extract("../../block/util.ts", ["genEmptyElement", "genEmptyBlock"]) + "\n" +
+ extract("../wysiwyg/list.ts", ["genListItemElement"]));
const temporary = mkdtempSync(path.join(tmpdir(), "siyuan-table-cell-code-test-"));
const script = path.join(temporary, "run.cjs");
const lutePath = path.resolve(__dirname, "../../../stage/protyle/js/lute/lute.min.js");
@@ -655,7 +778,7 @@ app.whenReady().then(async () => {
await win.webContents.executeJavaScript(require("node:fs").readFileSync(${JSON.stringify(lutePath)}, "utf8"));
const result = await win.webContents.executeJavaScript(${JSON.stringify("const __name = value => value; (" +
browserCases.toString() + ")(" + [source, compile(read("../wysiwyg/enter.ts")), hintSource, keydownSource, copySource,
- selectionSource, highlightSource]
+ selectionSource, highlightSource, blockSource]
.map(value => JSON.stringify(value)).join(",") + ")")});
console.log(result);
win.destroy();
diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts
index 35eb725b6c..dd3ccb4e7a 100644
--- a/app/src/protyle/wysiwyg/index.ts
+++ b/app/src/protyle/wysiwyg/index.ts
@@ -45,7 +45,7 @@ import {
} from "../util/selection";
import {focusByRange, getSelectionOffset, setLastNodeRange} from "../util/selectionOffsets";
import {Constants} from "../../constants";
-import {mergeTableCellContents} from "../util/tableCellRich";
+import {getTableCellPlainText, mergeTableCellContents} from "../util/tableCellRich";
import {resolveDocumentBlockElement} from "../util/outlineBlock";
import {isMobile} from "../../util/functions";
import {previewDocImage} from "../preview/image";
@@ -2927,7 +2927,7 @@ export class WYSIWYG {
if (tableBlockElement) {
let textPlain = "";
selectedCellElements.forEach((item, index) => {
- textPlain += item.textContent.trim() + "\t";
+ textPlain += getTableCellPlainText(item).trim() + "\t";
if (!item.nextElementSibling || !selectedCellElements[index + 1] ||
item.nextElementSibling !== selectedCellElements[index + 1]) {
textPlain = textPlain.slice(0, -1) + "\n";