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: underline not work when align bottom & moving clipboard controller from steady to render (#3139)

lumix10484d8a5c57
diff --git a/packages/engine-render/src/components/sheets/extensions/font.ts b/packages/engine-render/src/components/sheets/extensions/font.ts
index e5d796e39b..54a14cb13a 100644
--- a/packages/engine-render/src/components/sheets/extensions/font.ts
+++ b/packages/engine-render/src/components/sheets/extensions/font.ts
@@ -306,8 +306,8 @@ export class Font extends SheetExtension {
}
const { documentSkeleton, vertexAngle = 0, wrapStrategy } = docsConfig;
- const cellWidth = endX - startX;
const cellHeight = endY - startY;
+ const cellWidth = endX - startX;
if (wrapStrategy === WrapStrategy.WRAP && vertexAngle === 0) {
documentSkeleton.getViewModel().getDataModel().updateDocumentDataPageSize(cellWidth);
@@ -336,9 +336,7 @@ export class Font extends SheetExtension {
}
documentSkeleton.makeDirty(false);
-
documents.resize(cellWidth, cellHeight);
-
documents.changeSkeleton(documentSkeleton).render(ctx);
}
diff --git a/packages/engine-render/src/components/sheets/extensions/sheet-extension.ts b/packages/engine-render/src/components/sheets/extensions/sheet-extension.ts
index a973139381..b10b7b7555 100644
--- a/packages/engine-render/src/components/sheets/extensions/sheet-extension.ts
+++ b/packages/engine-render/src/components/sheets/extensions/sheet-extension.ts
@@ -27,6 +27,16 @@ export enum SHEET_EXTENSION_TYPE {
export class SheetExtension extends ComponentExtension<SpreadsheetSkeleton, SHEET_EXTENSION_TYPE, IRange[]> {
override type = SHEET_EXTENSION_TYPE.GRID;
+ /**
+ * Get ISelectionCellWithMergeInfo by cell rowIndex and cell columnIndex.
+ * The startXY in return value does not include rowHeader and columnHeader.
+ * @param rowIndex
+ * @param columnIndex
+ * @param rowHeightAccumulation
+ * @param columnWidthAccumulation
+ * @param dataMergeCache
+ * @returns ISelectionCellWithMergeInfo
+ */
getCellIndex(
rowIndex: number,
columnIndex: number,
@@ -34,6 +44,7 @@ export class SheetExtension extends ComponentExtension<SpreadsheetSkeleton, SHEE
columnWidthAccumulation: number[],
dataMergeCache: IRange[]
) {
+ // TODO @lumixraku: there are two coords in sheet!! This one does not include rowHeader and columnHeader. Should keep coord to be only one.
return getCellByIndex(rowIndex, columnIndex, rowHeightAccumulation, columnWidthAccumulation, dataMergeCache);
}
diff --git a/packages/engine-render/src/components/sheets/sheet-skeleton.ts b/packages/engine-render/src/components/sheets/sheet-skeleton.ts
index 9f5b203ef5..0c5acdb319 100644
--- a/packages/engine-render/src/components/sheets/sheet-skeleton.ts
+++ b/packages/engine-render/src/components/sheets/sheet-skeleton.ts
@@ -1851,7 +1851,7 @@ export class SpreadsheetSkeleton extends Skeleton {
paddingData = {
t: 0,
r: 2,
- b: 1,
+ b: 2, // must over 1, see https://github.com/dream-num/univer/issues/2727
l: 2,
},
horizontalAlign = HorizontalAlign.UNSPECIFIED,
diff --git a/packages/engine-render/src/engine.ts b/packages/engine-render/src/engine.ts
index 35c0055880..b71162344e 100644
--- a/packages/engine-render/src/engine.ts
+++ b/packages/engine-render/src/engine.ts
@@ -108,7 +108,7 @@ export class Engine extends ThinEngine<Scene> {
private _remainCapture: number = -1;
/** previous pointer position */
- private pointer: { [deviceSlot: number]: number } = {};
+ private _pointer: { [deviceSlot: number]: number } = {};
private _mouseId = -1;
@@ -465,10 +465,10 @@ export class Engine extends ThinEngine<Scene> {
// const previousVertical = this.pointer[PointerInput.Vertical];
// const previousDeltaHorizontal = this.pointer[PointerInput.DeltaHorizontal];
// const previousDeltaVertical = this.pointer[PointerInput.DeltaVertical];
- this.pointer[PointerInput.Horizontal] = evt.clientX;
- this.pointer[PointerInput.Vertical] = evt.clientY;
- this.pointer[PointerInput.DeltaHorizontal] = evt.movementX;
- this.pointer[PointerInput.DeltaVertical] = evt.movementY;
+ this._pointer[PointerInput.Horizontal] = evt.clientX;
+ this._pointer[PointerInput.Vertical] = evt.clientY;
+ this._pointer[PointerInput.DeltaHorizontal] = evt.movementX;
+ this._pointer[PointerInput.DeltaVertical] = evt.movementY;
const deviceEvent = evt as unknown as IPointerEvent;
deviceEvent.deviceType = deviceType;
deviceEvent.inputIndex = PointerInput.Horizontal;// horizon 0 vertical 1
@@ -507,9 +507,9 @@ export class Engine extends ThinEngine<Scene> {
// Lets Propagate the event for move with same position.
if (!this._usingSafari && evt.button !== -1) {
deviceEvent.inputIndex = evt.button + 2;
- deviceEvent.previousState = this.pointer[evt.button + 2];
- this.pointer[evt.button + 2] = this.pointer[evt.button + 2] ? 0 : 1; // Reverse state of button if evt.button has value
- deviceEvent.currentState = this.pointer[evt.button + 2];
+ deviceEvent.previousState = this._pointer[evt.button + 2];
+ this._pointer[evt.button + 2] = this._pointer[evt.button + 2] ? 0 : 1; // Reverse state of button if evt.button has value
+ deviceEvent.currentState = this._pointer[evt.button + 2];
this.onInputChanged$.emitEvent(deviceEvent);
}
};
@@ -519,9 +519,9 @@ export class Engine extends ThinEngine<Scene> {
// TODO: maybe we should wrap the native event to an CustomEvent
const deviceType = this._getPointerType(evt);
- const previousHorizontal = this.pointer[PointerInput.Horizontal];
- const previousVertical = this.pointer[PointerInput.Vertical];
- const previousButton = this.pointer[evt.button + 2];
+ const previousHorizontal = this._pointer[PointerInput.Horizontal];
+ const previousVertical = this._pointer[PointerInput.Vertical];
+ const previousButton = this._pointer[evt.button + 2];
if (deviceType === DeviceType.Mouse) {
// Mouse; Among supported browsers, value is either 1 or 0 for mouse
@@ -545,9 +545,9 @@ export class Engine extends ThinEngine<Scene> {
}
}
- this.pointer[PointerInput.Horizontal] = evt.clientX;
- this.pointer[PointerInput.Vertical] = evt.clientY;
- this.pointer[evt.button + 2] = 1;
+ this._pointer[PointerInput.Horizontal] = evt.clientX;
+ this._pointer[PointerInput.Vertical] = evt.clientY;
+ this._pointer[evt.button + 2] = 1;
const deviceEvent = evt as IPointerEvent;
deviceEvent.deviceType = deviceType;
@@ -555,14 +555,14 @@ export class Engine extends ThinEngine<Scene> {
if (previousHorizontal !== evt.clientX) {
deviceEvent.inputIndex = PointerInput.Horizontal;
deviceEvent.previousState = previousHorizontal;
- deviceEvent.currentState = this.pointer[PointerInput.Horizontal];
+ deviceEvent.currentState = this._pointer[PointerInput.Horizontal];
this.onInputChanged$.emitEvent(deviceEvent);
}
if (previousVertical !== evt.clientY) {
deviceEvent.inputIndex = PointerInput.Vertical;
deviceEvent.previousState = previousVertical;
- deviceEvent.currentState = this.pointer[PointerInput.Vertical];
+ deviceEvent.currentState = this._pointer[PointerInput.Vertical];
this.onInputChanged$.emitEvent(deviceEvent);
}
@@ -570,7 +570,7 @@ export class Engine extends ThinEngine<Scene> {
// evt.button + 2 ---> leftClick: 2, middleClick: 3, rightClick:4
deviceEvent.inputIndex = evt.button + 2;
deviceEvent.previousState = previousButton;
- deviceEvent.currentState = this.pointer[evt.button + 2];
+ deviceEvent.currentState = this._pointer[evt.button + 2];
this.onInputChanged$.emitEvent(deviceEvent);
};
@@ -578,13 +578,13 @@ export class Engine extends ThinEngine<Scene> {
const evt = _evt as PointerEvent | MouseEvent;
const deviceType = this._getPointerType(evt);
- const previousHorizontal = this.pointer[PointerInput.Horizontal];
- const previousVertical = this.pointer[PointerInput.Vertical];
- const previousButton = this.pointer[evt.button + 2];
+ const previousHorizontal = this._pointer[PointerInput.Horizontal];
+ const previousVertical = this._pointer[PointerInput.Vertical];
+ const previousButton = this._pointer[evt.button + 2];
- this.pointer[PointerInput.Horizontal] = evt.clientX;
- this.pointer[PointerInput.Vertical] = evt.clientY;
- this.pointer[evt.button + 2] = 0;
+ this._pointer[PointerInput.Horizontal] = evt.clientX;
+ this._pointer[PointerInput.Vertical] = evt.clientY;
+ this._pointer[evt.button + 2] = 0;
const deviceEvent = evt as IPointerEvent;
deviceEvent.deviceType = deviceType;
@@ -592,21 +592,21 @@ export class Engine extends ThinEngine<Scene> {
if (previousHorizontal !== evt.clientX) {
deviceEvent.inputIndex = PointerInput.Horizontal;
deviceEvent.previousState = previousHorizontal;
- deviceEvent.currentState = this.pointer[PointerInput.Horizontal];
+ deviceEvent.currentState = this._pointer[PointerInput.Horizontal];
this.onInputChanged$.emitEvent(deviceEvent);
}
if (previousVertical !== evt.clientY) {
deviceEvent.inputIndex = PointerInput.Vertical;
deviceEvent.previousState = previousVertical;
- deviceEvent.currentState = this.pointer[PointerInput.Vertical];
+ deviceEvent.currentState = this._pointer[PointerInput.Vertical];
this.onInputChanged$.emitEvent(deviceEvent);
}
deviceEvent.inputIndex = evt.button + 2;
deviceEvent.previousState = previousButton;
- deviceEvent.currentState = this.pointer[evt.button + 2];
+ deviceEvent.currentState = this._pointer[evt.button + 2];
const canvasEle = this.getCanvasElement();
if (
@@ -625,7 +625,7 @@ export class Engine extends ThinEngine<Scene> {
// We don't want to unregister the mouse because we may miss input data when a mouse is moving after a click
if (deviceType !== DeviceType.Mouse) {
- this.pointer = {};
+ this._pointer = {};
}
};
@@ -681,39 +681,39 @@ export class Engine extends ThinEngine<Scene> {
// this._mouseId = -1;
}
- this.pointer = {};
+ this._pointer = {};
};
this._pointerWheelEvent = (evt: any) => {
const deviceType = DeviceType.Mouse;
// Store previous values for event
- const previousWheelScrollX = this.pointer[PointerInput.MouseWheelX];
- const previousWheelScrollY = this.pointer[PointerInput.MouseWheelY];
- const previousWheelScrollZ = this.pointer[PointerInput.MouseWheelZ];
+ const previousWheelScrollX = this._pointer[PointerInput.MouseWheelX];
+ const previousWheelScrollY = this._pointer[PointerInput.MouseWheelY];
+ const previousWheelScrollZ = this._pointer[PointerInput.MouseWheelZ];
- this.pointer[PointerInput.MouseWheelX] = evt.deltaX || 0;
- this.pointer[PointerInput.MouseWheelY] = evt.deltaY || evt.wheelDelta || 0;
- this.pointer[PointerInput.MouseWheelZ] = evt.deltaZ || 0;
+ this._pointer[PointerInput.MouseWheelX] = evt.deltaX || 0;
+ this._pointer[PointerInput.MouseWheelY] = evt.deltaY || evt.wheelDelta || 0;
+ this._pointer[PointerInput.MouseWheelZ] = evt.deltaZ || 0;
const deviceEvent = evt as IPointerEvent;
deviceEvent.deviceType = deviceType;
- if (this.pointer[PointerInput.MouseWheelX] !== 0) {
+ if (this._pointer[PointerInput.MouseWheelX] !== 0) {
deviceEvent.inputIndex = PointerInput.MouseWheelX;
deviceEvent.previousState = previousWheelScrollX;
- deviceEvent.currentState = this.pointer[PointerInput.MouseWheelX];
+ deviceEvent.currentState = this._pointer[PointerInput.MouseWheelX];
this.onInputChanged$.emitEvent(deviceEvent);
}
- if (this.pointer[PointerInput.MouseWheelY] !== 0) {
+ if (this._pointer[PointerInput.MouseWheelY] !== 0) {
deviceEvent.inputIndex = PointerInput.MouseWheelY;
deviceEvent.previousState = previousWheelScrollY;
- deviceEvent.currentState = this.pointer[PointerInput.MouseWheelY];
+ deviceEvent.currentState = this._pointer[PointerInput.MouseWheelY];
this.onInputChanged$.emitEvent(deviceEvent);
}
- if (this.pointer[PointerInput.MouseWheelZ] !== 0) {
+ if (this._pointer[PointerInput.MouseWheelZ] !== 0) {
deviceEvent.inputIndex = PointerInput.MouseWheelZ;
deviceEvent.previousState = previousWheelScrollZ;
- deviceEvent.currentState = this.pointer[PointerInput.MouseWheelZ];
+ deviceEvent.currentState = this._pointer[PointerInput.MouseWheelZ];
this.onInputChanged$.emitEvent(deviceEvent);
}
};
@@ -764,15 +764,15 @@ export class Engine extends ThinEngine<Scene> {
const deviceType = this._getPointerType(evt);
// Store previous values for event
- const previousHorizontal = this.pointer[PointerInput.Horizontal];
- const previousVertical = this.pointer[PointerInput.Vertical];
- const previousDeltaHorizontal = this.pointer[PointerInput.DeltaHorizontal];
- const previousDeltaVertical = this.pointer[PointerInput.DeltaVertical];
-
- this.pointer[PointerInput.Horizontal] = evt.clientX;
- this.pointer[PointerInput.Vertical] = evt.clientY;
- this.pointer[PointerInput.DeltaHorizontal] = evt.movementX;
- this.pointer[PointerInput.DeltaVertical] = evt.movementY;
+ const previousHorizontal = this._pointer[PointerInput.Horizontal];
+ const previousVertical = this._pointer[PointerInput.Vertical];
+ const previousDeltaHorizontal = this._pointer[PointerInput.DeltaHorizontal];
+ const previousDeltaVertical = this._pointer[PointerInput.DeltaVertical];
+
+ this._pointer[PointerInput.Horizontal] = evt.clientX;
+ this._pointer[PointerInput.Vertical] = evt.clientY;
+ this._pointer[PointerInput.DeltaHorizontal] = evt.movementX;
+ this._pointer[PointerInput.DeltaVertical] = evt.movementY;
// console.log('pointerMoveEvent_1', previousHorizontal, evt.clientX, previousVertical, evt.clientY, this._pointer);
const deviceEvent = evt as IPointerEvent;
deviceEvent.deviceType = deviceType;
@@ -780,28 +780,28 @@ export class Engine extends ThinEngine<Scene> {
if (previousHorizontal !== evt.clientX) {
deviceEvent.inputIndex = PointerInput.Horizontal;
deviceEvent.previousState = previousHorizontal;
- deviceEvent.currentState = this.pointer[PointerInput.Horizontal];
+ deviceEvent.currentState = this._pointer[PointerInput.Horizontal];
this.onInputChanged$.emitEvent(deviceEvent);
}
if (previousVertical !== evt.clientY) {
deviceEvent.inputIndex = PointerInput.Vertical;
deviceEvent.previousState = previousVertical;
- deviceEvent.currentState = this.pointer[PointerInput.Vertical];
+ deviceEvent.currentState = this._pointer[PointerInput.Vertical];
this.onInputChanged$.emitEvent(deviceEvent);
}
- if (this.pointer[PointerInput.DeltaHorizontal] !== 0) {
+ if (this._pointer[PointerInput.DeltaHorizontal] !== 0) {
deviceEvent.inputIndex = PointerInput.DeltaHorizontal;
deviceEvent.previousState = previousDeltaHorizontal;
- deviceEvent.currentState = this.pointer[PointerInput.DeltaHorizontal];
+ deviceEvent.currentState = this._pointer[PointerInput.DeltaHorizontal];
this.onInputChanged$.emitEvent(deviceEvent);
}
- if (this.pointer[PointerInput.DeltaVertical] !== 0) {
+ if (this._pointer[PointerInput.DeltaVertical] !== 0) {
deviceEvent.inputIndex = PointerInput.DeltaVertical;
deviceEvent.previousState = previousDeltaVertical;
- deviceEvent.currentState = this.pointer[PointerInput.DeltaVertical];
+ deviceEvent.currentState = this._pointer[PointerInput.DeltaVertical];
this.onInputChanged$.emitEvent(deviceEvent);
}
@@ -809,9 +809,9 @@ export class Engine extends ThinEngine<Scene> {
// Lets Propagate the event for move with same position.
if (!this._usingSafari && evt.button !== -1) {
deviceEvent.inputIndex = evt.button + 2;
- deviceEvent.previousState = this.pointer[evt.button + 2];
- this.pointer[evt.button + 2] = this.pointer[evt.button + 2] ? 0 : 1; // Reverse state of button if evt.button has value
- deviceEvent.currentState = this.pointer[evt.button + 2];
+ deviceEvent.previousState = this._pointer[evt.button + 2];
+ this._pointer[evt.button + 2] = this._pointer[evt.button + 2] ? 0 : 1; // Reverse state of button if evt.button has value
+ deviceEvent.currentState = this._pointer[evt.button + 2];
this.onInputChanged$.emitEvent(deviceEvent);
}
};
diff --git a/packages/sheets-ui/src/controllers/clipboard/clipboard.controller.ts b/packages/sheets-ui/src/controllers/clipboard/clipboard.controller.ts
index fc8ac73303..34030f8c56 100644
--- a/packages/sheets-ui/src/controllers/clipboard/clipboard.controller.ts
+++ b/packages/sheets-ui/src/controllers/clipboard/clipboard.controller.ts
@@ -99,7 +99,7 @@ import {
* This controller add basic clipboard logic for basic features such as text color / BISU / row widths to the clipboard
* service. You can create a similar clipboard controller to add logic for your own features.
*/
-@OnLifecycle(LifecycleStages.Steady, SheetClipboardController)
+@OnLifecycle(LifecycleStages.Rendered, SheetClipboardController)
export class SheetClipboardController extends RxDisposable {
constructor(
@Inject(Injector) private readonly _injector: Injector,
@@ -114,7 +114,6 @@ export class SheetClipboardController extends RxDisposable {
@Optional(ITextSelectionRenderManager) private readonly _textSelectionRenderManager?: ITextSelectionRenderManager
) {
super();
-
this._init();
this._textSelectionRenderManager?.onPaste$.pipe(takeUntil(this.dispose$)).subscribe((config) => {
@@ -155,6 +154,7 @@ export class SheetClipboardController extends RxDisposable {
this.disposeWithMe({ dispose: () => disposables.forEach((d) => d.dispose()) });
}
+ //eslint-disable-next-line max-lines-per-function
private _initCopyingHooks(): ISheetClipboardHook {
const self = this;
let currentSheet: Worksheet | null = null;
@@ -278,6 +278,7 @@ export class SheetClipboardController extends RxDisposable {
};
}
+ //eslint-disable-next-line max-lines-per-function
private _initPastingHook(): ISheetClipboardHook {
const self = this;
@@ -603,6 +604,7 @@ export class SheetClipboardController extends RxDisposable {
});
}
+ //eslint-disable-next-line max-lines-per-function
private _initSpecialPasteHooks() {
const self = this;
diff --git a/packages/sheets-ui/src/services/editor-bridge.service.ts b/packages/sheets-ui/src/services/editor-bridge.service.ts
index f8dd539077..73c0aa9d47 100644
--- a/packages/sheets-ui/src/services/editor-bridge.service.ts
+++ b/packages/sheets-ui/src/services/editor-bridge.service.ts
@@ -281,7 +281,8 @@ export class EditorBridgeService extends Disposable implements IEditorBridgeServ
}
documentLayoutObject = blankModel;
}
-
+ // background of canvas is set to transparent, so if no bgcolor sepcified in curr cell, set it to white.
+ documentLayoutObject.fill = documentLayoutObject.fill || '#fff';
documentLayoutObject.documentModel?.setZoomRatio(Math.max(scaleX, scaleY));
if (cell?.isInArrayFormulaRange === true) {
diff --git a/packages/sheets-ui/src/views/editor-container/index.module.less b/packages/sheets-ui/src/views/editor-container/index.module.less
index 6576f6c816..37c8508a3a 100644
--- a/packages/sheets-ui/src/views/editor-container/index.module.less
+++ b/packages/sheets-ui/src/views/editor-container/index.module.less
@@ -21,7 +21,9 @@
width: 100%;
height: 100%;
- background: white;
+ // Do not set a color, it should be transparent.
+ // create a rendering editor canvas may took 200ms, there would be a white flash if rendering have not finished.
+ // background: white;
canvas {
position: absolute;