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: bugs in format painter & copypaste (#664)
YuHongc9b8e2402e97
diff --git a/packages/sheets-ui/src/commands/commands/__tests__/auto-fill.controller.spec.ts b/packages/sheets-ui/src/commands/commands/__tests__/auto-fill.controller.spec.tsindex 920250f507..55768f4623 100644--- a/packages/sheets-ui/src/commands/commands/__tests__/auto-fill.controller.spec.ts+++ b/packages/sheets-ui/src/commands/commands/__tests__/auto-fill.controller.spec.ts@@ -17,6 +17,7 @@ import {SetSelectionsOperation,} from '@univerjs/sheets';import { createCommandTestBed } from '@univerjs/sheets/commands/commands/__tests__/create-command-test-bed.js';+import { DesktopPlatformService, DesktopShortcutService, IPlatformService, IShortcutService } from '@univerjs/ui';import type { Injector } from '@wendellhu/redi';import { beforeEach, describe, expect, it } from 'vitest';@@ -222,6 +223,8 @@ describe('Test auto fill rules in controller', () => {const testBed = createCommandTestBed(TEST_WORKBOOK_DATA, [[ISelectionRenderService, { useClass: SelectionRenderService }],[IAutoFillService, { useClass: AutoFillService }],+ [IShortcutService, { useClass: DesktopShortcutService }],+ [IPlatformService, { useClass: DesktopPlatformService }],[AutoFillController],]);univer = testBed.univer;diff --git a/packages/sheets-ui/src/commands/commands/set-format-painter.command.ts b/packages/sheets-ui/src/commands/commands/set-format-painter.command.tsindex 0a2b9554f8..bbdd1d703d 100644--- a/packages/sheets-ui/src/commands/commands/set-format-painter.command.ts+++ b/packages/sheets-ui/src/commands/commands/set-format-painter.command.ts@@ -1,10 +1,8 @@import type { ICommand } from '@univerjs/core';-import { CommandType, ICommandService, IUniverInstanceService } from '@univerjs/core';-import { NORMAL_SELECTION_PLUGIN_NAME, SelectionManagerService } from '@univerjs/sheets';+import { CommandType, ICommandService } from '@univerjs/core';import type { IAccessor } from '@wendellhu/redi';import { FormatPainterStatus, IFormatPainterService } from '../../services/format-painter/format-painter.service';-import { FORMAT_PAINTER_SELECTION_PLUGIN_NAME, SetCopySelectionsOperation } from '../operations/selection.operation';import { SetFormatPainterOperation } from '../operations/set-format-painter.operation';export interface ISetFormatPainterCommandParams {@@ -24,9 +22,6 @@ export const SetInfiniteFormatPainterCommand: ICommand = {newStatus = FormatPainterStatus.INFINITE;}const commandService = accessor.get(ICommandService);- await commandService.executeCommand(SetCopySelectionCommand.id, {- show: newStatus === FormatPainterStatus.INFINITE,- });return commandService.executeCommand(SetFormatPainterOperation.id, { status: newStatus });},@@ -45,52 +40,6 @@ export const SetOnceFormatPainterCommand: ICommand = {newStatus = FormatPainterStatus.ONCE;}const commandService = accessor.get(ICommandService);- await commandService.executeCommand(SetCopySelectionCommand.id, {- show: newStatus === FormatPainterStatus.ONCE,- });return commandService.executeCommand(SetFormatPainterOperation.id, { status: newStatus });},};--export interface ISetCopySelectionCommandParams {- show?: boolean;-}--export const SetCopySelectionCommand: ICommand = {- type: CommandType.COMMAND,- id: 'sheet.command.set-copy-selection',- handler: async (accessor: IAccessor, params: ISetCopySelectionCommandParams) => {- const commandService = accessor.get(ICommandService);- const currentService = accessor.get(IUniverInstanceService);- const workbookId = currentService.getCurrentUniverSheetInstance().getUnitId();- const worksheetId = currentService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();- let setSelectionsParam;- const selectionManagerService = accessor.get(SelectionManagerService);- const selections = selectionManagerService.getSelections();- if (!selections || selections.length === 0) {- return false;- }-- if (params.show) {- const { range, primary, style } = selections[0];- setSelectionsParam = {- workbookId,- worksheetId,- pluginName: FORMAT_PAINTER_SELECTION_PLUGIN_NAME,- selections: [{ range, primary, style: null }],- show: true,- };- } else {- const { range, primary, style } = selections[selections.length - 1];- setSelectionsParam = {- workbookId,- worksheetId,- pluginName: NORMAL_SELECTION_PLUGIN_NAME,- selections: [{ range, primary, style }],- show: false,- };- }-- return commandService.executeCommand(SetCopySelectionsOperation.id, setSelectionsParam);- },-};diff --git a/packages/sheets-ui/src/commands/operations/selection.operation.ts b/packages/sheets-ui/src/commands/operations/selection.operation.tsdeleted file mode 100644index 8d2da066d2..0000000000--- a/packages/sheets-ui/src/commands/operations/selection.operation.ts+++ /dev/null@@ -1,53 +0,0 @@-// This file provide operations to change selection of sheets.--import type { IOperation } from '@univerjs/core';-import { CommandType } from '@univerjs/core';-import type { ISelectionWithStyle } from '@univerjs/sheets';-import { SelectionManagerService } from '@univerjs/sheets';--import { ISelectionRenderService } from '../../services/selection/selection-render.service';--export interface ISetCopySelectionsOperationParams {- workbookId: string;- worksheetId: string;- pluginName: string;- selections: ISelectionWithStyle[];- show: boolean;-}--export const FORMAT_PAINTER_SELECTION_PLUGIN_NAME = 'formatPainterSelectionPluginName';--export const SetCopySelectionsOperation: IOperation<ISetCopySelectionsOperationParams> = {- id: 'sheet.operation.set-copy-selection',- type: CommandType.OPERATION,- handler: (accessor, params) => {- const selectionManagerService = accessor.get(SelectionManagerService);- const selectionRenderService = accessor.get(ISelectionRenderService);- if (!params) {- return false;- }- if (!params.show) {- selectionRenderService.disableShowPrevious();- selectionManagerService.makeDirty(true);- selectionManagerService.reset();- selectionManagerService.add(params.selections);- return true;- }- selectionRenderService.enableShowPrevious();- selectionManagerService.makeDirty(false);- selectionManagerService.setCurrentSelectionNotRefresh({- pluginName: params.pluginName,- unitId: params.workbookId,- sheetId: params.worksheetId,- });- const selection = params.selections[0];- const { range, primary } = selection;- const newSelection = {- range,- primary,- style: selectionManagerService.createCopyPasteSelection(),- };- selectionManagerService.add([newSelection]);- return true;- },-};diff --git a/packages/sheets-ui/src/controllers/format-painter/format-painter.controller.ts b/packages/sheets-ui/src/controllers/format-painter/format-painter.controller.tsindex 4b3cd222dd..07e9ca9e46 100644--- a/packages/sheets-ui/src/controllers/format-painter/format-painter.controller.ts+++ b/packages/sheets-ui/src/controllers/format-painter/format-painter.controller.ts@@ -6,7 +6,6 @@ import { SelectionManagerService, SetRangeValuesCommand, SetSelectionsOperationimport { Inject } from '@wendellhu/redi';import { SetOnceFormatPainterCommand } from '../../commands/commands/set-format-painter.command';-import { FORMAT_PAINTER_SELECTION_PLUGIN_NAME } from '../../commands/operations/selection.operation';import { FormatPainterStatus, IFormatPainterService } from '../../services/format-painter/format-painter.service';@OnLifecycle(LifecycleStages.Rendered, FormatPainterController)@@ -45,14 +44,15 @@ export class FormatPainterController extends Disposable {this._commandService.onCommandExecuted((command: ICommandInfo) => {if (command.id === SetSelectionsOperation.id &&- (command.params as ISetSelectionsOperationParams)?.pluginName ===- FORMAT_PAINTER_SELECTION_PLUGIN_NAME+ this._formatPainterService.getStatus() !== FormatPainterStatus.OFF) {- const isFormatPainterOn = this._formatPainterService.getStatus() !== FormatPainterStatus.OFF;- if (!isFormatPainterOn) return;const { selections } = command.params as ISetSelectionsOperationParams;const { range } = selections[selections.length - 1];this._applyFormatPainter(range);+ // if once, turn off the format painter+ if (this._formatPainterService.getStatus() === FormatPainterStatus.ONCE) {+ this._commandService.executeCommand(SetOnceFormatPainterCommand.id);+ }}}));@@ -64,16 +64,17 @@ export class FormatPainterController extends Disposable {const worksheetId = this._currentService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();if (!stylesMatrix) return;- const styleRowsNum = stylesMatrix.getLength();- const styleColsNum = stylesMatrix.getSizeOf();+ const { startRow, startColumn, endRow, endColumn } = stylesMatrix.getDataRange();+ const styleRowsNum = endRow - startRow + 1;+ const styleColsNum = endColumn - startColumn + 1;const styleValues: ICellData[][] = Array.from({ length: range.endRow - range.startRow + 1 }, () =>Array.from({ length: range.endColumn - range.startColumn + 1 }, () => ({})));styleValues.forEach((row, rowIndex) => {row.forEach((col, colIndex) => {- const mappedRowIndex = rowIndex % styleRowsNum;- const mappedColIndex = colIndex % styleColsNum;+ const mappedRowIndex = (rowIndex % styleRowsNum) + startRow;+ const mappedColIndex = (colIndex % styleColsNum) + startColumn;const style = stylesMatrix.getValue(mappedRowIndex, mappedColIndex);if (style) {@@ -90,10 +91,5 @@ export class FormatPainterController extends Disposable {};this._commandService.executeCommand(SetRangeValuesCommand.id, setRangeValuesCommandParams);-- // if the format painter is once, turn it off- if (this._formatPainterService.getStatus() === FormatPainterStatus.ONCE) {- this._commandService.executeCommand(SetOnceFormatPainterCommand.id);- }}}diff --git a/packages/sheets-ui/src/controllers/sheet-ui.controller.ts b/packages/sheets-ui/src/controllers/sheet-ui.controller.tsindex edf63d846d..05750eb933 100644--- a/packages/sheets-ui/src/controllers/sheet-ui.controller.ts+++ b/packages/sheets-ui/src/controllers/sheet-ui.controller.ts@@ -31,7 +31,6 @@ import {import { RefillCommand } from '../commands/commands/refill.command';import { RenameSheetOperation } from '../commands/commands/rename.command';import {- SetCopySelectionCommand,SetInfiniteFormatPainterCommand,SetOnceFormatPainterCommand,} from '../commands/commands/set-format-painter.command';@@ -56,7 +55,6 @@ import {SetCellEditVisibleOperation,} from '../commands/operations/cell-edit.operation';import { SetScrollOperation } from '../commands/operations/scroll.operation';-import { SetCopySelectionsOperation } from '../commands/operations/selection.operation';import { SetEditorResizeOperation } from '../commands/operations/set-editor-resize.operation';import { SetFormatPainterOperation } from '../commands/operations/set-format-painter.operation';import { SetZoomRatioOperation } from '../commands/operations/set-zoom-ratio.operation';@@ -235,8 +233,6 @@ export class SheetUIController extends Disposable {SetBoldCommand,SetCellEditVisibleArrowOperation,SetCellEditVisibleOperation,- SetCopySelectionCommand,- SetCopySelectionsOperation,SetRangeBoldCommand,SetRangeItalicCommand,SetRangeUnderlineCommand,diff --git a/packages/sheets-ui/src/services/clipboard/clipboard.service.ts b/packages/sheets-ui/src/services/clipboard/clipboard.service.tsindex 13887c4960..16480affb9 100644--- a/packages/sheets-ui/src/services/clipboard/clipboard.service.ts+++ b/packages/sheets-ui/src/services/clipboard/clipboard.service.ts@@ -24,6 +24,7 @@ import { createIdentifier, Inject } from '@wendellhu/redi';import { BehaviorSubject } from 'rxjs';import { IMarkSelectionService } from '../mark-selection/mark-selection.service';+import { SheetSkeletonManagerService } from '../sheet-skeleton-manager.service';import { copyContentCache, extractId, genId } from './copy-content-cache';import { HtmlToUSMService } from './html-to-usm/converter';import PastePluginLark from './html-to-usm/paste-plugins/plugin-lark';@@ -69,8 +70,8 @@ export class SheetClipboardService extends Disposable implements ISheetClipboardprivate readonly _clipboardHooks$ = new BehaviorSubject<ISheetClipboardHook[]>([]);readonly clipboardHooks$ = this._clipboardHooks$.asObservable();- private _htmlToUSM = new HtmlToUSMService();- private _usmToHtml = new USMToHtmlService();+ private _htmlToUSM;+ private _usmToHtml;private _copyMarkId: string | null = null;private _pasteType = PREDEFINED_HOOK_NAME.DEFAULT_PASTE;@@ -81,9 +82,14 @@ export class SheetClipboardService extends Disposable implements ISheetClipboard@IClipboardInterfaceService private readonly _clipboardInterfaceService: IClipboardInterfaceService,@IUndoRedoService private readonly _undoRedoService: IUndoRedoService,@ICommandService private readonly _commandService: ICommandService,- @IMarkSelectionService private readonly _markSelectionService: IMarkSelectionService+ @IMarkSelectionService private readonly _markSelectionService: IMarkSelectionService,+ @Inject(SheetSkeletonManagerService) private readonly _sheetSkeletonManagerService: SheetSkeletonManagerService) {super();+ this._htmlToUSM = new HtmlToUSMService({+ getCurrentSkeleton: () => this._sheetSkeletonManagerService.getCurrent(),+ });+ this._usmToHtml = new USMToHtmlService();}async copy(copyType = COPY_TYPE.COPY): Promise<boolean> {@@ -111,11 +117,12 @@ export class SheetClipboardService extends Disposable implements ISheetClipboardfor (let c = startColumn; c <= endColumn; c++) {const 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,+ ...getEmptyCell(),+ ...Tools.deepClone(cellData),});+ } else {+ matrixFragment.setValue(r - startRow, c - startColumn, getEmptyCell());}}}@@ -367,11 +374,10 @@ export class SheetClipboardService extends Disposable implements ISheetClipboardif (cachedData.copyType === COPY_TYPE.CUT) {copyContentCache.del(copyId);+ this._copyMarkId && this._markSelectionService.removeShape(this._copyMarkId);+ this._copyMarkId = null;}- this._copyMarkId && this._markSelectionService.removeShape(this._copyMarkId);- this._copyMarkId = null;-return pasteRes;}@@ -802,3 +808,14 @@ function isMultipleCells(cellMatrix: ObjectMatrix<ICellDataWithSpanInfo>): boolefunction 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,+ v: null,+ s: null,+ f: null,+ si: null,+ t: null,+ };+}diff --git a/packages/sheets-ui/src/services/clipboard/html-to-usm/converter.ts b/packages/sheets-ui/src/services/clipboard/html-to-usm/converter.tsindex c895829fda..568175c67c 100644--- a/packages/sheets-ui/src/services/clipboard/html-to-usm/converter.ts+++ b/packages/sheets-ui/src/services/clipboard/html-to-usm/converter.ts@@ -1,8 +1,8 @@-import type { IDocumentBody, ITextRun, ITextStyle, Nullable } from '@univerjs/core';+import type { IDocumentBody, IDocumentData, ITextRun, ITextStyle, Nullable } from '@univerjs/core';import { ObjectMatrix } from '@univerjs/core';import { handleStringToStyle } from '@univerjs/ui';-import { genId } from '../copy-content-cache';+import type { ISheetSkeletonManagerParam } from '../../sheet-skeleton-manager.service';import type {ICellDataWithSpanInfo,IClipboardPropertyItem,@@ -43,6 +43,10 @@ function matchFilter(node: HTMLElement, filter: IStyleRule['filter']) {return filter(node);}+interface IHtmlToUSMServiceProps {+ getCurrentSkeleton: () => Nullable<ISheetSkeletonManagerParam>;+}+export class HtmlToUSMService {private static pluginList: IPasteExtension[] = [];@@ -60,6 +64,12 @@ export class HtmlToUSMService {private afterProcessRules: IAfterProcessRule[] = [];+ private getCurrentSkeleton: () => Nullable<ISheetSkeletonManagerParam>;++ constructor(props: IHtmlToUSMServiceProps) {+ this.getCurrentSkeleton = props.getCurrentSkeleton;+ }+convert(html: string): IUniverSheetCopyDataModel {const pastePlugin = HtmlToUSMService.pluginList.find((plugin) => plugin.checkPasteType(html));if (pastePlugin) {@@ -104,16 +114,15 @@ export class HtmlToUSMService {}});// set rich format+ const p = this._generateDocumentDataModelSnapshot({+ body: {+ dataStream: cellDataStream,+ textRuns: cellTextRuns,+ },+ });valueMatrix.setValue(valueMatrix.getLength(), 0, {v: cellDataStream,- p: {- id: genId(),- body: {- dataStream: cellDataStream,- textRuns: cellTextRuns,- },- documentStyle: { textStyle: cellTextRuns[0]?.ts },- },+ p,});rowProperties.push({}); // TODO@yuhongz@@ -142,9 +151,12 @@ export class HtmlToUSMService {}} else {if (dataStream) {+ const p = this._generateDocumentDataModelSnapshot({+ body: newDocBody,+ });valueMatrix.setValue(0, 0, {v: dataStream,- p: { id: genId(), body: newDocBody, documentStyle: {} },+ p,});rowProperties.push({}); // TODO@yuhongz}@@ -192,6 +204,19 @@ export class HtmlToUSMService {};}+ private _generateDocumentDataModelSnapshot(snapshot: Partial<IDocumentData>) {+ const currentSkeleton = this.getCurrentSkeleton();+ if (currentSkeleton == null) {+ return null;+ }+ const { skeleton } = currentSkeleton;+ const documentModel = skeleton.getBlankCellDocumentModel()?.documentModel;+ const p = documentModel?.getSnapshot();+ const documentData = { ...p, ...snapshot };+ documentModel?.reset(documentData);+ return documentModel?.getSnapshot();+ }+private process(parent: Nullable<ChildNode>,nodes: NodeListOf<ChildNode>,diff --git a/packages/sheets-ui/src/services/format-painter/format-painter.service.ts b/packages/sheets-ui/src/services/format-painter/format-painter.service.tsindex c49cf16f84..3ec284373a 100644--- a/packages/sheets-ui/src/services/format-painter/format-painter.service.ts+++ b/packages/sheets-ui/src/services/format-painter/format-painter.service.ts@@ -5,6 +5,8 @@ import { createIdentifier, Inject } from '@wendellhu/redi';import type { Observable } from 'rxjs';import { BehaviorSubject } from 'rxjs';+import { IMarkSelectionService } from '../mark-selection/mark-selection.service';+export interface IFormatPainterService {status$: Observable<FormatPainterStatus>;setStatus(status: FormatPainterStatus): void;@@ -23,12 +25,13 @@ export const IFormatPainterService = createIdentifier<IFormatPainterService>('unexport class FormatPainterService extends Disposable implements IFormatPainterService {readonly status$: Observable<FormatPainterStatus>;private _selectionStyles: ObjectMatrix<IStyleData>;-+ private _markId: string | null = null;private readonly _status$: BehaviorSubject<FormatPainterStatus>;constructor(@Inject(SelectionManagerService) private readonly _selectionManagerService: SelectionManagerService,- @IUniverInstanceService private readonly _currentService: IUniverInstanceService+ @IUniverInstanceService private readonly _currentService: IUniverInstanceService,+ @IMarkSelectionService private readonly _markSelectionService: IMarkSelectionService) {super();@@ -41,6 +44,7 @@ export class FormatPainterService extends Disposable implements IFormatPainterSeif (status !== FormatPainterStatus.OFF) {this._getSelectionRangeStyle();}+ this._updateRangeMark(status);this._status$.next(status);}@@ -48,6 +52,20 @@ export class FormatPainterService extends Disposable implements IFormatPainterSereturn this._status$.getValue();}+ private _updateRangeMark(status: FormatPainterStatus) {+ if (this._markId) {+ this._markSelectionService.removeShape(this._markId);+ this._markId = null;+ }+ if (status !== FormatPainterStatus.OFF) {+ const selection = this._selectionManagerService.getLast();+ if (selection) {+ const style = this._selectionManagerService.createCopyPasteSelection();+ this._markId = this._markSelectionService.addShape({ ...selection, style });+ }+ }+ }+private _getSelectionRangeStyle() {const selection = this._selectionManagerService.getLast();const range = selection?.range;@@ -56,14 +74,16 @@ export class FormatPainterService extends Disposable implements IFormatPainterSeconst workbook = this._currentService.getCurrentUniverSheetInstance();const worksheet = workbook?.getActiveSheet();const cellData = worksheet.getCellMatrix();- const value = cellData.getFragments(startRow, endRow, startColumn, endColumn);+ // const value = cellData.getFragments(startRow, endRow, startColumn, endColumn);const styles = workbook.getStyles();const stylesMatrix = new ObjectMatrix<IStyleData>();- value.forValue((r, c, cell) => {- cell = cell as ICellData;- stylesMatrix.setValue(r, c, styles.getStyleByCell(cell) || {});- });+ for (let r = startRow; r <= endRow; r++) {+ for (let c = startColumn; c <= endColumn; c++) {+ const cell = cellData.getValue(r, c) as ICellData;+ stylesMatrix.setValue(r, c, styles.getStyleByCell(cell) || {});+ }+ }this._selectionStyles = stylesMatrix;}diff --git a/packages/sheets-ui/src/services/mark-selection/mark-selection.service.ts b/packages/sheets-ui/src/services/mark-selection/mark-selection.service.tsindex 530cac73e9..0bd83fba15 100644--- a/packages/sheets-ui/src/services/mark-selection/mark-selection.service.ts+++ b/packages/sheets-ui/src/services/mark-selection/mark-selection.service.ts@@ -11,7 +11,7 @@ import { SelectionShape } from '../selection/selection-shape';import { SheetSkeletonManagerService } from '../sheet-skeleton-manager.service';export interface IMarkSelectionService {- addShape(selection: ISelectionWithStyle): string | null;+ addShape(selection: ISelectionWithStyle, zIndex?: number): string | null;removeShape(id: string): void;removeAllShapes(): void;}diff --git a/packages/sheets-ui/src/services/selection/selection-render.service.ts b/packages/sheets-ui/src/services/selection/selection-render.service.tsindex fc8e5efe5f..e9bae8160d 100644--- a/packages/sheets-ui/src/services/selection/selection-render.service.ts+++ b/packages/sheets-ui/src/services/selection/selection-render.service.ts@@ -12,6 +12,7 @@ import type { IMouseEvent, IPointerEvent, Scene, SpreadsheetSkeleton, Viewport }import { ScrollTimer, ScrollTimerType, Vector2 } from '@univerjs/engine-render';import type { ISelectionStyle, ISelectionWithCoordAndStyle, ISelectionWithStyle } from '@univerjs/sheets';import { getNormalSelectionStyle } from '@univerjs/sheets';+import { IShortcutService } from '@univerjs/ui';import { createIdentifier, Inject } from '@wendellhu/redi';import type { Observable } from 'rxjs';import { BehaviorSubject, Subject } from 'rxjs';@@ -161,7 +162,10 @@ export class SelectionRenderService implements ISelectionRenderService {private _activeViewport!: Viewport;- constructor(@Inject(ThemeService) private readonly _themeService: ThemeService) {+ constructor(+ @Inject(ThemeService) private readonly _themeService: ThemeService,+ @IShortcutService private readonly _shortcutService: IShortcutService+ ) {this._selectionStyle = getNormalSelectionStyle(this._themeService);}@@ -640,7 +644,13 @@ export class SelectionRenderService implements ISelectionRenderService {this._upObserver = scene.onPointerUpObserver.add((upEvt: IPointerEvent | IMouseEvent) => {this._endSelection();this._selectionRangeWithStyle$.next(this.getSelectionDataWithStyle());++ // when selection mouse up, enable the short cut service+ this._shortcutService.setDisable(false);});++ // when selection mouse down, disable the short cut service+ this._shortcutService.setDisable(true);}convertSelectionRangeToData(selectionWithStyle: ISelectionWithStyle): ISelectionWithCoordAndStyle {diff --git a/packages/ui/src/services/shortcut/shortcut.service.ts b/packages/ui/src/services/shortcut/shortcut.service.tsindex db69e82812..49dddfe281 100644--- a/packages/ui/src/services/shortcut/shortcut.service.ts+++ b/packages/ui/src/services/shortcut/shortcut.service.ts@@ -44,6 +44,7 @@ export interface IShortcutService {getShortcutDisplay(shortcut: IShortcutItem): string;getShortcutDisplayOfCommand(id: string): string | null;getAllShortcuts(): IShortcutItem[];+ setDisable(disable: boolean): void;}export const IShortcutService = createIdentifier<IShortcutService>('univer.shortcut');@@ -57,6 +58,8 @@ export class DesktopShortcutService extends Disposable implements IShortcutServiprivate _forceEscaped = false;+ private _disable = false;+constructor(@ICommandService private readonly _commandService: ICommandService,@IPlatformService private readonly _platformService: IPlatformService,@@ -72,6 +75,10 @@ export class DesktopShortcutService extends Disposable implements IShortcutServi);}+ setDisable(disable: boolean): void {+ this._disable = disable;+ }+getAllShortcuts(): IShortcutItem[] {return Array.from(this._shortCutMapping.values()).map((v) => Array.from(v.values()))@@ -155,6 +162,10 @@ export class DesktopShortcutService extends Disposable implements IShortcutServireturn;}+ if (this._disable) {+ return;+ }+const shouldPreventDefault = this._dispatch(e);if (shouldPreventDefault) {e.preventDefault();