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.

feat(doc): refactor doc clipboard and support firefox (#1302)

Wenzhao Hu66b9f7c5cd2e
diff --git a/packages/docs/src/commands/commands/clipboard.command.ts b/packages/docs/src/commands/commands/clipboard.command.ts
index 7c06b34c58..39e7996634 100644
--- a/packages/docs/src/commands/commands/clipboard.command.ts
+++ b/packages/docs/src/commands/commands/clipboard.command.ts
@@ -14,19 +14,33 @@
* limitations under the License.
*/
-import type { IMultiCommand } from '@univerjs/core';
+import type { IContextService, IMultiCommand } from '@univerjs/core';
import { CommandType, EDITOR_ACTIVATED, FOCUSING_DOC } from '@univerjs/core';
-import { CopyCommand, CutCommand, PasteCommand } from '@univerjs/ui';
+import { CopyCommand, CutCommand, IClipboardInterfaceService, PasteCommand } from '@univerjs/ui';
+import type { IAccessor } from '@wendellhu/redi';
+
+import { IDocClipboardService } from '../../services/clipboard/clipboard.service';
+
+export function whenDocOrEditor(contextService: IContextService): boolean {
+ return contextService.getContextValue(FOCUSING_DOC) || contextService.getContextValue(EDITOR_ACTIVATED);
+}
+
+const DOC_CLIPBOARD_PRIORITY = 999;
+
+// Commands here should have higher priority than commands of sheets
+// in packages/sheets-ui/src/commands/commands/clipboard.command.ts
export const DocCopyCommand: IMultiCommand = {
id: CopyCommand.id,
name: 'doc.command.copy',
type: CommandType.COMMAND,
multi: true,
- priority: 999,
- preconditions: (contextService) =>
- contextService.getContextValue(FOCUSING_DOC) || contextService.getContextValue(EDITOR_ACTIVATED),
- handler: async () => true,
+ priority: DOC_CLIPBOARD_PRIORITY,
+ preconditions: whenDocOrEditor,
+ handler: async (accessor: IAccessor) => {
+ const docClipboardService = accessor.get(IDocClipboardService);
+ return docClipboardService.copy();
+ },
};
export const DocCutCommand: IMultiCommand = {
@@ -34,10 +48,12 @@ export const DocCutCommand: IMultiCommand = {
name: 'doc.command.cut',
type: CommandType.COMMAND,
multi: true,
- priority: 999,
- preconditions: (contextService) =>
- contextService.getContextValue(FOCUSING_DOC) || contextService.getContextValue(EDITOR_ACTIVATED),
- handler: async () => true,
+ priority: DOC_CLIPBOARD_PRIORITY,
+ preconditions: whenDocOrEditor,
+ handler: async (accessor: IAccessor) => {
+ const docClipboardService = accessor.get(IDocClipboardService);
+ return docClipboardService.cut();
+ },
};
export const DocPasteCommand: IMultiCommand = {
@@ -45,8 +61,17 @@ export const DocPasteCommand: IMultiCommand = {
name: 'doc.command.paste',
type: CommandType.COMMAND,
multi: true,
- priority: 999, // Need to bigger than SheetPasteCommand's priority.
- preconditions: (contextService) =>
- contextService.getContextValue(FOCUSING_DOC) || contextService.getContextValue(EDITOR_ACTIVATED),
- handler: async () => true,
+ priority: DOC_CLIPBOARD_PRIORITY,
+ preconditions: whenDocOrEditor,
+ handler: async (accessor: IAccessor) => {
+ const docClipboardService = accessor.get(IDocClipboardService);
+ const clipboardInterfaceService = accessor.get(IClipboardInterfaceService);
+
+ const clipboardItems = await clipboardInterfaceService.read();
+ if (clipboardItems.length === 0) {
+ return false;
+ }
+
+ return docClipboardService.paste(clipboardItems);
+ },
};
diff --git a/packages/docs/src/controllers/clipboard.controller.ts b/packages/docs/src/controllers/clipboard.controller.ts
index b2966439dc..850aa37eb6 100644
--- a/packages/docs/src/controllers/clipboard.controller.ts
+++ b/packages/docs/src/controllers/clipboard.controller.ts
@@ -14,224 +14,55 @@
* limitations under the License.
*/
-import type { ICommandInfo, IDocumentBody } from '@univerjs/core';
import {
- Disposable,
- EDITOR_ACTIVATED,
- FOCUSING_DOC,
ICommandService,
IContextService,
- ILogService,
- IUniverInstanceService,
LifecycleStages,
OnLifecycle,
+ RxDisposable,
} from '@univerjs/core';
-import { Inject } from '@wendellhu/redi';
+import { IClipboardInterfaceService } from '@univerjs/ui';
-import { DocCopyCommand, DocCutCommand, DocPasteCommand } from '../commands/commands/clipboard.command';
+import { ITextSelectionRenderManager } from '@univerjs/engine-render';
+import { takeUntil } from 'rxjs';
+import { DocCopyCommand, DocCutCommand, DocPasteCommand, whenDocOrEditor } from '../commands/commands/clipboard.command';
import { CutContentCommand, InnerPasteCommand } from '../commands/commands/clipboard.inner.command';
import { IDocClipboardService } from '../services/clipboard/clipboard.service';
-import { TextSelectionManagerService } from '../services/text-selection-manager.service';
-@OnLifecycle(LifecycleStages.Rendered, DocClipboardController)
-export class DocClipboardController extends Disposable {
+@OnLifecycle(LifecycleStages.Steady, DocClipboardController)
+export class DocClipboardController extends RxDisposable {
constructor(
- @ILogService private readonly _logService: ILogService,
@ICommandService private readonly _commandService: ICommandService,
- @IUniverInstanceService private readonly _currentUniverService: IUniverInstanceService,
+ @IClipboardInterfaceService private readonly _clipboardInterfaceService: IClipboardInterfaceService,
@IDocClipboardService private readonly _docClipboardService: IDocClipboardService,
- @Inject(TextSelectionManagerService) private readonly _textSelectionManagerService: TextSelectionManagerService,
+ @ITextSelectionRenderManager private readonly _textSelectionRenderManager: ITextSelectionRenderManager,
@IContextService private readonly _contextService: IContextService
) {
super();
- this._commandExecutedListener();
- this.initialize();
- }
-
- initialize() {
- [DocCopyCommand, DocCutCommand, DocPasteCommand].forEach((command) =>
- this.disposeWithMe(this._commandService.registerMultipleCommand(command))
- );
- [InnerPasteCommand, CutContentCommand].forEach((command) =>
- this.disposeWithMe(this._commandService.registerCommand(command))
- );
- }
-
- private _commandExecutedListener() {
- const updateCommandList = [DocCutCommand.id, DocCopyCommand.id, DocPasteCommand.id];
-
- this.disposeWithMe(
- this._commandService.onCommandExecuted((command: ICommandInfo) => {
- if (!updateCommandList.includes(command.id)) {
- return;
- }
-
- if (
- !this._contextService.getContextValue(FOCUSING_DOC) &&
- !this._contextService.getContextValue(EDITOR_ACTIVATED)
- ) {
- return;
- }
-
- switch (command.id) {
- case DocPasteCommand.id: {
- this._handlePaste();
- break;
- }
-
- case DocCopyCommand.id: {
- this._handleCopy();
- break;
- }
-
- case DocCutCommand.id: {
- this._handleCut();
- break;
- }
-
- default:
- throw new Error(`Unhandled command ${command.id}`);
- }
- })
- );
- }
-
- private async _handlePaste() {
- const { _docClipboardService: clipboard } = this;
- const {
- segmentId,
- endOffset: activeEndOffset,
- style,
- } = this._textSelectionManagerService.getActiveRange() ?? {};
- const ranges = this._textSelectionManagerService.getSelections();
-
- if (segmentId == null) {
- this._logService.error('[DocClipboardController] segmentId is not existed');
- }
-
- if (activeEndOffset == null || ranges == null) {
- return;
- }
-
- try {
- const body = await clipboard.queryClipboardData();
-
- // When doc has multiple selections, the cursor moves to the last pasted content's end.
- let cursor = activeEndOffset;
- for (const range of ranges) {
- const { startOffset, endOffset } = range;
-
- if (startOffset == null || endOffset == null) {
- continue;
- }
-
- if (endOffset <= activeEndOffset) {
- cursor += body.dataStream.length - (endOffset - startOffset);
- }
- }
- const textRanges = [
- {
- startOffset: cursor,
- endOffset: cursor,
- style,
- },
- ];
-
- this._commandService.executeCommand(InnerPasteCommand.id, { body, segmentId, textRanges });
- } catch (_e) {
- this._logService.error('[DocClipboardController] clipboard is empty');
- }
+ this._init();
}
- private _getDocumentBodyInRanges(): IDocumentBody[] {
- const ranges = this._textSelectionManagerService.getSelections();
- const docDataModel = this._currentUniverService.getCurrentUniverDocInstance();
-
- const results: IDocumentBody[] = [];
-
- if (ranges == null) {
- return results;
- }
-
- for (const range of ranges) {
- const { startOffset, endOffset, collapsed } = range;
-
- if (collapsed) {
- continue;
- }
+ private _init() {
+ [DocCopyCommand, DocCutCommand, DocPasteCommand].forEach((command) => this.disposeWithMe(this._commandService.registerMultipleCommand(command)));
+ [InnerPasteCommand, CutContentCommand].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));
- if (startOffset == null || endOffset == null) {
- continue;
- }
-
- const docBody = docDataModel.sliceBody(startOffset, endOffset);
-
- if (docBody == null) {
- continue;
- }
-
- results.push(docBody);
- }
-
- return results;
+ this._initLegacyPasteCommand();
}
- private async _handleCopy() {
- const { _docClipboardService: clipboard } = this;
- const documentBodyList = this._getDocumentBodyInRanges();
-
- try {
- clipboard.setClipboardData(documentBodyList);
- } catch (_e) {
- this._logService.error('[DocClipboardController] set clipboard failed');
- }
- }
-
- private async _handleCut() {
- const {
- segmentId,
- endOffset: activeEndOffset,
- style,
- } = this._textSelectionManagerService.getActiveRange() ?? {};
- const ranges = this._textSelectionManagerService.getSelections();
-
- if (segmentId == null) {
- this._logService.error('[DocClipboardController] segmentId is not existed');
- }
-
- if (activeEndOffset == null || ranges == null) {
- return;
- }
-
- // Set content to clipboard.
- this._handleCopy();
-
- try {
- let cursor = activeEndOffset;
- for (const range of ranges) {
- const { startOffset, endOffset } = range;
-
- if (startOffset == null || endOffset == null) {
- continue;
- }
-
- if (endOffset <= activeEndOffset) {
- cursor -= endOffset - startOffset;
+ private _initLegacyPasteCommand(): void {
+ if (!this._clipboardInterfaceService.supportClipboard) {
+ this._textSelectionRenderManager?.onPaste$.pipe(takeUntil(this.dispose$)).subscribe((config) => {
+ if (!whenDocOrEditor(this._contextService)) {
+ return;
}
- }
-
- const textRanges = [
- {
- startOffset: cursor,
- endOffset: cursor,
- style,
- },
- ];
- this._commandService.executeCommand(CutContentCommand.id, { segmentId, textRanges });
- } catch (e) {
- this._logService.error('[DocClipboardController] cut content failed');
+ config!.event.preventDefault();
+ const clipboardEvent = config!.event as ClipboardEvent;
+ const htmlContent = clipboardEvent.clipboardData?.getData('text/html');
+ const textContent = clipboardEvent.clipboardData?.getData('text/plain');
+ this._docClipboardService.legacyPaste(htmlContent, textContent);
+ });
}
}
}
diff --git a/packages/docs/src/services/clipboard/clipboard.service.ts b/packages/docs/src/services/clipboard/clipboard.service.ts
index 1973b177ae..d4e8e1f3c7 100644
--- a/packages/docs/src/services/clipboard/clipboard.service.ts
+++ b/packages/docs/src/services/clipboard/clipboard.service.ts
@@ -15,11 +15,13 @@
*/
import type { IDocumentBody, IParagraph } from '@univerjs/core';
-import { Disposable, IUniverInstanceService, toDisposable } from '@univerjs/core';
+import { Disposable, ICommandService, ILogService, IUniverInstanceService, toDisposable } from '@univerjs/core';
import { HTML_CLIPBOARD_MIME_TYPE, IClipboardInterfaceService, PLAIN_TEXT_CLIPBOARD_MIME_TYPE } from '@univerjs/ui';
import type { IDisposable } from '@wendellhu/redi';
-import { createIdentifier } from '@wendellhu/redi';
+import { createIdentifier, Inject } from '@wendellhu/redi';
+import { TextSelectionManagerService } from '../text-selection-manager.service';
+import { CutContentCommand, InnerPasteCommand } from '../../commands/commands/clipboard.inner.command';
import { copyContentCache, extractId, genId } from './copy-content-cache';
import { HtmlToUDMService } from './html-to-udm/converter';
import PastePluginLark from './html-to-udm/paste-plugins/plugin-lark';
@@ -54,9 +56,10 @@ export interface IDocClipboardHook {
}
export interface IDocClipboardService {
- queryClipboardData(): Promise<IDocumentBody>;
-
- setClipboardData(documentBodyList: IDocumentBody[]): Promise<void>;
+ copy(): Promise<boolean>;
+ cut(): Promise<boolean>;
+ paste(items: ClipboardItem[]): Promise<boolean>;
+ legacyPaste(html?: string, text?: string): Promise<boolean>;
addClipboardHook(hook: IDocClipboardHook): IDisposable;
}
@@ -65,58 +68,137 @@ export const IDocClipboardService = createIdentifier<IDocClipboardService>('doc.
export class DocClipboardService extends Disposable implements IDocClipboardService {
private _clipboardHooks: IDocClipboardHook[] = [];
+
private _htmlToUDM = new HtmlToUDMService();
private _umdToHtml = new UDMToHtmlService();
constructor(
@IUniverInstanceService private readonly _currentUniverService: IUniverInstanceService,
- @IClipboardInterfaceService private readonly _clipboardInterfaceService: IClipboardInterfaceService
+ @ILogService private readonly _logService: ILogService,
+ @ICommandService private readonly _commandService: ICommandService,
+ @IClipboardInterfaceService private readonly _clipboardInterfaceService: IClipboardInterfaceService,
+ @Inject(TextSelectionManagerService) private readonly _textSelectionManagerService: TextSelectionManagerService
) {
super();
}
- async queryClipboardData(): Promise<IDocumentBody> {
- const clipboardItems = await this._clipboardInterfaceService.read();
- if (clipboardItems.length === 0) {
- return Promise.reject();
+ async copy(): Promise<boolean> {
+ const documentBodyList = this._getDocumentBodyInRanges();
+ try {
+ this._setClipboardData(documentBodyList);
+ } catch (e) {
+ this._logService.error('[DocClipboardService] copy failed', e);
+ return false;
}
+ return true;
+ }
+
+ async cut(): Promise<boolean> {
+ return this._cut();
+ }
+
+ async paste(items: ClipboardItem[]): Promise<boolean> {
+ const body = await this._generateBodyFromClipboardItems(items);
+ return this._paste(body);
+ }
+
+ async legacyPaste(html?: string, text?: string): Promise<boolean> {
+ const body = this._generateBodyFromHtmlAndText(html, text);
+ return this._paste(body);
+ }
+
+ private async _cut(): Promise<boolean> {
+ const {
+ segmentId,
+ endOffset: activeEndOffset,
+ style,
+ } = this._textSelectionManagerService.getActiveRange() ?? {};
+ const ranges = this._textSelectionManagerService.getSelections();
+
+ if (segmentId == null) {
+ this._logService.error('[DocClipboardController] segmentId is not existed');
+ }
+
+ if (activeEndOffset == null || ranges == null) {
+ return false;
+ }
+
+ // Set content to clipboard.
+ this.copy();
+
try {
- // TODO: support paste image.
- let html = '';
- let text = '';
+ let cursor = activeEndOffset;
+ for (const range of ranges) {
+ const { startOffset, endOffset } = range;
- for (const clipboardItem of clipboardItems) {
- for (const type of clipboardItem.types) {
- if (type === PLAIN_TEXT_CLIPBOARD_MIME_TYPE) {
- text = await clipboardItem.getType(type).then((blob) => blob && blob.text());
- } else if (type === HTML_CLIPBOARD_MIME_TYPE) {
- html = await clipboardItem.getType(type).then((blob) => blob && blob.text());
- }
+ if (startOffset == null || endOffset == null) {
+ continue;
}
- }
- if (!html) {
- return generateBody(text);
+ if (endOffset <= activeEndOffset) {
+ cursor -= endOffset - startOffset;
+ }
}
- const copyId = extractId(html);
+ const textRanges = [
+ {
+ startOffset: cursor,
+ endOffset: cursor,
+ style,
+ },
+ ];
+
+ return this._commandService.executeCommand(CutContentCommand.id, { segmentId, textRanges });
+ } catch (e) {
+ this._logService.error('[DocClipboardController] cut content failed');
+ return false;
+ }
+ }
+
+ private async _paste(body: IDocumentBody): Promise<boolean> {
+ const { segmentId, endOffset: activeEndOffset, style } = this._textSelectionManagerService.getActiveRange() ?? {};
+ const ranges = this._textSelectionManagerService.getSelections();
+
+ if (segmentId == null) {
+ this._logService.error('[DocClipboardController] segmentId does not exist!');
+ }
+
+ if (activeEndOffset == null || ranges == null) {
+ return false;
+ }
- if (copyId) {
- const copyCache = copyContentCache.get(copyId);
+ try {
+ // When doc has multiple selections, the cursor moves to the last pasted content's end.
+ let cursor = activeEndOffset;
+ for (const range of ranges) {
+ const { startOffset, endOffset } = range;
- if (copyCache) {
- return copyCache;
+ if (startOffset == null || endOffset == null) {
+ continue;
+ }
+
+ if (endOffset <= activeEndOffset) {
+ cursor += body.dataStream.length - (endOffset - startOffset);
}
}
- return this._htmlToUDM.convert(html);
- } catch (e) {
- return Promise.reject(e);
+ const textRanges = [
+ {
+ startOffset: cursor,
+ endOffset: cursor,
+ style,
+ },
+ ];
+
+ return this._commandService.executeCommand(InnerPasteCommand.id, { body, segmentId, textRanges });
+ } catch (_e) {
+ this._logService.error('[DocClipboardController]', 'clipboard is empty.');
+ return false;
}
}
- async setClipboardData(documentBodyList: IDocumentBody[]): Promise<void> {
+ private async _setClipboardData(documentBodyList: IDocumentBody[]): Promise<void> {
const copyId = genId();
const text =
documentBodyList.length > 1
@@ -144,4 +226,79 @@ export class DocClipboardService extends Disposable implements IDocClipboardServ
}
});
}
+
+ private _getDocumentBodyInRanges(): IDocumentBody[] {
+ const ranges = this._textSelectionManagerService.getSelections();
+ const docDataModel = this._currentUniverService.getCurrentUniverDocInstance();
+
+ const results: IDocumentBody[] = [];
+
+ if (ranges == null) {
+ return results;
+ }
+
+ for (const range of ranges) {
+ const { startOffset, endOffset, collapsed } = range;
+
+ if (collapsed) {
+ continue;
+ }
+
+ if (startOffset == null || endOffset == null) {
+ continue;
+ }
+
+ const docBody = docDataModel.sliceBody(startOffset, endOffset);
+ if (docBody == null) {
+ continue;
+ }
+
+ results.push(docBody);
+ }
+
+ return results;
+ }
+
+ private async _generateBodyFromClipboardItems(items: ClipboardItem[]): Promise<IDocumentBody> {
+ try {
+ // TODO: support paste image.
+
+ let html = '';
+ let text = '';
+
+ for (const clipboardItem of items) {
+ for (const type of clipboardItem.types) {
+ if (type === PLAIN_TEXT_CLIPBOARD_MIME_TYPE) {
+ text = await clipboardItem.getType(type).then((blob) => blob && blob.text());
+ } else if (type === HTML_CLIPBOARD_MIME_TYPE) {
+ html = await clipboardItem.getType(type).then((blob) => blob && blob.text());
+ }
+ }
+ }
+
+ return this._generateBodyFromHtmlAndText(html, text);
+ } catch (e) {
+ return Promise.reject(e);
+ }
+ }
+
+ private _generateBodyFromHtmlAndText(html?: string, text?: string): IDocumentBody {
+ if (!html) {
+ if (text) {
+ return generateBody(text);
+ } else {
+ throw new Error('[DocClipboardService] html and text cannot be both empty!');
+ }
+ }
+
+ const copyId = extractId(html);
+ if (copyId) {
+ const copyCache = copyContentCache.get(copyId);
+ if (copyCache) {
+ return copyCache;
+ }
+ }
+
+ return this._htmlToUDM.convert(html);
+ }
}
diff --git a/packages/sheets-ui/src/commands/commands/clipboard.command.ts b/packages/sheets-ui/src/commands/commands/clipboard.command.ts
index 6bd2332c54..36b781e3d9 100644
--- a/packages/sheets-ui/src/commands/commands/clipboard.command.ts
+++ b/packages/sheets-ui/src/commands/commands/clipboard.command.ts
@@ -14,21 +14,27 @@
* limitations under the License.
*/
-import type { ICommand, IMultiCommand } from '@univerjs/core';
-import { CommandType, ICommandService, ILogService } from '@univerjs/core';
+import type { ICommand, IContextService, IMultiCommand } from '@univerjs/core';
+import { CommandType, EDITOR_ACTIVATED, ICommandService, ILogService } from '@univerjs/core';
import { CopyCommand, CutCommand, IClipboardInterfaceService, PasteCommand } from '@univerjs/ui';
import type { IAccessor } from '@wendellhu/redi';
-import { whenSheetEditorFocused, whenSheetFocused } from '../../controllers/shortcuts/utils';
+import { whenSheetEditorActivated, whenSheetEditorFocused } from '../../controllers/shortcuts/utils';
import { ISheetClipboardService, PREDEFINED_HOOK_NAME } from '../../services/clipboard/clipboard.service';
+function whenSheetEditorNotActivated(context: IContextService): boolean {
+ return whenSheetEditorFocused(context) && !context.getContextValue(EDITOR_ACTIVATED);
+}
+
+const SHEET_CLIPBOARD_PRIORITY = 998;
+
export const SheetCopyCommand: IMultiCommand = {
id: CopyCommand.id,
name: 'sheet.command.copy',
type: CommandType.COMMAND,
multi: true,
- priority: 1000,
- preconditions: whenSheetFocused,
+ priority: SHEET_CLIPBOARD_PRIORITY,
+ preconditions: whenSheetEditorNotActivated,
handler: async (accessor) => {
const sheetClipboardService = accessor.get(ISheetClipboardService);
return sheetClipboardService.copy();
@@ -40,8 +46,8 @@ export const SheetCutCommand: IMultiCommand = {
name: 'sheet.command.cut',
type: CommandType.COMMAND,
multi: true,
- priority: 1000,
- preconditions: whenSheetEditorFocused,
+ priority: SHEET_CLIPBOARD_PRIORITY,
+ preconditions: whenSheetEditorActivated,
handler: async (accessor) => {
const sheetClipboardService = accessor.get(ISheetClipboardService);
return sheetClipboardService.cut();
@@ -57,8 +63,8 @@ export const SheetPasteCommand: IMultiCommand = {
type: CommandType.COMMAND,
multi: true,
name: 'sheet.command.paste',
- priority: 998,
- preconditions: whenSheetEditorFocused,
+ priority: SHEET_CLIPBOARD_PRIORITY,
+ preconditions: whenSheetEditorNotActivated,
handler: async (accessor: IAccessor, params: ISheetPasteParams) => {
const logService = accessor.get(ILogService);
@@ -68,7 +74,6 @@ export const SheetPasteCommand: IMultiCommand = {
logService.debug('[SheetPasteCommand]', 'the focusing element is', document.activeElement);
const result = document.execCommand('paste');
-
if (!result) {
logService.debug(
'[SheetPasteCommand]',
@@ -79,7 +84,8 @@ export const SheetPasteCommand: IMultiCommand = {
const clipboardItems = await clipboardInterfaceService.read();
const sheetClipboardService = accessor.get(ISheetClipboardService);
- // logService.log('[SheetPasteCommand]: clipboard data is', clipboardItems);
+ // logService.debug('[SheetPasteCommand]: clipboard data is', clipboardItems);
+
if (clipboardItems.length !== 0) {
return sheetClipboardService.paste(clipboardItems[0], params?.value);
}
diff --git a/packages/sheets-ui/src/controllers/clipboard/clipboard.controller.ts b/packages/sheets-ui/src/controllers/clipboard/clipboard.controller.ts
index eb992a67bc..d1375e009b 100644
--- a/packages/sheets-ui/src/controllers/clipboard/clipboard.controller.ts
+++ b/packages/sheets-ui/src/controllers/clipboard/clipboard.controller.ts
@@ -115,7 +115,7 @@ export class SheetClipboardController extends RxDisposable {
if (!this._clipboardInterfaceService.supportClipboard) {
this._textSelectionRenderManager?.onPaste$.pipe(takeUntil(this.dispose$)).subscribe((config) => {
- if (whenSheetEditorFocused(this._contextService) === false) {
+ if (!whenSheetEditorFocused(this._contextService)) {
return;
}
diff --git a/packages/sheets-ui/src/services/clipboard/clipboard.service.ts b/packages/sheets-ui/src/services/clipboard/clipboard.service.ts
index aec5b4db19..d724ef2651 100644
--- a/packages/sheets-ui/src/services/clipboard/clipboard.service.ts
+++ b/packages/sheets-ui/src/services/clipboard/clipboard.service.ts
@@ -83,13 +83,14 @@ export const ISheetClipboardService = createIdentifier<ISheetClipboardService>('
export class SheetClipboardService extends Disposable implements ISheetClipboardService {
private _clipboardHooks: ISheetClipboardHook[] = [];
+
private readonly _clipboardHooks$ = new BehaviorSubject<ISheetClipboardHook[]>([]);
readonly clipboardHooks$ = this._clipboardHooks$.asObservable();
- private _htmlToUSM;
- private _usmToHtml;
+ private _htmlToUSM: HtmlToUSMService;
+ private _usmToHtml: USMToHtmlService;
+
private _copyMarkId: string | null = null;
- private _pasteType = PREDEFINED_HOOK_NAME.DEFAULT_PASTE;
constructor(
@ILogService private readonly _logService: ILogService,
@@ -601,8 +602,6 @@ export class SheetClipboardService extends Disposable implements ISheetClipboard
};
}
- // NOTE: why there are some differences between internal and external pasting?
-
private _getPastingTarget() {
const workbook = this._currentUniverService.getCurrentUniverSheetInstance();
const worksheet = workbook.getActiveSheet();
@@ -789,22 +788,8 @@ export class SheetClipboardService extends Disposable implements ISheetClipboard
}
}
-// #region paste parsing
-
-// #endregion
-
// #region copy generation
-/**
- *
- * @param matrix
- * @param cols
- * @param hooks
- */
-function getTableContent(matrix: number[][], cols: number[], hooks: ISheetClipboardHook[]) {}
-
-function getSingleCellContent() {}
-
function getMatrixPlainText(matrix: ObjectMatrix<ICellDataWithSpanInfo>) {
let plain = '';
matrix.forRow((row, cols) => {
@@ -881,10 +866,6 @@ function isMultipleCells(cellMatrix: ObjectMatrix<ICellDataWithSpanInfo>): boole
// #endregion
-function isLegalSpreadsheetHTMLContent(html: string): boolean {
- return html.indexOf('<table') !== -1; // NOTE: This is just a temporary implementation. Definitely would be changed later.
-}
-
function getEmptyCell(): ICellData {
return {
p: null,