An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:sparkles: Support inline rich text editing of tab titles https://github.com/siyuan-note/siyuan/issues/17642
Daniel63f510dd1a01
diff --git a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-6yi0dv5/20200924101225-k254i8g.sy b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-6yi0dv5/20200924101225-k254i8g.syindex b10c5f5736..3d994b9210 100644--- a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-6yi0dv5/20200924101225-k254i8g.sy+++ b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-6yi0dv5/20200924101225-k254i8g.sy@@ -6,7 +6,7 @@"id": "20200924101225-k254i8g","title": "Content Block Type","type": "doc",- "updated": "20260906003609"+ "updated": "20260906013806"},"Children": [{@@ -1336,7 +1336,7 @@"HeadingLevel": 2,"Properties": {"id": "20210104091538-a55chyw",- "updated": "20260906003122"+ "updated": "20260906013806"},"Children": [{@@ -2696,7 +2696,7 @@"Type": "NodeHeading","Properties": {"id": "20260905124213-wbxn79t",- "updated": "20260906003122"+ "updated": "20260906013806"},"HeadingLevel": 3,"Children": [@@ -2786,12 +2786,12 @@"Type": "NodeParagraph","Properties": {"id": "20260906003122-knct56j",- "updated": "20260906003122"+ "updated": "20260906013806"},"Children": [{"Type": "NodeText",- "Data": "Type / and choose the tabs block to create a group. Use + to add tabs and the more menu to manage tabs and their layout. Double-click a title or use Rename to edit it. Renaming supports Markdown such as **bold**. Existing colors and other styles appear as Kramdown source; edit the text while keeping the style markup to preserve formatting."+ "Data": "Type / and choose the tabs block to create a group. Use + to add tabs and the more menu to adjust the layout. Double-click a title or use Rename to edit the text directly in the tab. Like callout titles, tab titles support WYSIWYG editing: use the inline toolbar to apply bold, colors, and other styles while preserving existing formatting as you edit the text."}]},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.syindex 31b634a966..2b69470d21 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": "20260905124213"+ "updated": "20260906013806"},"Children": [{@@ -3987,7 +3987,7 @@"HeadingLevel": 2,"Properties": {"id": "20210106154056-koo4wdj",- "updated": "20260905124213"+ "updated": "20260906013806"},"Children": [{@@ -13264,7 +13264,7 @@"Type": "NodeHeading","Properties": {"id": "20260905124213-pfrny4c",- "updated": "20260905124213"+ "updated": "20260906013806"},"HeadingLevel": 3,"Children": [@@ -13279,12 +13279,34 @@"Type": "NodeParagraph","Properties": {"id": "20260905124213-dh6bex8",- "updated": "20260905124213"+ "updated": "20260906013806"},"Children": [{"Type": "NodeText","Data": "When the tab bar has focus, Left and Right move focus between top tabs; Up and Down move focus between left tabs. Arrow keys in the content keep their normal editing behavior."+ },+ {+ "Type": "NodeText",+ "Data": " While editing a tab title, press "+ },+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Enter"+ },+ {+ "Type": "NodeText",+ "Data": " or "+ },+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Tab"+ },+ {+ "Type": "NodeText",+ "Data": " to finish editing and move to the content. Clicking the content also ends title editing."}]},diff --git a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-fqgskfj/20200905090211-2vixtlf.sy b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-fqgskfj/20200905090211-2vixtlf.syindex 9ecb9a895b..61e9a4eff3 100644--- a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-fqgskfj/20200905090211-2vixtlf.sy+++ b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-fqgskfj/20200905090211-2vixtlf.sy@@ -6,7 +6,7 @@"id": "20200905090211-2vixtlf","title": "内容块类型","type": "doc",- "updated": "20260906003609"+ "updated": "20260906013806"},"Children": [{@@ -1369,7 +1369,7 @@"HeadingLevel": 2,"Properties": {"id": "20210104090624-9qgquxh",- "updated": "20260906003122"+ "updated": "20260906013806"},"Children": [{@@ -2778,7 +2778,7 @@"Type": "NodeHeading","Properties": {"id": "20260905124213-9etkynq",- "updated": "20260906003122"+ "updated": "20260906013806"},"HeadingLevel": 3,"Children": [@@ -2868,12 +2868,12 @@"Type": "NodeParagraph","Properties": {"id": "20260906003122-812ct16",- "updated": "20260906003122"+ "updated": "20260906013806"},"Children": [{"Type": "NodeText",- "Data": "输入 / 并选择页签块可创建一组页签。通过 + 添加页签,通过更多菜单管理页签及布局。双击标题或使用重命名菜单修改标题。重命名支持 **加粗** 等 Markdown;已有颜色等样式会显示为 Kramdown 源码,修改其中的文字并保留样式标记即可保留格式。"+ "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.syindex 063040602c..1626742872 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": "20260905124213"+ "updated": "20260906013806"},"Children": [{@@ -3985,7 +3985,7 @@"HeadingLevel": 2,"Properties": {"id": "20201227133317-rkh4bji",- "updated": "20260905124213"+ "updated": "20260906013806"},"Children": [{@@ -13250,7 +13250,7 @@"Type": "NodeHeading","Properties": {"id": "20260905124213-avhukx7",- "updated": "20260905124213"+ "updated": "20260906013806"},"HeadingLevel": 3,"Children": [@@ -13265,12 +13265,34 @@"Type": "NodeParagraph","Properties": {"id": "20260905124213-w4xwhs9",- "updated": "20260905124213"+ "updated": "20260906013806"},"Children": [{"Type": "NodeText","Data": "页签栏获得焦点时,左右方向键移动顶部页签的焦点,上下方向键移动左侧页签的焦点;正文中的方向键保持文本编辑行为。"+ },+ {+ "Type": "NodeText",+ "Data": "编辑页签标题时,按 "+ },+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Enter"+ },+ {+ "Type": "NodeText",+ "Data": " 或 "+ },+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Tab"+ },+ {+ "Type": "NodeText",+ "Data": " 结束编辑并进入正文;点击正文也可结束编辑。"}]},diff --git a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226115825-mhcslw2/20211226120147-ib6yy3i.sy b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226115825-mhcslw2/20211226120147-ib6yy3i.syindex e1d999f53e..66dd734770 100644--- a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226115825-mhcslw2/20211226120147-ib6yy3i.sy+++ b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226115825-mhcslw2/20211226120147-ib6yy3i.sy@@ -6,7 +6,7 @@"id": "20211226120147-ib6yy3i","title": "內容區塊類型","type": "doc",- "updated": "20260906003609"+ "updated": "20260906013806"},"Children": [{@@ -1365,7 +1365,7 @@"HeadingLevel": 2,"Properties": {"id": "20211226120227-esm6f20",- "updated": "20260906003122"+ "updated": "20260906013806"},"Children": [{@@ -2696,7 +2696,7 @@"Type": "NodeHeading","Properties": {"id": "20260905124213-371qsy7",- "updated": "20260906003122"+ "updated": "20260906013806"},"HeadingLevel": 3,"Children": [@@ -2786,12 +2786,12 @@"Type": "NodeParagraph","Properties": {"id": "20260906003122-0jlwsyi",- "updated": "20260906003122"+ "updated": "20260906013806"},"Children": [{"Type": "NodeText",- "Data": "輸入 / 並選擇頁籤區塊可建立一組頁籤。透過 + 新增頁籤,透過更多選單管理頁籤及配置。按兩下標題或使用重新命名選單修改標題。重新命名支援 **粗體** 等 Markdown;已有顏色等樣式會顯示為 Kramdown 原始碼,修改其中的文字並保留樣式標記即可保留格式。"+ "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.syindex 87ed2d5f6a..fc99b26258 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": "20260905124213"+ "updated": "20260906013806"},"Children": [{@@ -3979,7 +3979,7 @@"HeadingLevel": 2,"Properties": {"id": "20211226122652-htptsmh",- "updated": "20260905124213"+ "updated": "20260906013806"},"Children": [{@@ -13256,7 +13256,7 @@"Type": "NodeHeading","Properties": {"id": "20260905124213-degzfbw",- "updated": "20260905124213"+ "updated": "20260906013806"},"HeadingLevel": 3,"Children": [@@ -13271,12 +13271,34 @@"Type": "NodeParagraph","Properties": {"id": "20260905124213-z6l8pda",- "updated": "20260905124213"+ "updated": "20260906013806"},"Children": [{"Type": "NodeText","Data": "頁籤列取得焦點時,左右方向鍵移動頂部頁籤的焦點,上下方向鍵移動左側頁籤的焦點;內文中的方向鍵維持文字編輯行為。"+ },+ {+ "Type": "NodeText",+ "Data": "編輯頁籤標題時,按 "+ },+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Enter"+ },+ {+ "Type": "NodeText",+ "Data": " 或 "+ },+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Tab"+ },+ {+ "Type": "NodeText",+ "Data": " 結束編輯並進入內文;點擊內文也可結束編輯。"}]},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.syindex aa0b9c2f4c..94631ff920 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": "20260905124213"+ "updated": "20260906013806"},"Children": [{@@ -3949,7 +3949,7 @@"Properties": {"ID": "20240530101000-twmuxke","id": "20240530101000-675gu9g",- "updated": "20260905124213"+ "updated": "20260906013806"},"Children": [{@@ -13237,7 +13237,7 @@"Type": "NodeHeading","Properties": {"id": "20260905124213-unrfwm9",- "updated": "20260905124213"+ "updated": "20260906013806"},"HeadingLevel": 3,"Children": [@@ -13252,12 +13252,34 @@"Type": "NodeParagraph","Properties": {"id": "20260905124213-fem82m0",- "updated": "20260905124213"+ "updated": "20260906013806"},"Children": [{"Type": "NodeText","Data": "タブバーにフォーカスがあるとき、左右の矢印キーで上部タブ、上下の矢印キーで左側タブのフォーカスを移動します。本文では通常のテキスト編集として動作します。"+ },+ {+ "Type": "NodeText",+ "Data": "タブのタイトルを編集中に "+ },+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Enter"+ },+ {+ "Type": "NodeText",+ "Data": " または "+ },+ {+ "Type": "NodeTextMark",+ "TextMarkType": "kbd",+ "TextMarkTextContent": "Tab"+ },+ {+ "Type": "NodeText",+ "Data": " を押すと編集を終了して本文に移動します。本文をクリックしてもタイトルの編集を終了できます。"}]},diff --git a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-gvtksyj/20240530101000-35bbvcx.sy b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-gvtksyj/20240530101000-35bbvcx.syindex 881a4693ff..0d3c4ba387 100644--- a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-gvtksyj/20240530101000-35bbvcx.sy+++ b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-gvtksyj/20240530101000-35bbvcx.sy@@ -7,7 +7,7 @@"id": "20240530101000-35bbvcx","title": "コンテンツブロックの種類","type": "doc",- "updated": "20260906003609"+ "updated": "20260906013806"},"Children": [{@@ -1422,7 +1422,7 @@"Properties": {"ID": "20240530101000-rjjxxn8","id": "20240530101000-p035stn",- "updated": "20260906003122"+ "updated": "20260906013806"},"Children": [{@@ -2890,7 +2890,7 @@"Type": "NodeHeading","Properties": {"id": "20260905124213-rmj1ui2",- "updated": "20260906003122"+ "updated": "20260906013806"},"HeadingLevel": 3,"Children": [@@ -2980,12 +2980,12 @@"Type": "NodeParagraph","Properties": {"id": "20260906003122-om7wyo8",- "updated": "20260906003122"+ "updated": "20260906013806"},"Children": [{"Type": "NodeText",- "Data": "/ を入力してタブブロックを選択すると、タブのグループを作成できます。+ でタブを追加し、その他メニューでタブや配置を管理します。タイトルのダブルクリックまたは名前変更メニューで編集できます。**太字** などの Markdown に対応しています。文字色などの既存のスタイルは Kramdown ソースで表示されるため、書式を残すにはスタイルの記述を保ったまま文字を変更してください。"+ "Data": "/ を入力してタブブロックを選択すると、タブのグループを作成できます。+ でタブを追加し、その他メニューで配置を調整します。タイトルをダブルクリックするか名前変更メニューを使うと、タブのタイトルをその場で直接編集できます。コールアウトのタイトルと同様に、見たままの状態で編集でき、インラインツールバーから太字や文字色などを設定できます。文字を変更しても既存の書式は保持されます。"}]},diff --git a/app/src/assets/scss/protyle/_tabs.scss b/app/src/assets/scss/protyle/_tabs.scssindex f1e5e07e8e..a125482064 100644--- a/app/src/assets/scss/protyle/_tabs.scss+++ b/app/src/assets/scss/protyle/_tabs.scss@@ -111,6 +111,57 @@min-width: 0;}+ .tabs-tab--editing > .tabs-tab-label {+ visibility: hidden;+ }++ .tabs-title-editor {+ position: absolute;+ z-index: 1;+ box-sizing: border-box;+ display: flex;+ align-items: center;+ padding: 0 8px;+ border-radius: var(--b3-border-radius);+ background: var(--b3-theme-primary-lightest);+ color: var(--b3-theme-on-background);+ box-shadow: 0 0 0 1px var(--b3-theme-primary-lighter) inset;+ font-size: 87.5%;+ line-height: 22px;+ user-select: text;++ > [tabs-title] {+ margin: 0;+ padding: 0;+ min-width: 0;+ width: 100%;++ > .protyle-attr {+ display: none;+ }+ }++ .tab-item-title[spellcheck] {+ margin: 0;+ min-width: 0;+ width: 100%;+ min-height: 22px;+ font-weight: normal;+ white-space: nowrap;+ word-break: normal;+ overflow-x: auto;+ scrollbar-width: none;++ &::-webkit-scrollbar {+ display: none;+ }++ br {+ display: none;+ }+ }+ }+.tabs[data-tabs-ready="true"] {> .tabs-header {display: flex;@@ -165,6 +216,27 @@> .tab-item[data-tabs-hidden], > .tab-item > .tab-item-info {display: block !important;}++ > .tab-item > .tabs-title-editor {+ position: static;+ width: auto !important;+ height: auto !important;+ clip-path: none !important;+ padding: 0;+ background: transparent;+ box-shadow: none;+ font-size: inherit;++ .tab-item-title[spellcheck] {+ font-weight: bold;+ white-space: normal;+ overflow: visible;++ br {+ display: initial;+ }+ }+ }}}}diff --git a/app/src/protyle/render/tabsRender.ts b/app/src/protyle/render/tabsRender.tsindex 01fb2d8497..72904a8d4d 100644--- a/app/src/protyle/render/tabsRender.ts+++ b/app/src/protyle/render/tabsRender.ts@@ -76,6 +76,7 @@ export const tabsRender = (element: Element, options: ITabsRenderOptions = {}) =];let scheduled = false;let destroyed = false;+ const sizes = new WeakMap<Element, string>();const schedule = () => {if (scheduled || destroyed) {return;@@ -88,6 +89,31 @@ export const tabsRender = (element: Element, options: ITabsRenderOptions = {}) =}});};+ const endTitleEditing = () => {+ const selection = window.getSelection();+ const active = document.activeElement;+ // 工具栏及其弹窗继续使用标题选区,不结束正在进行的富文本编辑。+ if (active?.closest(".protyle-toolbar, .protyle-util, .b3-menu, .b3-dialog")) {+ return;+ }+ let changed = false;+ element.querySelectorAll<HTMLElement>('.tab-item[data-tabs-editing="true"]').forEach(item => {+ const title = getTabTitle(item);+ const selectionInTitle = title?.contains(selection?.anchorNode) &&+ (active === element || element.contains(active));+ if (title && !title.contains(active) && !selectionInTitle) {+ item.dataset.tabsEditing = "false";+ changed = true;+ }+ });+ if (changed) {+ schedule();+ }+ };+ const onFocusOut = () => queueMicrotask(() => {+ endTitleEditing();+ schedule();+ });const controller: ITabsRoot = {options,select(tabs, id, persist) {@@ -95,6 +121,9 @@ export const tabsRender = (element: Element, options: ITabsRenderOptions = {}) =if (!state || !getTabItems(tabs).some(item => itemID(item) === id)) {return;}+ if (state.active !== id) {+ getTabItems(tabs).forEach(item => item.dataset.tabsEditing = "false");+ }state.active = id;state.pending = undefined;if (persist && !controller.options.readonly?.(tabs)) {@@ -154,7 +183,8 @@ export const tabsRender = (element: Element, options: ITabsRenderOptions = {}) =});header.addEventListener("selectstart", event => event.preventDefault());}- const signature = JSON.stringify([readonly, ...items.map(item => [itemID(item), getTabTitle(item)?.innerHTML])]);+ const signature = JSON.stringify([readonly, ...items.map(item => [itemID(item),+ item.dataset.tabsEditing === "true" ? null : getTabTitle(item)?.innerHTML])]);if (state.signature !== signature || !header.firstElementChild) {const focusedID = (document.activeElement as HTMLElement)?.dataset?.tabId;header.replaceChildren();@@ -165,7 +195,8 @@ export const tabsRender = (element: Element, options: ITabsRenderOptions = {}) =header.appendChild(list);bindTabsDrag(list, {tabs,- readonly: () => (controller.options.readonly?.(tabs) ?? true) || !controller.options.move,+ readonly: () => (controller.options.readonly?.(tabs) ?? true) || !controller.options.move ||+ getTabItems(tabs).some(item => item.dataset.tabsEditing === "true"),move: (source, target, after) => controller.options.move?.(source, target, after),render: schedule,});@@ -182,9 +213,11 @@ export const tabsRender = (element: Element, options: ITabsRenderOptions = {}) =const clone = title.cloneNode(true) as HTMLElement;clone.className = "tabs-tab-label";clone.removeAttribute("contenteditable");+ clone.removeAttribute("spellcheck");clone.querySelectorAll("br").forEach(br => br.replaceWith(" "));- clone.querySelectorAll("[contenteditable], [id], [data-node-id]").forEach(child => {+ clone.querySelectorAll("[contenteditable], [spellcheck], [id], [data-node-id]").forEach(child => {child.removeAttribute("contenteditable");+ child.removeAttribute("spellcheck");child.removeAttribute("id");child.removeAttribute("data-node-id");});@@ -263,6 +296,9 @@ export const tabsRender = (element: Element, options: ITabsRenderOptions = {}) =const list = header.querySelector<HTMLElement>(".tabs-list");list.setAttribute("aria-orientation", vertical ? "vertical" : "horizontal");items.forEach((item, index) => {+ if (readonly) {+ item.dataset.tabsEditing = "false";+ }const selected = itemID(item) === state.active;const button = list.children[index] as HTMLElement;const panelID = `${state.instance}-panel-${index}`;@@ -286,8 +322,38 @@ export const tabsRender = (element: Element, options: ITabsRenderOptions = {}) =if (title && !readonly && item.dataset.tabsEditing === "true") {title.setAttribute("contenteditable", "true");}+ const editing = !readonly && selected && item.dataset.tabsEditing === "true";+ button.classList.toggle("tabs-tab--editing", editing);+ button.draggable = !readonly && !editing && !!controller.options.move;+ const info = item.querySelector<HTMLElement>(":scope > .tab-item-info");+ if (info) {+ info.classList.toggle("tabs-title-editor", editing);+ if (!editing) {+ info.removeAttribute("style");+ }+ }});tabs.setAttribute("data-tabs-ready", "true");+ items.forEach((item, index) => {+ const info = item.querySelector<HTMLElement>(":scope > .tabs-title-editor");+ if (!info) {+ return;+ }+ // 原始标题保留在页签项内,仅将显示位置对齐到导航标签,沿用块编辑和撤销事务。+ const button = list.children[index] as HTMLElement;+ const rect = button.getBoundingClientRect();+ const parentRect = item.getBoundingClientRect();+ const listRect = list.getBoundingClientRect();+ const scale = parentRect.width ? item.offsetWidth / parentRect.width : 1;+ info.style.left = `${(rect.left - parentRect.left) * scale - item.clientLeft}px`;+ info.style.top = `${(rect.top - parentRect.top) * scale - item.clientTop}px`;+ info.style.width = `${rect.width * scale}px`;+ info.style.height = `${rect.height * scale}px`;+ info.style.clipPath = `inset(${Math.max(0, listRect.top - rect.top) * scale}px ` ++ `${Math.max(0, rect.right - listRect.right) * scale}px ` ++ `${Math.max(0, rect.bottom - listRect.bottom) * scale}px ` ++ `${Math.max(0, listRect.left - rect.left) * scale}px)`;+ });list.querySelectorAll<HTMLElement>(".tabs-tab-label").forEach(label => {label.parentElement.classList.toggle("ariaLabel", label.scrollWidth > label.clientWidth);});@@ -314,18 +380,35 @@ export const tabsRender = (element: Element, options: ITabsRenderOptions = {}) =shown.forEach(item => controller.options.shown?.(item));},observer: new MutationObserver(schedule),- resize: new ResizeObserver(schedule),+ resize: new ResizeObserver(entries => {+ let changed = false;+ entries.forEach(entry => {+ const target = entry.target as HTMLElement;+ const size = `${target.clientWidth}:${target.clientHeight}`;+ if (sizes.get(target) !== size) {+ sizes.set(target, size);+ changed = true;+ }+ });+ if (changed) {+ schedule();+ }+ }),destroy() {cancelTabsDrag(element);destroyed = true;controller.observer.disconnect();controller.resize.disconnect();- element.removeEventListener("focusout", schedule);+ element.removeEventListener("focusout", onFocusOut);+ element.removeEventListener("scroll", schedule, true);+ document.removeEventListener("selectionchange", endTitleEditing);roots.delete(element);},};roots.set(element, controller);- element.addEventListener("focusout", schedule);+ element.addEventListener("focusout", onFocusOut);+ element.addEventListener("scroll", schedule, true);+ document.addEventListener("selectionchange", endTitleEditing);controller.render();};diff --git a/app/src/protyle/wysiwyg/tabs.ts b/app/src/protyle/wysiwyg/tabs.tsindex 1b39e381ba..0e54af0fae 100644--- a/app/src/protyle/wysiwyg/tabs.ts+++ b/app/src/protyle/wysiwyg/tabs.ts@@ -3,7 +3,7 @@ import {repairActiveTab} from "./tabsRemoval";import {transaction} from "./transaction";import {Constants} from "../../constants";import {fetchPost} from "../../util/fetch";-import {focusBlock} from "../util/selection";+import {focusBlock, focusByRange} from "../util/selection";import {genEmptyElement, genSBElement} from "../../block/util";import {Menu} from "../../plugin/Menu";import {processRender} from "../util/processCode";@@ -11,9 +11,6 @@ import {avRender} from "../render/av/render";import {isHiddenTabContent} from "../render/tabsVisibility";import {queueTransaction} from "../util/transactionQueue";import {remapTabsDOMIDs} from "../util/tabsCopy";-import {Dialog} from "../../dialog";-import {isMobile} from "../../util/functions";-import {getTabsTitleMarkdown, renderTabsTitleMarkdown} from "./tabsTitle";const canEdit = (protyle: IProtyle, element: Element) => !protyle.disabled &&!protyle.options.action.includes(Constants.CB_GET_HISTORY) && !element.closest(".protyle-wysiwyg__embed");@@ -44,34 +41,13 @@ export const renameTab = (protyle: IProtyle, item: HTMLElement) => {return;}revealTabAncestors(protyle.wysiwyg.element, item);+ item.dataset.tabsEditing = "true";+ initEditorTabs(protyle);const title = getTabTitle(item);- const initialTitle = getTabsTitleMarkdown(protyle.lute, title);- const dialog = new Dialog({- title: window.siyuan.languages.rename,- content: `<div class="b3-dialog__content"><input class="b3-text-field fn__block"></div>-<div class="b3-dialog__action">- <button class="b3-button b3-button--cancel">${window.siyuan.languages.cancel}</button><div class="fn__space"></div>- <button class="b3-button b3-button--text">${window.siyuan.languages.confirm}</button>-</div>`,- width: isMobile() ? "92vw" : "520px",- });- const input = dialog.element.querySelector("input") as HTMLInputElement;- const buttons = dialog.element.querySelectorAll<HTMLButtonElement>(".b3-button");- const confirm = () => {- const value = input.value.trim();- if (value !== initialTitle) {- changeTabs(protyle, [item.parentElement], () => {- title.innerHTML = renderTabsTitleMarkdown(protyle.lute, value);- });- }- dialog.destroy();- };- dialog.bindInput(input, confirm);- input.value = initialTitle;- input.focus();- input.select();- buttons[0].addEventListener("click", () => dialog.destroy());- buttons[1].addEventListener("click", confirm);+ const range = document.createRange();+ range.selectNodeContents(title);+ title.focus();+ focusByRange(range);};const addTab = (protyle: IProtyle, tabs: HTMLElement) => {@@ -214,10 +190,4 @@ export const initEditorTabs = (protyle: IProtyle) => {protyle.contentElement?.dispatchEvent(new Event("scroll"));}),});- root.addEventListener("focusout", event => {- const title = (event.target as Element).closest(".tab-item-title");- if (title && !title.contains(event.relatedTarget as Node)) {- title.closest<HTMLElement>(".tab-item").dataset.tabsEditing = "false";- }- });};diff --git a/app/src/protyle/wysiwyg/tabsTitle.test.ts b/app/src/protyle/wysiwyg/tabsTitle.test.tsdeleted file mode 100644index 88add5f5c1..0000000000--- a/app/src/protyle/wysiwyg/tabsTitle.test.ts+++ /dev/null@@ -1,70 +0,0 @@-import * as assert from "node:assert/strict";-import {test} from "node:test";-import {getTabsTitleMarkdown, renderTabsTitleMarkdown} from "./tabsTitle";--test("serializes the existing tab title as Markdown", () => {- assert.equal(getTabsTitleMarkdown({- BlockDOM2Md: () => "",- BlockDOM2StdMd: html => html === '<span data-type="strong">foo</span>' ? "**foo**\n" : "",- InlineMd2BlockDOM: () => "",- Md2BlockDOM: () => "",- }, {- innerHTML: '<span data-type="strong">foo</span>',- querySelector: (): Element | null => null,- } as unknown as HTMLElement), "**foo**");-});--test("serializes combined font styles as reversible Kramdown", () => {- const markdown = '<span data-type="strong text">foo</span>{: style="color: red;"}';- assert.equal(getTabsTitleMarkdown({- BlockDOM2Md: html => html.includes('data-type="strong text"') ? markdown + "\n" : "",- BlockDOM2StdMd: () => {- throw new Error("unexpected standard Markdown serializer");- },- InlineMd2BlockDOM: () => "",- Md2BlockDOM: () => "",- }, {- innerHTML: '<span data-type="strong text" style="color: red;">foo</span>',- querySelector: (selector: string): Element | null =>- selector === "span[style]" ? {} as Element : null,- } as unknown as HTMLElement), markdown);-});--test("parses regular inline Markdown without block interpretation", () => {- let inline = "";- const html = renderTabsTitleMarkdown({- BlockDOM2Md: () => "",- BlockDOM2StdMd: () => "",- InlineMd2BlockDOM: markdown => {- inline = markdown;- return '<div data-type="NodeParagraph"><div contenteditable="true"><span data-type="strong">foo</span></div></div>';- },- Md2BlockDOM: () => {- throw new Error("unexpected block parser");- },- }, "**foo**", {- content: {querySelector: () => ({innerHTML: '<span data-type="strong">foo</span>'})},- } as unknown as HTMLTemplateElement);- assert.equal(inline, "**foo**");- assert.equal(html, '<span data-type="strong">foo</span>');-});--test("restores serialized combined font styles with the block Markdown parser", () => {- const markdown = '<span data-type="strong text">foo</span>{: style="color: red;"}';- let block = "";- const html = renderTabsTitleMarkdown({- BlockDOM2Md: () => "",- BlockDOM2StdMd: () => "",- InlineMd2BlockDOM: () => {- throw new Error("unexpected inline parser");- },- Md2BlockDOM: value => {- block = value;- return '<div data-type="NodeParagraph"><div contenteditable="true"><span data-type="strong text" style="color: red;">foo</span></div></div>';- },- }, markdown, {- content: {querySelector: () => ({innerHTML: '<span data-type="strong text" style="color: red;">foo</span>'})},- } as unknown as HTMLTemplateElement);- assert.equal(block, markdown + "\n");- assert.equal(html, '<span data-type="strong text" style="color: red;">foo</span>');-});diff --git a/app/src/protyle/wysiwyg/tabsTitle.ts b/app/src/protyle/wysiwyg/tabsTitle.tsdeleted file mode 100644index 7ab4437baa..0000000000--- a/app/src/protyle/wysiwyg/tabsTitle.ts+++ /dev/null@@ -1,23 +0,0 @@-interface ITabsTitleLute {- BlockDOM2Md(html: string): string;- BlockDOM2StdMd(html: string): string;- InlineMd2BlockDOM(markdown: string): string;- Md2BlockDOM(markdown: string): string;-}--export const getTabsTitleMarkdown = (lute: ITabsTitleLute, title: HTMLElement) => {- // 标准 Markdown 会丢弃 strong text 等组合文本标记上的字体样式,含样式时使用可逆的 Kramdown。- const serialize = title.querySelector("span[style]") ?- lute.BlockDOM2Md.bind(lute) : lute.BlockDOM2StdMd.bind(lute);- return serialize(title.innerHTML).trim();-};--export const renderTabsTitleMarkdown = (lute: ITabsTitleLute, markdown: string,- template = document.createElement("template")) => {- // 字体颜色等文本标记使用带 span 属性的 Kramdown,块解析器可将其还原为原文本标记。- const hasKramdownStyle = /<span\b[^>]*\bdata-type=["'][^"']*\btext\b/i.test(markdown) ||- /\{:\s*style\s*=/.test(markdown);- template.innerHTML = hasKramdownStyle ?- lute.Md2BlockDOM(markdown + "\n") : lute.InlineMd2BlockDOM(markdown);- return template.content.querySelector<HTMLElement>('[contenteditable="true"]')?.innerHTML || "";-};