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: fix clipboard when dispose (#4253)

ybzkyf06ab868f05b
diff --git a/packages/sheets-ui/src/services/clipboard/clipboard.service.ts b/packages/sheets-ui/src/services/clipboard/clipboard.service.ts
index d0bcbaebca..b6b8d3d213 100644
--- a/packages/sheets-ui/src/services/clipboard/clipboard.service.ts
+++ b/packages/sheets-ui/src/services/clipboard/clipboard.service.ts
@@ -147,6 +147,7 @@ export class SheetClipboardService extends Disposable implements ISheetClipboard
this._copyContentCache = new CopyContentCache();
this.disposeWithMe(this._htmlToUSM);
+ this._initUnitDisposed();
}
copyContentCache(): CopyContentCache {
@@ -1082,6 +1083,17 @@ export class SheetClipboardService extends Disposable implements ISheetClipboard
this._copyMarkId = null;
}
}
+
+ private _initUnitDisposed() {
+ this.disposeWithMe(
+ this._univerInstanceService.getTypeOfUnitDisposed$<Workbook>(UniverInstanceType.UNIVER_SHEET).subscribe((workbook) => {
+ if (workbook) {
+ const copyCache = this.copyContentCache();
+ copyCache.clearWithUnitId(workbook.getUnitId());
+ }
+ })
+ );
+ }
}
// #region copy generation
diff --git a/packages/sheets-ui/src/services/clipboard/copy-content-cache.ts b/packages/sheets-ui/src/services/clipboard/copy-content-cache.ts
index 2e71416ac4..476c4f7094 100644
--- a/packages/sheets-ui/src/services/clipboard/copy-content-cache.ts
+++ b/packages/sheets-ui/src/services/clipboard/copy-content-cache.ts
@@ -15,10 +15,10 @@
*/
import type { Nullable, ObjectMatrix } from '@univerjs/core';
-import { LRUMap, Tools } from '@univerjs/core';
-
import type { IDiscreteRange } from '../../controllers/utils/range-tools';
+
import type { COPY_TYPE, ICellDataWithSpanInfo } from './type';
+import { LRUMap, Tools } from '@univerjs/core';
const COPY_CONTENT_CACHE_LIMIT = 10;
const ID_LENGTH = 6;
@@ -63,6 +63,14 @@ export class CopyContentCache {
clear() {
this._cache.clear();
}
+
+ clearWithUnitId(unitId: string) {
+ this._cache.forEach((value, key) => {
+ if (value.unitId === unitId) {
+ this._cache.delete(key);
+ }
+ });
+ }
}
export const copyContentCache = new CopyContentCache();
diff --git a/packages/sheets-ui/src/views/permission/panel/index.tsx b/packages/sheets-ui/src/views/permission/panel/index.tsx
index b612cfb5b9..90fc59949a 100644
--- a/packages/sheets-ui/src/views/permission/panel/index.tsx
+++ b/packages/sheets-ui/src/views/permission/panel/index.tsx
@@ -51,6 +51,7 @@ export const SheetPermissionPanel = ({ showDetail, fromSheetBar, rule, oldRule }
fromSheetBar={fromSheetBar}
rule={rule}
oldRule={oldRule}
+ key={fromSheetBar ? 'sheet-bar' : 'normal'}
/>
)
: <SheetPermissionPanelList key={key} />