mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-09-22 00:20:47 +02:00
This commit is contained in:
parent
edba62bdf1
commit
0acda592dc
2 changed files with 52 additions and 99 deletions
|
@ -371,12 +371,27 @@ export const setFontStyle = (textElement: HTMLElement, textOption: ITextOption)
|
|||
}
|
||||
};
|
||||
|
||||
export const hasSameTextStyle = (currentElement: HTMLElement, sideElement: HTMLElement, textObj: ITextOption) => {
|
||||
if (!textObj) {
|
||||
// https://github.com/siyuan-note/siyuan/issues/14019
|
||||
if (currentElement && currentElement.nodeType !== 3 && sideElement.nodeType !== 3 &&
|
||||
// 当为 span 时,都经过 isArrayEqual 判断
|
||||
sideElement.style.color === currentElement.style.color &&
|
||||
export const hasSameTextStyle = (currentElement: HTMLElement, sideElement: HTMLElement, textObj?: ITextOption) => {
|
||||
if (!textObj && currentElement) {
|
||||
const types = sideElement.getAttribute("data-type").split(" ");
|
||||
if (types.includes("inline-math") || types.includes("inline-memo") ||
|
||||
types.includes("a")) {
|
||||
return false;
|
||||
}
|
||||
if (types.includes("id")) {
|
||||
if (currentElement.getAttribute("data-id") !== sideElement.getAttribute("data-id") ||
|
||||
currentElement.getAttribute("data-subtype") !== sideElement.getAttribute("data-subtype") ||
|
||||
currentElement.textContent !== sideElement.textContent) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (types.includes("file-annotation-ref")) {
|
||||
if (currentElement.getAttribute("data-id") !== sideElement.getAttribute("data-id") ||
|
||||
currentElement.textContent !== sideElement.textContent) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (sideElement.style.color === currentElement.style.color &&
|
||||
sideElement.style.webkitTextFillColor === currentElement.style.webkitTextFillColor &&
|
||||
sideElement.style.webkitTextStroke === currentElement.style.webkitTextStroke &&
|
||||
sideElement.style.textShadow === currentElement.style.textShadow &&
|
||||
|
@ -386,101 +401,39 @@ export const hasSameTextStyle = (currentElement: HTMLElement, sideElement: HTMLE
|
|||
}
|
||||
return false;
|
||||
}
|
||||
if (textObj.type === "inline-math" || textObj.type === "inline-memo" || textObj.type === "a") {
|
||||
return false;
|
||||
}
|
||||
if (textObj.type === "id") {
|
||||
if (currentElement && currentElement.nodeType !== 3) {
|
||||
return currentElement.getAttribute("data-id") === sideElement.getAttribute("data-id") &&
|
||||
currentElement.getAttribute("data-subtype") === sideElement.getAttribute("data-subtype") &&
|
||||
currentElement.textContent === sideElement.textContent;
|
||||
}
|
||||
const blockRefData = textObj.color.split(Constants.ZWSP);
|
||||
return blockRefData[0] === sideElement.getAttribute("data-id") &&
|
||||
blockRefData[1] === sideElement.getAttribute("data-subtype") &&
|
||||
blockRefData[2] === sideElement.textContent;
|
||||
}
|
||||
|
||||
if (textObj.type === "file-annotation-ref") {
|
||||
if (currentElement && currentElement.nodeType !== 3) {
|
||||
return currentElement.getAttribute("data-id") === sideElement.getAttribute("data-id") &&
|
||||
currentElement.textContent === sideElement.textContent;
|
||||
if (textObj) {
|
||||
if (textObj.type === "text") {
|
||||
// 清除样式
|
||||
return !sideElement.style.color &&
|
||||
!sideElement.style.webkitTextFillColor &&
|
||||
!sideElement.style.webkitTextStroke &&
|
||||
!sideElement.style.textShadow &&
|
||||
!sideElement.style.fontSize &&
|
||||
!sideElement.style.backgroundColor;
|
||||
}
|
||||
if (textObj.type === "color") {
|
||||
return textObj.color === sideElement.style.color;
|
||||
}
|
||||
if (textObj.type === "backgroundColor") {
|
||||
return textObj.color === sideElement.style.backgroundColor;
|
||||
}
|
||||
if (textObj.type === "style1") {
|
||||
return textObj.color.split(Constants.ZWSP)[0] === sideElement.style.color &&
|
||||
textObj.color.split(Constants.ZWSP)[1] === sideElement.style.backgroundColor;
|
||||
}
|
||||
if (textObj.type === "style2") {
|
||||
return "transparent" === sideElement.style.webkitTextFillColor &&
|
||||
"0.2px var(--b3-theme-on-background)" === sideElement.style.webkitTextStroke;
|
||||
}
|
||||
if (textObj.type === "style4") {
|
||||
return "1px 1px var(--b3-theme-surface-lighter), 2px 2px var(--b3-theme-surface-lighter), 3px 3px var(--b3-theme-surface-lighter), 4px 4px var(--b3-theme-surface-lighter)" === sideElement.style.textShadow;
|
||||
}
|
||||
if (textObj.type === "fontSize") {
|
||||
return textObj.color === sideElement.style.fontSize;
|
||||
}
|
||||
return textObj.color === sideElement.getAttribute("data-id");
|
||||
}
|
||||
|
||||
let color = "";
|
||||
let webkitTextFillColor = "";
|
||||
let webkitTextStroke = "";
|
||||
let textShadow = "";
|
||||
let backgroundColor = "";
|
||||
let fontSize = "";
|
||||
if (currentElement && currentElement.nodeType !== 3) {
|
||||
color = currentElement.style.color;
|
||||
webkitTextFillColor = currentElement.style.webkitTextFillColor;
|
||||
webkitTextStroke = currentElement.style.webkitTextStroke;
|
||||
textShadow = currentElement.style.textShadow;
|
||||
backgroundColor = currentElement.style.backgroundColor;
|
||||
fontSize = currentElement.style.fontSize;
|
||||
}
|
||||
if (textObj.type === "text") {
|
||||
// 清除样式
|
||||
return color === sideElement.style.color &&
|
||||
webkitTextFillColor === sideElement.style.webkitTextFillColor &&
|
||||
webkitTextStroke === sideElement.style.webkitTextStroke &&
|
||||
textShadow === sideElement.style.textShadow &&
|
||||
fontSize === sideElement.style.fontSize &&
|
||||
backgroundColor === sideElement.style.backgroundColor;
|
||||
}
|
||||
if (textObj.type === "color") {
|
||||
return textObj.color === sideElement.style.color &&
|
||||
webkitTextFillColor === sideElement.style.webkitTextFillColor &&
|
||||
webkitTextStroke === sideElement.style.webkitTextStroke &&
|
||||
textShadow === sideElement.style.textShadow &&
|
||||
fontSize === sideElement.style.fontSize &&
|
||||
backgroundColor === sideElement.style.backgroundColor;
|
||||
}
|
||||
if (textObj.type === "backgroundColor") {
|
||||
return color === sideElement.style.color &&
|
||||
webkitTextFillColor === sideElement.style.webkitTextFillColor &&
|
||||
webkitTextStroke === sideElement.style.webkitTextStroke &&
|
||||
textShadow === sideElement.style.textShadow &&
|
||||
fontSize === sideElement.style.fontSize &&
|
||||
textObj.color === sideElement.style.backgroundColor;
|
||||
}
|
||||
if (textObj.type === "style1") {
|
||||
return textObj.color.split(Constants.ZWSP)[0] === sideElement.style.color &&
|
||||
webkitTextFillColor === sideElement.style.webkitTextFillColor &&
|
||||
webkitTextStroke === sideElement.style.webkitTextStroke &&
|
||||
textShadow === sideElement.style.textShadow &&
|
||||
fontSize === sideElement.style.fontSize &&
|
||||
textObj.color.split(Constants.ZWSP)[1] === sideElement.style.backgroundColor;
|
||||
}
|
||||
if (textObj.type === "style2") {
|
||||
return color === sideElement.style.color &&
|
||||
"transparent" === sideElement.style.webkitTextFillColor &&
|
||||
"0.2px var(--b3-theme-on-background)" === sideElement.style.webkitTextStroke &&
|
||||
textShadow === sideElement.style.textShadow &&
|
||||
fontSize === sideElement.style.fontSize &&
|
||||
backgroundColor === sideElement.style.backgroundColor;
|
||||
}
|
||||
if (textObj.type === "style4") {
|
||||
return color === sideElement.style.color &&
|
||||
webkitTextFillColor === sideElement.style.webkitTextFillColor &&
|
||||
webkitTextStroke === sideElement.style.webkitTextStroke &&
|
||||
fontSize === sideElement.style.fontSize &&
|
||||
"1px 1px var(--b3-theme-surface-lighter), 2px 2px var(--b3-theme-surface-lighter), 3px 3px var(--b3-theme-surface-lighter), 4px 4px var(--b3-theme-surface-lighter)" === sideElement.style.textShadow &&
|
||||
backgroundColor === sideElement.style.backgroundColor;
|
||||
}
|
||||
if (textObj.type === "fontSize") {
|
||||
return color === sideElement.style.color &&
|
||||
webkitTextFillColor === sideElement.style.webkitTextFillColor &&
|
||||
webkitTextStroke === sideElement.style.webkitTextStroke &&
|
||||
textShadow === sideElement.style.textShadow &&
|
||||
textObj.color === sideElement.style.fontSize &&
|
||||
backgroundColor === sideElement.style.backgroundColor;
|
||||
}
|
||||
return true; // 清除字体样式会使用 "text" 作为标识
|
||||
return false;
|
||||
};
|
||||
|
||||
export const getFontNodeElements = (protyle: IProtyle) => {
|
||||
|
|
|
@ -681,7 +681,7 @@ export class Toolbar {
|
|||
previousElement && previousElement.nodeType !== 3 &&
|
||||
currentNode.nodeType !== 3 &&
|
||||
isArrayEqual(currentType, (previousElement.getAttribute("data-type") || "").split(" ")) &&
|
||||
hasSameTextStyle(currentNode, previousElement, textObj)) {
|
||||
hasSameTextStyle(currentNode, previousElement)) {
|
||||
if (currentType.includes("code") || currentType.includes("tag") || currentType.includes("kbd")) {
|
||||
if (currentNode.textContent.startsWith(Constants.ZWSP)) {
|
||||
currentNode.textContent = currentNode.textContent.substring(1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue