Skip to content

Commit

Permalink
fix: cell number display when set text wrap (#2314)
Browse files Browse the repository at this point in the history
* fix: cell number display when set text wrap

* fix: wrong cell value render when edit
  • Loading branch information
Jocs authored May 27, 2024
1 parent 3cc0d55 commit 0144179
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
21 changes: 11 additions & 10 deletions packages/engine-render/src/components/docs/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ export class Documents extends DocComponent {

docsTop: number = 0;

private _drawLiquid: Liquid;
private _drawLiquid: Nullable<Liquid> = new Liquid();

private _findLiquid: Liquid;
// private _findLiquid: Nullable<Liquid> = new Liquid();

// private _hasEditor = false;

Expand All @@ -72,10 +72,6 @@ export class Documents extends DocComponent {
constructor(oKey: string, documentSkeleton?: DocumentSkeleton, config?: IDocumentsConfig) {
super(oKey, documentSkeleton, config);

this._drawLiquid = new Liquid();

this._findLiquid = new Liquid();

this._initialDefaultExtension();

// this._addSkeletonChangeObserver(documentSkeleton);
Expand All @@ -93,8 +89,8 @@ export class Documents extends DocComponent {
this._skeletonObserver?.dispose();
this._skeletonObserver = null;
this.onPageRenderObservable.clear();
this._drawLiquid = null as unknown as Liquid;
this._findLiquid = null as unknown as Liquid;
this._drawLiquid = null;
// this._findLiquid = null;
}

getOffsetConfig(): IDocumentOffsetConfig {
Expand Down Expand Up @@ -167,7 +163,7 @@ export class Documents extends DocComponent {
override draw(ctx: UniverRenderingContext, bounds?: IViewportInfo) {
const skeletonData = this.getSkeleton()?.getSkeletonData();

if (skeletonData == null) {
if (skeletonData == null || this._drawLiquid == null) {
return;
}

Expand Down Expand Up @@ -319,7 +315,12 @@ export class Documents extends DocComponent {
this._drawLiquid.translate(0, -rotateTranslateY);

rotateTranslateXListApply = rotateTranslateXList;
} else if (wrapStrategy === WrapStrategy.WRAP) {
} else if (
wrapStrategy === WrapStrategy.WRAP
// Use fix: https://github.com/dream-num/univer-pro/issues/734
&& (horizontalAlign !== HorizontalAlign.UNSPECIFIED || cellValueType !== CellValueType.NUMBER)
) {
// @Jocs, Why reset alignOffset.x? When you know the reason, add a description
alignOffset.x = pagePaddingLeft;
}

Expand Down
7 changes: 7 additions & 0 deletions packages/sheets-ui/src/services/editor-bridge.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import type { ICellDataForSheetInterceptor, IPosition, ISelectionCell, Nullable, Workbook } from '@univerjs/core';
import {
CellValueType,
createInterceptorKey,
Disposable,
DOCS_NORMAL_EDITOR_UNIT_ID_KEY,
Expand Down Expand Up @@ -231,6 +232,12 @@ export class EditorBridgeService extends Disposable implements IEditorBridgeServ

let documentLayoutObject = cell && skeleton.getCellDocumentModelWithFormula(cell);

// Rewrite the cellValueType to STRING to avoid render the value on the right side when number type.
const renderConfig = documentLayoutObject?.documentModel?.documentStyle.renderConfig;
if (renderConfig != null) {
renderConfig.cellValueType = CellValueType.STRING;
}

if (!documentLayoutObject || documentLayoutObject.documentModel == null) {
const blankModel = skeleton.getBlankCellDocumentModel(cell);

Expand Down

0 comments on commit 0144179

Please sign in to comment.