An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Continuous format painter menu closes immediately https://github.com/siyuan-note/siyuan/issues/12732
Danield2746e9b3175
diff --git a/app/src/assets/scss/protyle/_toolbar.scss b/app/src/assets/scss/protyle/_toolbar.scssindex 50caa45bb5..d2e7e2751f 100644--- a/app/src/assets/scss/protyle/_toolbar.scss+++ b/app/src/assets/scss/protyle/_toolbar.scss@@ -61,10 +61,22 @@&__format-painter {display: flex;+ > .protyle-toolbar__item {+ border-radius: 0;+ }+> .protyle-toolbar__item:first-child {padding-right: 4px;}+ &:first-child > .protyle-toolbar__item:first-child {+ border-radius: var(--b3-border-radius) 0 0 var(--b3-border-radius);+ }++ &:last-child > .protyle-toolbar__item:last-child {+ border-radius: 0 var(--b3-border-radius) var(--b3-border-radius) 0;+ }+&-menu {padding: 1px 3px 1px 0;diff --git a/app/src/protyle/toolbar/FormatPainter.ts b/app/src/protyle/toolbar/FormatPainter.tsindex 145888d605..ea0e4e95a0 100644--- a/app/src/protyle/toolbar/FormatPainter.ts+++ b/app/src/protyle/toolbar/FormatPainter.ts@@ -7,10 +7,10 @@ import {IFormatPainterSegment,IFormatPainterSnapshot,IFormatPainterStyle,+ shouldKeepFormatPainterActive,+ TFormatPainterMode,} from "./formatPainterCore";-export type TFormatPainterMode = "once" | "continuous";-const getSegment = (textNode: Text, editableElement: Element) => {const types: string[] = [];const styles: IFormatPainterStyle = {};@@ -95,7 +95,7 @@ class FormatPainterController {}const paintedRange = protyle.toolbar.range;protyle.toolbar.element.classList.add("fn__none");- if (this.mode === "once") {+ if (!shouldKeepFormatPainterActive(this.mode)) {this.deactivate();}return paintedRange;@@ -167,6 +167,7 @@ export class FormatPainter {const menuElement = document.createElement("button");menuElement.className = "protyle-toolbar__item protyle-toolbar__format-painter-menu " +"b3-tooltips b3-tooltips__n";+ menuElement.setAttribute("data-menu", "true");menuElement.setAttribute("aria-label", window.siyuan.languages.formatPainterContinuous);menuElement.innerHTML = '<svg><use xlink:href="#iconDown"></use></svg>';menuElement.addEventListener("mousedown", event => event.preventDefault());@@ -176,7 +177,9 @@ export class FormatPainter {window.siyuan.menus.menu.append(new MenuItem({icon: "iconFormat",label: window.siyuan.languages.formatPainterContinuous,- click: () => formatPainter.activate(protyle, "continuous"),+ click: () => {+ formatPainter.activate(protyle, "continuous");+ },}).element);const rect = menuElement.getBoundingClientRect();window.siyuan.menus.menu.popup({x: rect.left, y: rect.bottom, h: rect.height});diff --git a/app/src/protyle/toolbar/formatPainter.test.ts b/app/src/protyle/toolbar/formatPainter.test.tsindex 29a9bf7266..8671919fa4 100644--- a/app/src/protyle/toolbar/formatPainter.test.ts+++ b/app/src/protyle/toolbar/formatPainter.test.ts@@ -1,6 +1,6 @@import {describe, it} from "node:test";import * as assert from "node:assert/strict";-import {getCommonFormatPainterSnapshot} from "./formatPainterCore";+import {getCommonFormatPainterSnapshot, shouldKeepFormatPainterActive} from "./formatPainterCore";describe("getCommonFormatPainterSnapshot", () => {it("keeps only formats shared by every selected text segment", () => {@@ -40,3 +40,10 @@ describe("getCommonFormatPainterSnapshot", () => {assert.equal(getCommonFormatPainterSnapshot([]), undefined);});});++describe("shouldKeepFormatPainterActive", () => {+ it("keeps only continuous format painting active after applying a format", () => {+ assert.equal(shouldKeepFormatPainterActive("once"), false);+ assert.equal(shouldKeepFormatPainterActive("continuous"), true);+ });+});diff --git a/app/src/protyle/toolbar/formatPainterCore.ts b/app/src/protyle/toolbar/formatPainterCore.tsindex 7e908db71e..25c20510df 100644--- a/app/src/protyle/toolbar/formatPainterCore.ts+++ b/app/src/protyle/toolbar/formatPainterCore.ts@@ -6,6 +6,10 @@ export interface IFormatPainterStyle {hollow?: boolean;}+export type TFormatPainterMode = "once" | "continuous";++export const shouldKeepFormatPainterActive = (mode: TFormatPainterMode) => mode === "continuous";+export interface IFormatPainterSnapshot {styles: IFormatPainterStyle;types: string[];