Skip to content

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

:bug: Preserve tab title selection when applying inline formatting

Daniel8190a04cbdae
diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.ts
index a74727d131..3b7ac9e3b1 100644
--- a/app/src/protyle/toolbar/index.ts
+++ b/app/src/protyle/toolbar/index.ts
@@ -179,6 +179,21 @@ export class Toolbar {
const element = document.createElement("div");
element.className = "protyle-toolbar fn__none";
this.element = element;
+ element.addEventListener("mousedown", event => {
+ const range = this.range;
+ if (!range || range.collapsed || !(event.target as Element).closest("button")) {
+ return;
+ }
+ const start = range.startContainer.nodeType === Node.ELEMENT_NODE ?
+ range.startContainer as Element : range.startContainer.parentElement;
+ const end = range.endContainer.nodeType === Node.ELEMENT_NODE ?
+ range.endContainer as Element : range.endContainer.parentElement;
+ const title = start?.closest(".tab-item-info");
+ // 点击格式按钮时保留页签标题焦点,避免选区在 click 前因失焦而消失。
+ if (title && title === end?.closest(".tab-item-info")) {
+ event.preventDefault();
+ }
+ });
this.subElement = document.createElement("div");
/// #if MOBILE
this.subElement.className = "protyle-util fn__none protyle-util--mobile";