fortune-sheet
fortune-sheet copied to clipboard
fix: copy number with text format to a cell with text format
copy number with text format to a cell with text format will not auto generate cell type
-
before: When we copy "001" to a cell with text format, the cell will be convert to a number type and the value will be "1".
-
after The cell will stay text format and the number will still stay "001".
Thanks @gazedreamily
Let's make it more general rather than being specific to ".fa === '@'"
Check if the cell has
ct
, if so, useupdate
to generate the mask, otherwise, usegenerate
Thaks for your advice!
@gazedreamily I don't think you get what I mean. [txt, flowdata[r + minh][c + minc]?.ct, txt]
, here m
and v
should always be generated instead of just being assigned with raw data, except it's a plain text. This is my impl. Kindly check if it's expected.
diff --git a/packages/core/src/events/paste.ts b/packages/core/src/events/paste.ts
index 54641b0..8c51af7 100644
--- a/packages/core/src/events/paste.ts
+++ b/packages/core/src/events/paste.ts
@@ -318,6 +318,14 @@ function pasteHandler(ctx: Context, data: any, borderInfo?: any) {
value = data[h - minh][c - minc];
}
+ if (x[c]?.ct?.fa != null && x[c]?.ct?.fa !== value.ct?.fa) {
+ value.m = update(x[c]?.ct?.fa!, value.raw || value.v);
+ value.ct = x[c]?.ct;
+ if (x[c]?.ct?.t === "s" && value.raw) {
+ value.v = value.raw;
+ }
+ }
+ delete value.raw;
x[c] = value;
if (value != null && x?.[c]?.mc) {
@@ -1782,6 +1790,8 @@ export function _handlePaste(ctx: Context, htmlText?: string, plainText?: string
[cell.m, cell.ct, cell.v] = mask;
}
+ // @ts-ignore
+ cell.raw = txt;
const styleString =
typeof allStyleList[`.${className}`] === "string"
? allStyleList[`.${className}`]
@zyc9012 I think that we shouldn't change the format which the user set to the cell. I do the steps in Excel.
- select A1 and set its type into
percentage
- input
aaaa
to A1 - the cell type of A1 is still
percentage
and the cell displays asaaaa
@gazedreamily We are talking about paste here. Try pasting a string to the percentage
cell.
@zyc9012 It is still percentage
after I pasting a aaa
value from a txt file
@gazedreamily I tried several scenarios
- If the source is plain text, e.g. copied from Notepad, the format is unchanged
- If the source is HTML, e.g. copied from a web page, the format is changed
- If the source is a table, e.g. copied from Google Sheets, the format is changed
@zyc9012 change the type of the cell before copy a value into it
@gazedreamily That's exactly what I did
@zyc9012 Oh! My fault, you are right!