fix: style loss while adding style to inline text

This commit is contained in:
gaze 2023-09-07 12:50:30 +08:00
parent 71aa0434c0
commit d3e8fba9b0
2 changed files with 24 additions and 19 deletions

View File

@ -738,10 +738,6 @@ export function updateCell(
}
curv ||= {};
const fontSize = curv.fs || 10;
delete curv.fs;
delete curv.f;
delete curv.v;
delete curv.m;
if (!curv.ct) {
curv.ct = {};
@ -749,7 +745,14 @@ export function updateCell(
}
curv.ct.t = "inlineStr";
curv.ct.s = convertSpanToShareString($input!.querySelectorAll("span"));
curv.ct.s = convertSpanToShareString(
$input!.querySelectorAll("span"),
curv
);
delete curv.fs;
delete curv.f;
delete curv.v;
delete curv.m;
curv.fs = fontSize;
if (isCopyVal) {
curv.ct.s = [

View File

@ -58,7 +58,7 @@ export function getInlineStringNoStyle(r: number, c: number, data: CellMatrix) {
return "";
}
export function convertCssToStyleList(cssText: string) {
export function convertCssToStyleList(cssText: string, originCell: Cell) {
if (_.isEmpty(cssText)) {
return {};
}
@ -66,12 +66,12 @@ export function convertCssToStyleList(cssText: string) {
const styleList: CellStyle = {
// ff: locale_fontarray[0], // font family
fc: "#000000", // font color
fs: 10, // font size
cl: 0, // strike
un: 0, // underline
bl: 0, // blod
it: 0, // italic
fc: originCell.fc || "#000000", // font color
fs: originCell.fs || 10, // font size
cl: originCell.cl || 0, // strike
un: originCell.un || 0, // underline
bl: originCell.bl || 0, // blod
it: originCell.it || 0, // italic
};
cssTextArray.forEach((s) => {
s = s.toLowerCase();
@ -80,16 +80,12 @@ export function convertCssToStyleList(cssText: string) {
if (key === "font-weight") {
if (value === "bold") {
styleList.bl = 1;
} else {
styleList.bl = 0;
}
}
if (key === "font-style") {
if (value === "italic") {
styleList.it = 1;
} else {
styleList.it = 0;
}
}
@ -130,14 +126,20 @@ export function convertCssToStyleList(cssText: string) {
return styleList;
}
// eslint-disable-next-line no-undef
export function convertSpanToShareString($dom: NodeListOf<HTMLSpanElement>) {
export function convertSpanToShareString(
// eslint-disable-next-line no-undef
$dom: NodeListOf<HTMLSpanElement>,
originCell: Cell
) {
const styles: CellStyle[] = [];
let preStyleList: Cell;
let preStyleListString = null;
for (let i = 0; i < $dom.length; i += 1) {
const span = $dom[i];
const styleList = convertCssToStyleList(span.style.cssText) as Cell;
const styleList = convertCssToStyleList(
span.style.cssText,
originCell
) as Cell;
const curStyleListString = JSON.stringify(styleList);
// let v = span.innerHTML;