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.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix: some bugs in copy paste (#652)
YuHongba307fbe077c
diff --git a/packages/sheets-ui/src/controllers/status-bar.controller.ts b/packages/sheets-ui/src/controllers/status-bar.controller.tsindex 8f93be1001..0922c7bc42 100644--- a/packages/sheets-ui/src/controllers/status-bar.controller.ts+++ b/packages/sheets-ui/src/controllers/status-bar.controller.ts@@ -1,11 +1,18 @@import type { IRange } from '@univerjs/core';-import { Disposable, IUniverInstanceService, LifecycleStages, ObjectMatrix, OnLifecycle } from '@univerjs/core';+import {+ Disposable,+ IUniverInstanceService,+ LifecycleStages,+ ObjectMatrix,+ OnLifecycle,+ toDisposable,+} from '@univerjs/core';import type { BaseValueObject, ISheetData } from '@univerjs/engine-formula';import { FormulaEngineService, RangeReferenceObject } from '@univerjs/engine-formula';-import type { ISelectionWithStyle } from '@univerjs/sheets';import { SelectionManagerService } from '@univerjs/sheets';import { Inject } from '@wendellhu/redi';+import { ISelectionRenderService } from '..';import type { IStatusBarServiceStatus } from '../services/status-bar.service';import { IStatusBarService } from '../services/status-bar.service';@@ -15,7 +22,8 @@ export class StatusBarController extends Disposable {@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,@Inject(SelectionManagerService) private readonly _selectionManagerService: SelectionManagerService,@Inject(FormulaEngineService) private readonly _formulaEngineService: FormulaEngineService,- @IStatusBarService private readonly _statusBarService: IStatusBarService+ @IStatusBarService private readonly _statusBarService: IStatusBarService,+ @ISelectionRenderService private readonly _selectionRenderService: ISelectionRenderService) {super();@@ -27,14 +35,27 @@ export class StatusBarController extends Disposable {}private _registerSelectionListener(): void {- this._selectionManagerService.selectionInfo$.subscribe((selectionRangeWithStyle) => {- if (selectionRangeWithStyle) {- this._calculateSelection(selectionRangeWithStyle);- }- });+ this.disposeWithMe(+ toDisposable(+ this._selectionRenderService.selectionMoving$.subscribe((selections) => {+ if (selections) {+ this._calculateSelection(selections);+ }+ })+ )+ );+ this.disposeWithMe(+ toDisposable(+ this._selectionManagerService.selectionInfo$.subscribe((selections) => {+ if (selections) {+ this._calculateSelection(selections.map((selection) => selection.range));+ }+ })+ )+ );}- private _calculateSelection(selections: ISelectionWithStyle[]) {+ private _calculateSelection(selections: IRange[]) {const workbook = this._univerInstanceService.getCurrentUniverSheetInstance();const unitId = workbook.getUnitId();const sheetId = workbook.getActiveSheet().getSheetId();@@ -50,8 +71,8 @@ export class StatusBarController extends Disposable {columnCount: sheetConfig.columnCount,};});- if (selections?.length && (selections?.length > 1 || !this._isSingleCell(selections[0].range))) {- const refs = selections.map((s) => new RangeReferenceObject(s.range, sheetId, unitId));+ if (selections?.length && (selections?.length > 1 || !this._isSingleCell(selections[0]))) {+ const refs = selections.map((s) => new RangeReferenceObject(s, sheetId, unitId));refs.forEach((ref) =>ref.setUnitData({[unitId]: sheetData,diff --git a/packages/sheets-ui/src/services/clipboard/clipboard.service.ts b/packages/sheets-ui/src/services/clipboard/clipboard.service.tsindex 7f166b00f3..13887c4960 100644--- a/packages/sheets-ui/src/services/clipboard/clipboard.service.ts+++ b/packages/sheets-ui/src/services/clipboard/clipboard.service.ts@@ -112,6 +112,10 @@ export class SheetClipboardService extends Disposable implements ISheetClipboardconst cellData = matrix.getValue(r, c);if (cellData) {matrixFragment.setValue(r - startRow, c - startColumn, Tools.deepClone(cellData));+ } else {+ matrixFragment.setValue(r - startRow, c - startColumn, {+ v: null,+ });}}}@@ -313,7 +317,7 @@ export class SheetClipboardService extends Disposable implements ISheetClipboardprivate async _pasteInternal(copyId: string, pasteType: string): Promise<boolean> {const target = this._getPastingTarget();const { selection, workbookId, worksheetId } = target;- const cachedData = copyContentCache.get(copyId);+ const cachedData = Tools.deepClone(copyContentCache.get(copyId));const { range, matrix: cellMatrix } = cachedData || {};if (!selection || !cellMatrix || !cachedData || !range) {return false;diff --git a/packages/sheets-ui/src/views/sheet-bar/index.module.less b/packages/sheets-ui/src/views/sheet-bar/index.module.lessindex da64e0fac3..90e8f65e7e 100644--- a/packages/sheets-ui/src/views/sheet-bar/index.module.less+++ b/packages/sheets-ui/src/views/sheet-bar/index.module.less@@ -14,7 +14,6 @@min-width: calc(100% - @zoom-slider-width - @status-bar-max-width);max-width: calc(100% - @zoom-slider-width);height: 100%;- margin-right: @margin-right;background-color: rgb(var(--bg-color));@@ -26,7 +25,7 @@margin: var(--margin-xxs);transition: display .2s;-+&-divider::after {content: "";