Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

fix(sheet): editor input (#1411)

Univer76f5e9c0c5cc
diff --git a/packages/engine-render/src/basics/index.ts b/packages/engine-render/src/basics/index.ts
index 0be0eb9c0b..abc5ef76b7 100644
--- a/packages/engine-render/src/basics/index.ts
+++ b/packages/engine-render/src/basics/index.ts
@@ -29,3 +29,4 @@ export * from './scroll-xy';
export * from './tools';
export * from './transform';
export * from './vector2';
+export * from './text-rotation';
diff --git a/packages/engine-render/src/basics/text-rotation.ts b/packages/engine-render/src/basics/text-rotation.ts
new file mode 100644
index 0000000000..5484527083
--- /dev/null
+++ b/packages/engine-render/src/basics/text-rotation.ts
@@ -0,0 +1,31 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { BooleanNumber, type ITextRotation } from '@univerjs/core';
+
+export const VERTICAL_ROTATE_ANGLE = 90;
+
+export function convertTextRotation(textRotation: ITextRotation) {
+ const { a: angle = 0, v: isVertical = BooleanNumber.FALSE } = textRotation;
+ let centerAngle = 0;
+ let vertexAngle = angle;
+ if (isVertical === BooleanNumber.TRUE) {
+ centerAngle = VERTICAL_ROTATE_ANGLE;
+ vertexAngle = VERTICAL_ROTATE_ANGLE;
+ }
+
+ return { centerAngle, vertexAngle };
+}
diff --git a/packages/engine-render/src/components/sheets/sheet-skeleton.ts b/packages/engine-render/src/components/sheets/sheet-skeleton.ts
index df231d2d52..913d8e71b4 100644
--- a/packages/engine-render/src/components/sheets/sheet-skeleton.ts
+++ b/packages/engine-render/src/components/sheets/sheet-skeleton.ts
@@ -70,6 +70,7 @@ import { columnIterator } from '../docs/common/tools';
import { DocumentSkeleton } from '../docs/doc-skeleton';
import { DocumentViewModel } from '../docs/view-model/document-view-model';
import { Skeleton } from '../skeleton';
+import { convertTextRotation, VERTICAL_ROTATE_ANGLE } from '../../basics/text-rotation';
import type { BorderCache, IFontCacheItem, IStylesCache } from './interfaces';
/**
@@ -178,8 +179,6 @@ export interface IDocumentLayoutObject {
fill?: Nullable<string>;
}
-const VERTICAL_ROTATE_ANGLE = 90;
-
const DEFAULT_PADDING_DATA = {
t: 0,
b: 0,
@@ -1056,13 +1055,7 @@ export class SpreadsheetSkeleton extends Skeleton {
if (cell.f && formulaFirst) {
documentModel = this._getDocumentDataByStyle(cell.f.toString(), {}, {});
} else if (cell.p) {
- const { a: angle = 0, v: isVertical = BooleanNumber.FALSE } = textRotation;
- let centerAngle = 0;
- let vertexAngle = angle;
- if (isVertical === BooleanNumber.TRUE) {
- centerAngle = VERTICAL_ROTATE_ANGLE;
- vertexAngle = VERTICAL_ROTATE_ANGLE;
- }
+ const { centerAngle, vertexAngle } = convertTextRotation(textRotation);
documentModel = this._updateConfigAndGetDocumentModel(
isDeepClone ? Tools.deepClone(cell.p) : cell.p,
horizontalAlign,
diff --git a/packages/sheets-ui/src/services/editor-bridge.service.ts b/packages/sheets-ui/src/services/editor-bridge.service.ts
index 594380be6c..e3cba74b03 100644
--- a/packages/sheets-ui/src/services/editor-bridge.service.ts
+++ b/packages/sheets-ui/src/services/editor-bridge.service.ts
@@ -26,7 +26,7 @@ import {
toDisposable,
} from '@univerjs/core';
import type { Engine, IDocumentLayoutObject, Scene } from '@univerjs/engine-render';
-import { DeviceInputEventType, fixLineWidthByScale, getCanvasOffsetByEngine } from '@univerjs/engine-render';
+import { convertTextRotation, DeviceInputEventType, fixLineWidthByScale, getCanvasOffsetByEngine } from '@univerjs/engine-render';
import type { ISheetLocation } from '@univerjs/sheets';
import type { KeyCode } from '@univerjs/ui';
import type { IDisposable } from '@wendellhu/redi';
@@ -232,7 +232,16 @@ export class EditorBridgeService extends Disposable implements IEditorBridgeServ
let documentLayoutObject = cell && skeleton.getCellDocumentModelWithFormula(cell);
if (!documentLayoutObject || documentLayoutObject.documentModel == null) {
- documentLayoutObject = skeleton.getBlankCellDocumentModel(cell);
+ const blankModel = skeleton.getBlankCellDocumentModel(cell);
+
+ if (documentLayoutObject != null) {
+ const { verticalAlign, horizontalAlign, wrapStrategy, textRotation, fill } = documentLayoutObject;
+ const { centerAngle, vertexAngle } = convertTextRotation(textRotation);
+ blankModel.documentModel!.documentStyle.renderConfig = {
+ verticalAlign, horizontalAlign, wrapStrategy, background: { rgb: fill }, centerAngle, vertexAngle,
+ };
+ }
+ documentLayoutObject = blankModel;
}
documentLayoutObject.documentModel?.setZoomRatio(Math.max(scaleX, scaleY));