Skip to content

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

:art: Improve format painter toolbar interactions https://github.com/siyuan-note/siyuan/issues/12732

Daniel7c7a463d10ee
diff --git a/app/appearance/icons/index.html b/app/appearance/icons/index.html
index d630f83a64..3f5dbaadd0 100644
--- a/app/appearance/icons/index.html
+++ b/app/appearance/icons/index.html
@@ -724,6 +724,12 @@
</svg>
iconClear
</div>
+ <div>
+ <svg>
+ <use xlink:href="#iconEraser"></use>
+ </svg>
+ iconEraser
+ </div>
<div>
<svg>
<use xlink:href="#iconFormat"></use>
diff --git a/app/appearance/icons/litheness/icon.js b/app/appearance/icons/litheness/icon.js
index cdafa32ea7..cfe73062ad 100644
--- a/app/appearance/icons/litheness/icon.js
+++ b/app/appearance/icons/litheness/icon.js
@@ -356,6 +356,9 @@ document.body.insertAdjacentHTML('afterbegin', `<svg id="iconsLitheness" style="
<symbol id="iconClear" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round">
<path d="M4 7V4h16v3"/><path d="M5 20h6"/><path d="M13 4 8 20"/><path d="m15 15 5 5"/><path d="m20 15-5 5"/>
</symbol>
+ <symbol id="iconEraser" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round">
+ <path d="M21 21H8a2 2 0 0 1-1.42-.587l-3.994-3.999a2 2 0 0 1 0-2.828l10-10a2 2 0 0 1 2.829 0l5.999 6a2 2 0 0 1 0 2.828L12.834 21"/><path d="m5.082 11.09 8.828 8.828"/>
+ </symbol>
<symbol id="iconFormat" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round">
<path d="M12 22h6a2 2 0 0 0 2-2V8a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v6"/><path d="M14 2v5a1 1 0 0 0 1 1h5"/><path d="M3 16v-1.5a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 .5.5V16"/><path d="M6 22h2"/><path d="M7 14v8"/>
</symbol>
diff --git a/app/appearance/langs/ar.json b/app/appearance/langs/ar.json
index a1bc27615e..e6a77e7f5c 100644
--- a/app/appearance/langs/ar.json
+++ b/app/appearance/langs/ar.json
@@ -1,5 +1,6 @@
{
"dragTipSelectedNotebooks": "تم تحديد ${count} من دفاتر الملاحظات",
+ "formatPainterDoubleClickTip": "نسخ التنسيق؛ انقر نقرًا مزدوجًا للاستخدام المستمر",
"dragTipSelectedDocs": "تم تحديد ${count} من المستندات",
"entrySlashMenu": "قائمة الشرطة المائلة",
"importNotebook": "استيراد دفتر ملاحظات",
diff --git a/app/appearance/langs/de.json b/app/appearance/langs/de.json
index 5e6c87b649..7001e35862 100644
--- a/app/appearance/langs/de.json
+++ b/app/appearance/langs/de.json
@@ -1,5 +1,6 @@
{
"dragTipSelectedNotebooks": "${count} Notizbücher ausgewählt",
+ "formatPainterDoubleClickTip": "Format übertragen; für fortlaufende Verwendung doppelklicken",
"dragTipSelectedDocs": "${count} Dokumente ausgewählt",
"entrySlashMenu": "Slash-Menü",
"importNotebook": "Notizbuch importieren",
diff --git a/app/appearance/langs/en.json b/app/appearance/langs/en.json
index cb7f4f9663..784cc14bd4 100644
--- a/app/appearance/langs/en.json
+++ b/app/appearance/langs/en.json
@@ -1,5 +1,6 @@
{
"dragTipSelectedNotebooks": "Selected ${count} notebooks",
+ "formatPainterDoubleClickTip": "Format Painter; double-click for continuous use",
"dragTipSelectedDocs": "Selected ${count} documents",
"entrySlashMenu": "Slash menu",
"importNotebook": "Import Notebook",
diff --git a/app/appearance/langs/es.json b/app/appearance/langs/es.json
index 881fb9ace8..abe5db1434 100644
--- a/app/appearance/langs/es.json
+++ b/app/appearance/langs/es.json
@@ -1,5 +1,6 @@
{
"dragTipSelectedNotebooks": "${count} cuadernos de notas seleccionados",
+ "formatPainterDoubleClickTip": "Copiar formato; haz doble clic para usarlo continuamente",
"dragTipSelectedDocs": "${count} documentos seleccionados",
"entrySlashMenu": "Menú slash",
"importNotebook": "Importar cuaderno",
diff --git a/app/appearance/langs/fr.json b/app/appearance/langs/fr.json
index 9f9771cfe0..e8e6d64177 100644
--- a/app/appearance/langs/fr.json
+++ b/app/appearance/langs/fr.json
@@ -1,5 +1,6 @@
{
"dragTipSelectedNotebooks": "${count} carnets de notes sélectionnés",
+ "formatPainterDoubleClickTip": "Reproduire la mise en forme ; double-cliquez pour une utilisation continue",
"dragTipSelectedDocs": "${count} documents sélectionnés",
"entrySlashMenu": "Menu de commandes slash",
"importNotebook": "Importer un carnet",
diff --git a/app/appearance/langs/he.json b/app/appearance/langs/he.json
index 119efacf58..80d21153a6 100644
--- a/app/appearance/langs/he.json
+++ b/app/appearance/langs/he.json
@@ -1,5 +1,6 @@
{
"dragTipSelectedNotebooks": "נבחרו ${count} מחברות",
+ "formatPainterDoubleClickTip": "מברשת עיצוב; לחיצה כפולה לשימוש רציף",
"dragTipSelectedDocs": "נבחרו ${count} מסמכים",
"entrySlashMenu": "תפריט לוכסן",
"importNotebook": "ייבוא מחברת",
diff --git a/app/appearance/langs/hi.json b/app/appearance/langs/hi.json
index 537fe5c3bb..2d7192eaba 100644
--- a/app/appearance/langs/hi.json
+++ b/app/appearance/langs/hi.json
@@ -1,5 +1,6 @@
{
"dragTipSelectedNotebooks": "${count} नोटबुक चयनित",
+ "formatPainterDoubleClickTip": "फ़ॉर्मैट पेंटर; लगातार उपयोग के लिए डबल-क्लिक करें",
"dragTipSelectedDocs": "${count} दस्तावेज़ चयनित",
"entrySlashMenu": "स्लैश मेनू",
"importNotebook": "नोटबुक आयात करें",
diff --git a/app/appearance/langs/id.json b/app/appearance/langs/id.json
index c299d7240d..0b4047bab9 100644
--- a/app/appearance/langs/id.json
+++ b/app/appearance/langs/id.json
@@ -1,5 +1,6 @@
{
"dragTipSelectedNotebooks": "${count} buku catatan dipilih",
+ "formatPainterDoubleClickTip": "Salin format; klik dua kali untuk penggunaan berkelanjutan",
"dragTipSelectedDocs": "${count} dokumen dipilih",
"entrySlashMenu": "Menu garis miring",
"importNotebook": "Impor buku catatan",
diff --git a/app/appearance/langs/it.json b/app/appearance/langs/it.json
index 405a561412..87bf8d75a8 100644
--- a/app/appearance/langs/it.json
+++ b/app/appearance/langs/it.json
@@ -1,5 +1,6 @@
{
"dragTipSelectedNotebooks": "${count} taccuini selezionati",
+ "formatPainterDoubleClickTip": "Copia formato; fai doppio clic per l'uso continuo",
"dragTipSelectedDocs": "${count} documenti selezionati",
"entrySlashMenu": "Menu slash",
"importNotebook": "Importa taccuino",
diff --git a/app/appearance/langs/ja.json b/app/appearance/langs/ja.json
index 18e756de34..b3430f6a14 100644
--- a/app/appearance/langs/ja.json
+++ b/app/appearance/langs/ja.json
@@ -1,5 +1,6 @@
{
"dragTipSelectedNotebooks": "${count} 件のノートブックを選択",
+ "formatPainterDoubleClickTip": "書式のコピー。ダブルクリックで連続使用",
"dragTipSelectedDocs": "${count} 件の文書を選択",
"entrySlashMenu": "スラッシュメニュー",
"importNotebook": "ノートブックをインポート",
diff --git a/app/appearance/langs/ko.json b/app/appearance/langs/ko.json
index d18ef1a901..f002de8dc2 100644
--- a/app/appearance/langs/ko.json
+++ b/app/appearance/langs/ko.json
@@ -1,5 +1,6 @@
{
"dragTipSelectedNotebooks": "노트북 ${count}개 선택됨",
+ "formatPainterDoubleClickTip": "서식 복사; 연속 사용하려면 두 번 클릭",
"dragTipSelectedDocs": "문서 ${count}개 선택됨",
"entrySlashMenu": "슬래시 메뉴",
"importNotebook": "노트북 가져오기",
diff --git a/app/appearance/langs/nl.json b/app/appearance/langs/nl.json
index 834e21310d..3120d15071 100644
--- a/app/appearance/langs/nl.json
+++ b/app/appearance/langs/nl.json
@@ -1,5 +1,6 @@
{
"dragTipSelectedNotebooks": "${count} notitieboeken geselecteerd",
+ "formatPainterDoubleClickTip": "Opmaak kopiëren; dubbelklik voor doorlopend gebruik",
"dragTipSelectedDocs": "${count} documenten geselecteerd",
"entrySlashMenu": "Slashmenu",
"importNotebook": "Notitieboek importeren",
diff --git a/app/appearance/langs/pl.json b/app/appearance/langs/pl.json
index bab8e99871..f956ae1b64 100644
--- a/app/appearance/langs/pl.json
+++ b/app/appearance/langs/pl.json
@@ -1,5 +1,6 @@
{
"dragTipSelectedNotebooks": "Wybrane notesy: ${count}",
+ "formatPainterDoubleClickTip": "Malarz formatów; kliknij dwukrotnie, aby używać w trybie ciągłym",
"dragTipSelectedDocs": "Wybrane dokumenty: ${count}",
"entrySlashMenu": "Menu poleceń z ukośnikiem",
"importNotebook": "Importuj notatnik",
diff --git a/app/appearance/langs/pt-BR.json b/app/appearance/langs/pt-BR.json
index f139bd00c1..bdb6130eb2 100644
--- a/app/appearance/langs/pt-BR.json
+++ b/app/appearance/langs/pt-BR.json
@@ -1,5 +1,6 @@
{
"dragTipSelectedNotebooks": "${count} blocos de notas selecionados",
+ "formatPainterDoubleClickTip": "Pincel de formatação; clique duas vezes para uso contínuo",
"dragTipSelectedDocs": "${count} documentos selecionados",
"entrySlashMenu": "Menu slash",
"importNotebook": "Importar caderno",
diff --git a/app/appearance/langs/ru.json b/app/appearance/langs/ru.json
index a7f1949187..e44343fa23 100644
--- a/app/appearance/langs/ru.json
+++ b/app/appearance/langs/ru.json
@@ -1,5 +1,6 @@
{
"dragTipSelectedNotebooks": "Выбрано блокнотов: ${count}",
+ "formatPainterDoubleClickTip": "Формат по образцу; дважды щёлкните для непрерывного использования",
"dragTipSelectedDocs": "Выбрано документов: ${count}",
"entrySlashMenu": "Слэш-меню",
"importNotebook": "Импортировать блокнот",
diff --git a/app/appearance/langs/sk.json b/app/appearance/langs/sk.json
index a424e6680b..2bb3c7db6b 100644
--- a/app/appearance/langs/sk.json
+++ b/app/appearance/langs/sk.json
@@ -1,5 +1,6 @@
{
"dragTipSelectedNotebooks": "Vybrané zápisníky: ${count}",
+ "formatPainterDoubleClickTip": "Kopírovať formát; dvojklikom zapnete nepretržité použitie",
"dragTipSelectedDocs": "Vybrané dokumenty: ${count}",
"entrySlashMenu": "Ponuka príkazov s lomkou",
"importNotebook": "Importovať zápisník",
diff --git a/app/appearance/langs/th.json b/app/appearance/langs/th.json
index 5121272ba0..bdf1a2bffc 100644
--- a/app/appearance/langs/th.json
+++ b/app/appearance/langs/th.json
@@ -1,5 +1,6 @@
{
"dragTipSelectedNotebooks": "เลือกสมุด ${count} เล่ม",
+ "formatPainterDoubleClickTip": "คัดลอกรูปแบบ; ดับเบิลคลิกเพื่อใช้งานต่อเนื่อง",
"dragTipSelectedDocs": "เลือกเอกสาร ${count} ฉบับ",
"entrySlashMenu": "เมนูสแลช",
"importNotebook": "นำเข้าสมุดบันทึก",
diff --git a/app/appearance/langs/tr.json b/app/appearance/langs/tr.json
index d20ea6feb0..34dcb43eb8 100644
--- a/app/appearance/langs/tr.json
+++ b/app/appearance/langs/tr.json
@@ -1,5 +1,6 @@
{
"dragTipSelectedNotebooks": "${count} not defteri seçildi",
+ "formatPainterDoubleClickTip": "Biçim Boyacısı; sürekli kullanım için çift tıklayın",
"dragTipSelectedDocs": "${count} belge seçildi",
"entrySlashMenu": "Eğik çizgi menüsü",
"importNotebook": "Not defteri içe aktar",
diff --git a/app/appearance/langs/uk.json b/app/appearance/langs/uk.json
index f172bc4d38..405635aecf 100644
--- a/app/appearance/langs/uk.json
+++ b/app/appearance/langs/uk.json
@@ -1,5 +1,6 @@
{
"dragTipSelectedNotebooks": "Вибрано блокнотів: ${count}",
+ "formatPainterDoubleClickTip": "Формат за зразком; двічі клацніть для безперервного використання",
"dragTipSelectedDocs": "Вибрано документів: ${count}",
"entrySlashMenu": "Слеш-меню",
"importNotebook": "Імпортувати блокнот",
diff --git a/app/appearance/langs/zh-CN.json b/app/appearance/langs/zh-CN.json
index 194e75d963..0908548d2a 100644
--- a/app/appearance/langs/zh-CN.json
+++ b/app/appearance/langs/zh-CN.json
@@ -1,5 +1,6 @@
{
"dragTipSelectedNotebooks": "选中 ${count} 个笔记本",
+ "formatPainterDoubleClickTip": "格式刷,双击可连续使用",
"dragTipSelectedDocs": "选中 ${count} 个文档",
"entrySlashMenu": "斜杠菜单",
"importNotebook": "导入笔记本",
diff --git a/app/appearance/langs/zh-TW.json b/app/appearance/langs/zh-TW.json
index 27e169e79e..b03d41fd48 100644
--- a/app/appearance/langs/zh-TW.json
+++ b/app/appearance/langs/zh-TW.json
@@ -1,5 +1,6 @@
{
"dragTipSelectedNotebooks": "選中 ${count} 個筆記本",
+ "formatPainterDoubleClickTip": "格式刷,雙擊可連續使用",
"dragTipSelectedDocs": "選中 ${count} 個文件",
"entrySlashMenu": "斜線選單",
"importNotebook": "導入筆記本",
diff --git a/app/src/assets/scss/protyle/_toolbar.scss b/app/src/assets/scss/protyle/_toolbar.scss
index b2e8bb6c34..25f19bddf6 100644
--- a/app/src/assets/scss/protyle/_toolbar.scss
+++ b/app/src/assets/scss/protyle/_toolbar.scss
@@ -31,6 +31,11 @@
height: 16px;
}
+ &[data-type="format-painter"] svg {
+ width: 14px;
+ height: 14px;
+ }
+
&--current {
color: var(--b3-theme-primary);
}
diff --git a/app/src/protyle/toolbar/FormatPainter.ts b/app/src/protyle/toolbar/FormatPainter.ts
index 620d56c85d..c4a9cd8898 100644
--- a/app/src/protyle/toolbar/FormatPainter.ts
+++ b/app/src/protyle/toolbar/FormatPainter.ts
@@ -1,6 +1,5 @@
import {Constants} from "../../constants";
import {showMessage} from "../../dialog/message";
-import {MenuItem} from "../../menus/Menu";
import {getBlockRanges} from "../util/selection";
import {
FORMAT_PAINTER_TYPES,
@@ -193,33 +192,29 @@ export const formatPainter = new FormatPainterController();
export class FormatPainter {
public element: HTMLElement;
+ private clickTimeout?: number;
constructor(protyle: IProtyle, menuItem: IMenuItem) {
this.element = document.createElement("button");
this.element.className = "protyle-toolbar__item b3-tooltips b3-tooltips__n";
this.element.setAttribute("data-type", menuItem.name);
- this.element.setAttribute("data-menu", "true");
- this.element.setAttribute("aria-label", window.siyuan.languages.formatPainter);
+ this.element.setAttribute("aria-label", window.siyuan.languages.formatPainterDoubleClickTip);
this.element.innerHTML = '<svg><use xlink:href="#iconPaintRoller"></use></svg>';
this.element.addEventListener("mousedown", event => event.preventDefault());
this.element.addEventListener("click", event => {
event.preventDefault();
- window.siyuan.menus.menu.remove();
- const items: {label: string, mode: TFormatPainterMode}[] = [
- {label: window.siyuan.languages.formatPainter, mode: "once"},
- {label: window.siyuan.languages.formatPainterContinuous, mode: "continuous"},
- ];
- items.forEach(item => {
- window.siyuan.menus.menu.append(new MenuItem({
- iconHTML: "",
- label: item.label,
- click: () => {
- formatPainter.activate(protyle, item.mode);
- },
- }).element);
- });
- const rect = this.element.getBoundingClientRect();
- window.siyuan.menus.menu.popup({x: rect.left, y: rect.bottom, h: rect.height});
+ clearTimeout(this.clickTimeout);
+ if (event.detail > 1) {
+ this.clickTimeout = undefined;
+ formatPainter.activate(protyle, "continuous");
+ } else if (event.detail === 0) {
+ formatPainter.activate(protyle, "once");
+ } else {
+ this.clickTimeout = window.setTimeout(() => {
+ this.clickTimeout = undefined;
+ formatPainter.activate(protyle, "once");
+ }, Constants.TIMEOUT_DBLCLICK);
+ }
});
}
}
diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.ts
index 1143fe687f..81d6dea61c 100644
--- a/app/src/protyle/toolbar/index.ts
+++ b/app/src/protyle/toolbar/index.ts
@@ -163,14 +163,14 @@ export class Toolbar {
"mark",
"sup",
"sub",
- "clear",
- "format-painter",
- "|",
"code",
"kbd",
"tag",
"inline-math",
"inline-memo",
+ "|",
+ "format-painter",
+ {name: "clear", icon: "iconEraser"},
]);
protyle.app.plugins.forEach(item => {
const pluginToolbar = filterPluginToolbar(item.updateProtyleToolbar(protyle.options.toolbar), protyle.lite);