Skip to content

Commit

Permalink
fix(numfmt): support edit percent with numfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Gggpound committed Aug 26, 2024
1 parent a923a93 commit c06ce26
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions packages/sheets-numfmt/src/controllers/numfmt.editor.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ export class NumfmtEditorController extends Disposable {
const type = getPatternType(numfmtCell.pattern);
switch (type) {
case 'scientific':
case 'percent':
case 'currency':
case 'grouped':
case 'number': {
const cell = context.worksheet.getCellRaw(row, col);
return cell;
}
case 'percent':
case 'date':
case 'time':
case 'datetime':
Expand All @@ -138,6 +138,7 @@ export class NumfmtEditorController extends Disposable {
* @private
* @memberof NumfmtService
*/

private _initInterceptorEditorEnd() {
if (!this._editorBridgeService) {
return;
Expand All @@ -159,6 +160,7 @@ export class NumfmtEditorController extends Disposable {
);
const currentNumfmtType = (currentNumfmtValue && getPatternType(currentNumfmtValue.pattern)) ?? '';
const clean = () => {
// eslint-disable-next-line ts/no-unused-expressions
currentNumfmtValue &&
this._collectEffectMutation.add(
context.unitId,
Expand All @@ -174,24 +176,24 @@ export class NumfmtEditorController extends Disposable {

const content = String(value.v);

const dateInfo = numfmt.parseDate(content) || numfmt.parseTime(content);
const isTranslateDate = !!dateInfo;
if (isTranslateDate) {
if (dateInfo && dateInfo.z) {
const v = Number(dateInfo.v);
const numfmtInfo = numfmt.parseDate(content) || numfmt.parseTime(content) || numfmt.parseNumber(content);

if (numfmtInfo) {
if (numfmtInfo.z) {
const v = Number(numfmtInfo.v);
this._collectEffectMutation.add(
context.unitId,
context.subUnitId,
context.row,
context.col,
{
pattern: dateInfo.z,
pattern: numfmtInfo.z,
}
);
return { ...value, v, t: CellValueType.NUMBER };
}
} else if (
['date', 'time', 'datetime'].includes(currentNumfmtType) ||
['date', 'time', 'datetime', 'percent'].includes(currentNumfmtType) ||
!isNumeric(content)
) {
clean();
Expand Down

0 comments on commit c06ce26

Please sign in to comment.