Skip to content

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

:art: Refine recently used inline appearances https://github.com/siyuan-note/siyuan/issues/13858

Daniel2f5b4f2a6869
diff --git a/app/src/assets/scss/protyle/_toolbar.scss b/app/src/assets/scss/protyle/_toolbar.scss
index 3c05111d20..bad8fcd74c 100644
--- a/app/src/assets/scss/protyle/_toolbar.scss
+++ b/app/src/assets/scss/protyle/_toolbar.scss
@@ -114,10 +114,6 @@
overflow: auto;
max-height: calc(80vh - 24px);
- [data-id="lastUsedWrap"] > :nth-child(n + 8) {
- display: none;
- }
-
&__style {
background-color: var(--b3-theme-background);
margin: 4px;
diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.ts
index 48f9803041..02bee19c48 100644
--- a/app/src/protyle/gutter/index.ts
+++ b/app/src/protyle/gutter/index.ts
@@ -65,7 +65,7 @@ import {isMobile} from "../../util/functions";
import {AIActions} from "../../ai/actions";
import {activeBlur, renderTextMenu, showKeyboardToolbarUtil} from "../../mobile/util/keyboardToolbar";
import {hideTooltip} from "../../dialog/tooltip";
-import {appearanceMenu} from "../toolbar/Font";
+import {appearanceMenu, limitRecentFontStyleRows} from "../toolbar/Font";
import {setPosition} from "../../util/setPosition";
import {emitOpenMenu} from "../../plugin/EventBus";
import {insertAttrViewBlockAnimation, selectRow, updateHeader} from "../render/av/row";
@@ -1301,9 +1301,11 @@ export class Gutter {
protyle.toolbar.subElement.innerHTML = "";
protyle.toolbar.subElement.style.width = "";
protyle.toolbar.subElement.style.padding = "";
- protyle.toolbar.subElement.append(appearanceMenu(protyle, selectsElement));
+ const fontMenuElement = appearanceMenu(protyle, selectsElement);
+ protyle.toolbar.subElement.append(fontMenuElement);
protyle.toolbar.subElement.style.zIndex = (++window.siyuan.zIndex).toString();
protyle.toolbar.subElement.classList.remove("fn__none");
+ limitRecentFontStyleRows(fontMenuElement);
protyle.toolbar.subElementCloseCB = undefined;
const position = selectsElement[0].getBoundingClientRect();
setPosition(protyle.toolbar.subElement, position.left, position.top);
@@ -2504,9 +2506,11 @@ export class Gutter {
protyle.toolbar.subElement.innerHTML = "";
protyle.toolbar.subElement.style.width = "";
protyle.toolbar.subElement.style.padding = "";
- protyle.toolbar.subElement.append(appearanceMenu(protyle, [nodeElement]));
+ const fontMenuElement = appearanceMenu(protyle, [nodeElement]);
+ protyle.toolbar.subElement.append(fontMenuElement);
protyle.toolbar.subElement.style.zIndex = (++window.siyuan.zIndex).toString();
protyle.toolbar.subElement.classList.remove("fn__none");
+ limitRecentFontStyleRows(fontMenuElement);
protyle.toolbar.subElementCloseCB = undefined;
const position = nodeElement.getBoundingClientRect();
setPosition(protyle.toolbar.subElement, position.left, position.top);
diff --git a/app/src/protyle/toolbar/Font.ts b/app/src/protyle/toolbar/Font.ts
index ca77e52425..58303af0da 100644
--- a/app/src/protyle/toolbar/Font.ts
+++ b/app/src/protyle/toolbar/Font.ts
@@ -10,18 +10,41 @@ const MAX_RECENT_FONT_STYLES = 14;
const getRecentFontSizeDisplay = (fontSize: string) => {
if (fontSize.endsWith("em")) {
- const percentage = (parseFloat(fontSize) * 100).toFixed(0);
+ const percentage = `${(parseFloat(fontSize) * 100).toFixed(0)}%`;
return {
label: percentage,
- tooltip: `${window.siyuan.languages.fontSize} ${percentage}%`,
+ tooltip: `${window.siyuan.languages.fontSize} ${percentage}`,
};
}
return {
- label: fontSize.endsWith("px") ? fontSize.slice(0, -2) : fontSize,
+ label: fontSize,
tooltip: `${window.siyuan.languages.fontSize} ${fontSize}`,
};
};
+export const limitRecentFontStyleRows = (element: HTMLElement) => {
+ const wrapElement = element.querySelector('[data-id="lastUsedWrap"]');
+ if (!wrapElement) {
+ return;
+ }
+ const itemElements = Array.from(wrapElement.children) as HTMLElement[];
+ let rowCount = 0;
+ let lastTop: number;
+ let overflowIndex = itemElements.length;
+ itemElements.find((item, index) => {
+ if (item.offsetTop !== lastTop) {
+ rowCount++;
+ lastTop = item.offsetTop;
+ }
+ if (rowCount > 2) {
+ overflowIndex = index;
+ return true;
+ }
+ return false;
+ });
+ itemElements.slice(overflowIndex).forEach(item => item.classList.add("fn__none"));
+};
+
export class Font extends ToolbarItem {
public element: HTMLElement;
@@ -33,9 +56,11 @@ export class Font extends ToolbarItem {
protyle.toolbar.subElement.innerHTML = "";
protyle.toolbar.subElement.style.width = "";
protyle.toolbar.subElement.style.padding = "";
- protyle.toolbar.subElement.append(appearanceMenu(protyle, getFontNodeElements(protyle)));
+ const appearanceElement = appearanceMenu(protyle, getFontNodeElements(protyle));
+ protyle.toolbar.subElement.append(appearanceElement);
protyle.toolbar.subElement.style.zIndex = (++window.siyuan.zIndex).toString();
protyle.toolbar.subElement.classList.remove("fn__none");
+ limitRecentFontStyleRows(appearanceElement);
protyle.toolbar.subElementCloseCB = undefined;
focusByRange(protyle.toolbar.range);
/// #if !MOBILE
@@ -140,7 +165,7 @@ export const appearanceMenu = (protyle: IProtyle, nodeElements?: Element[],
case "fontSize":
if (!disableFont) {
const fontSizeDisplay = getRecentFontSizeDisplay(lastFontStatus[1]);
- lastColorHTML += `<button data-type="${lastFontStatus[0]}" class="protyle-font__style ariaLabel" data-position="3south" aria-label="${fontSizeDisplay.tooltip}">${fontSizeDisplay.label}</button>`;
+ lastColorHTML += `<button data-type="${lastFontStatus[0]}" data-value="${lastFontStatus[1]}" class="protyle-font__style ariaLabel" data-position="3south" aria-label="${fontSizeDisplay.tooltip}">${fontSizeDisplay.label}</button>`;
}
break;
case "style1":
@@ -223,7 +248,7 @@ export const appearanceMenu = (protyle: IProtyle, nodeElements?: Element[],
if (dataType === "style1") {
applyFontStyle(dataType, target.style.backgroundColor + Constants.ZWSP + target.style.color);
} else if (dataType === "fontSize") {
- applyFontStyle(dataType, target.textContent.trim());
+ applyFontStyle(dataType, target.getAttribute("data-value"));
} else if (dataType === "backgroundColor") {
applyFontStyle(dataType, target.style.backgroundColor);
} else if (dataType === "color") {
diff --git a/app/src/protyle/toolbar/tableCell.ts b/app/src/protyle/toolbar/tableCell.ts
index c459fbd91f..c4f645b083 100644
--- a/app/src/protyle/toolbar/tableCell.ts
+++ b/app/src/protyle/toolbar/tableCell.ts
@@ -1,5 +1,5 @@
import {setPosition} from "../../util/setPosition";
-import {appearanceMenu, fontEvent} from "./Font";
+import {appearanceMenu, fontEvent, limitRecentFontStyleRows} from "./Font";
import {toolbarKeyToMenu} from "./util";
import {matchHotKey} from "../util/hotKey";
@@ -26,12 +26,14 @@ export const openTableCellAppearance = (protyle: IProtyle, cellElements: HTMLTab
protyle.toolbar.subElement.style.width = "";
protyle.toolbar.subElement.style.padding = "";
const fontElement = cells[0].querySelector('[data-type~="text"]') || cells[0];
- protyle.toolbar.subElement.append(appearanceMenu(protyle, [fontElement], (type, color) => {
+ const appearanceElement = appearanceMenu(protyle, [fontElement], (type, color) => {
applyTableCellFontStyle(protyle, cells, type, color);
onApply?.();
- }));
+ });
+ protyle.toolbar.subElement.append(appearanceElement);
protyle.toolbar.subElement.style.zIndex = (++window.siyuan.zIndex).toString();
protyle.toolbar.subElement.classList.remove("fn__none");
+ limitRecentFontStyleRows(appearanceElement);
protyle.toolbar.subElementCloseCB = undefined;
const rect = cells[0].getBoundingClientRect();
setPosition(protyle.toolbar.subElement, rect.left, rect.top);