Skip to content

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

:bug: Correct tabbed container editing interactions https://github.com/siyuan-note/siyuan/issues/17642

Danielebeefc8ced02
diff --git a/app/src/assets/scss/protyle/_tabs.scss b/app/src/assets/scss/protyle/_tabs.scss
index 45ac373bc7..26d952de53 100644
--- a/app/src/assets/scss/protyle/_tabs.scss
+++ b/app/src/assets/scss/protyle/_tabs.scss
@@ -14,6 +14,7 @@
gap: 4px;
border-bottom: 1px solid var(--b3-border-color);
padding-bottom: 4px;
+ user-select: none;
}
.tabs-list {
@@ -58,6 +59,12 @@
pointer-events: none;
}
+ .tabs-control svg {
+ display: block;
+ width: 1em;
+ height: 1em;
+ }
+
.tab-item {
min-width: 0;
padding: 4px;
diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.ts
index a5b2db4dab..1332f8a05e 100644
--- a/app/src/protyle/gutter/index.ts
+++ b/app/src/protyle/gutter/index.ts
@@ -3721,8 +3721,10 @@ data-type="fold"${viewOccurrenceID ? ` data-view-occurrence-id="${encodeURICompo
while (previousBlock && !previousBlock.getAttribute("data-node-id")) {
previousBlock = previousBlock.previousElementSibling;
}
+ // 页签栏用于操作整个容器,正文区域的块标层级只显示到当前页签项。
+ const isTabItemBoundary = type === "NodeTabItem" && nodeElement.parentElement.classList.contains("tabs");
if ((previousBlock && previousBlock.getAttribute("data-node-id")) ||
- nodeElement.parentElement.classList.contains("callout-content")) {
+ nodeElement.parentElement.classList.contains("callout-content") || isTabItemBoundary) {
// 前一个块存在时,只显示到当前层级
hideParent = true;
// 由于折叠块的第二个子块在界面上不显示,因此移除块标 https://github.com/siyuan-note/siyuan/issues/14304
diff --git a/app/src/protyle/render/tabsRender.ts b/app/src/protyle/render/tabsRender.ts
index ea7b45b7f3..1214553aa1 100644
--- a/app/src/protyle/render/tabsRender.ts
+++ b/app/src/protyle/render/tabsRender.ts
@@ -6,7 +6,7 @@ export interface ITabsRenderOptions {
addLabel?: string;
menuLabel?: string;
select?: (tabs: HTMLElement, id: string) => void;
- edit?: (item: HTMLElement) => void;
+ rename?: (item: HTMLElement) => void;
add?: (tabs: HTMLElement) => void;
menu?: (tabs: HTMLElement, item: HTMLElement, anchor: HTMLElement) => void;
move?: (source: HTMLElement, target: HTMLElement, after?: boolean) => void;
@@ -142,9 +142,10 @@ export const tabsRender = (element: Element, options: ITabsRenderOptions = {}) =
header.setAttribute("contenteditable", "false");
if (!boundHeaders.has(header)) {
boundHeaders.add(header);
- ["pointerdown", "mousedown", "keydown"].forEach(type => {
+ ["pointerdown", "mousedown", "mouseup", "click", "keydown"].forEach(type => {
header.addEventListener(type, event => event.stopPropagation());
});
+ header.addEventListener("selectstart", event => event.preventDefault());
}
const signature = JSON.stringify([readonly, ...items.map(item => [itemID(item), getTabTitle(item)?.innerHTML])]);
if (state.signature !== signature || !header.firstElementChild) {
@@ -186,7 +187,7 @@ export const tabsRender = (element: Element, options: ITabsRenderOptions = {}) =
event.preventDefault();
event.stopPropagation();
if (!controller.options.readonly?.(tabs)) {
- controller.options.edit?.(item);
+ controller.options.rename?.(item);
}
});
button.addEventListener("contextmenu", event => {
@@ -255,7 +256,7 @@ export const tabsRender = (element: Element, options: ITabsRenderOptions = {}) =
const menu = document.createElement("button");
menu.type = "button";
menu.className = "tabs-control";
- menu.textContent = "...";
+ menu.innerHTML = '<svg><use xlink:href="#iconMore"></use></svg>';
menu.title = controller.options.menuLabel || "...";
menu.setAttribute("aria-label", menu.title);
menu.addEventListener("click", event => {
@@ -284,7 +285,11 @@ export const tabsRender = (element: Element, options: ITabsRenderOptions = {}) =
content.id = panelID;
content.setAttribute("role", "tabpanel");
content.setAttribute("aria-labelledby", button.id);
- content.tabIndex = 0;
+ if (readonly) {
+ content.tabIndex = 0;
+ } else {
+ content.removeAttribute("tabindex");
+ }
}
item.setAttribute("data-tabs-hidden", selected ? "false" : "true");
const title = getTabTitle(item);
diff --git a/app/src/protyle/wysiwyg/tabs.ts b/app/src/protyle/wysiwyg/tabs.ts
index 09665dd830..fcf26cab3c 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, focusByRange} from "../util/selection";
+import {focusBlock} from "../util/selection";
import {genEmptyElement, genSBElement} from "../../block/util";
import {Menu} from "../../plugin/Menu";
import {processRender} from "../util/processCode";
@@ -11,6 +11,8 @@ 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";
const canEdit = (protyle: IProtyle, element: Element) => !protyle.disabled &&
!protyle.options.action.includes(Constants.CB_GET_HISTORY) && !element.closest(".protyle-wysiwyg__embed");
@@ -36,19 +38,39 @@ const newTab = (protyle: IProtyle) => {
return template.content.querySelector<HTMLElement>(".tab-item");
};
-export const editTabTitle = (protyle: IProtyle, item: HTMLElement) => {
+export const renameTab = (protyle: IProtyle, item: HTMLElement) => {
if (!canEdit(protyle, item)) {
return;
}
revealTabAncestors(protyle.wysiwyg.element, item);
- protyle.wysiwyg.lastHTMLs[item.dataset.nodeId] = item.outerHTML;
- item.dataset.tabsEditing = "true";
const title = getTabTitle(item);
- title.setAttribute("contenteditable", "true");
- const range = document.createRange();
- range.selectNodeContents(title);
- title.focus();
- focusByRange(range);
+ const initialTitle = title.textContent || "";
+ 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.textContent = 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 addTab = (protyle: IProtyle, tabs: HTMLElement) => {
@@ -57,7 +79,7 @@ const addTab = (protyle: IProtyle, tabs: HTMLElement) => {
tabs.insertBefore(item, tabs.querySelector(":scope > .protyle-attr"));
tabs.setAttribute("tabs-active-id", item.dataset.nodeId);
});
- editTabTitle(protyle, item);
+ renameTab(protyle, item);
};
export const moveTab = (protyle: IProtyle, source: HTMLElement, target: HTMLElement, after = false) => {
@@ -111,7 +133,7 @@ export const openTabsMenu = (protyle: IProtyle, tabs: HTMLElement, item: HTMLEle
}
const lang = window.siyuan.languages;
const menu = new Menu();
- menu.addItem({icon: "iconEdit", label: lang.edit, click: () => editTabTitle(protyle, item)});
+ menu.addItem({icon: "iconEdit", label: lang.rename, click: () => renameTab(protyle, item)});
menu.addItem({icon: "iconAdd", label: lang.tabItem, click: () => addTab(protyle, tabs)});
const siblings = getTabItems(tabs);
const index = siblings.indexOf(item);
@@ -178,7 +200,7 @@ export const initEditorTabs = (protyle: IProtyle) => {
}));
}
},
- edit: item => editTabTitle(protyle, item),
+ rename: item => renameTab(protyle, item),
add: tabs => addTab(protyle, tabs),
menu: (tabs, item, anchor) => openTabsMenu(protyle, tabs, item, anchor),
move: (source, target, after) => moveTab(protyle, source, target, after),