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
feat: support select all in doc and sheet cell when edit (#533)
Ran Luo863a43c6bc2c
diff --git a/packages/base-docs/src/commands/operations/cursor.operation.ts b/packages/base-docs/src/commands/operations/cursor.operation.tsindex 6db4517cb9..13467a3643 100644--- a/packages/base-docs/src/commands/operations/cursor.operation.ts+++ b/packages/base-docs/src/commands/operations/cursor.operation.ts@@ -11,7 +11,9 @@ export interface IMoveCursorOperationParams {*/export const MoveCursorOperation: IOperation<IMoveCursorOperationParams> = {id: 'doc.operation.move-cursor',+type: CommandType.OPERATION,+handler: (accessor, params) => {if (!params) {return false;@@ -26,7 +28,9 @@ export const MoveCursorOperation: IOperation<IMoveCursorOperationParams> = {*/export const MoveSelectionOperation: IOperation<IMoveCursorOperationParams> = {id: 'doc.operation.move-selection',+type: CommandType.OPERATION,+handler: (accessor, params) => {if (!params) {return false;diff --git a/packages/base-docs/src/commands/operations/select-all.operation.ts b/packages/base-docs/src/commands/operations/select-all.operation.tsnew file mode 100644index 0000000000..d3fa176533--- /dev/null+++ b/packages/base-docs/src/commands/operations/select-all.operation.ts@@ -0,0 +1,35 @@+import { ITextRangeWithStyle } from '@univerjs/base-render';+import { CommandType, ICommand, IUniverInstanceService } from '@univerjs/core';++import { TextSelectionManagerService } from '../../services/text-selection-manager.service';++interface ISelectAllOperationParams {}++export const SelectAllOperation: ICommand<ISelectAllOperationParams> = {+ id: 'doc.operation.select-all',++ type: CommandType.COMMAND,++ handler: async (accessor) => {+ const univerInstanceService = accessor.get(IUniverInstanceService);+ const textSelectionManagerService = accessor.get(TextSelectionManagerService);++ const prevBody = univerInstanceService.getCurrentUniverDocInstance().getSnapshot().body;++ if (prevBody == null) {+ return false;+ }++ const textRanges: ITextRangeWithStyle[] = [+ {+ startOffset: 0,+ endOffset: prevBody.dataStream.length - 2,+ collapsed: false,+ },+ ];++ textSelectionManagerService.replaceTextRanges(textRanges);++ return true;+ },+};diff --git a/packages/base-docs/src/commands/operations/set-doc-zoom-ratio.operation.ts b/packages/base-docs/src/commands/operations/set-doc-zoom-ratio.operation.tsindex 6a06df38f7..c890c22d32 100644--- a/packages/base-docs/src/commands/operations/set-doc-zoom-ratio.operation.ts+++ b/packages/base-docs/src/commands/operations/set-doc-zoom-ratio.operation.ts@@ -20,7 +20,9 @@ export const SetDocZoomRatioUndoMutationFactory = (export const SetDocZoomRatioOperation: IOperation<ISetDocZoomRatioOperationParams> = {id: 'doc.operation.set-zoom-ratio',+type: CommandType.OPERATION,+handler: (accessor, params: ISetDocZoomRatioOperationParams) => {const documentModel = accessor.get(IUniverInstanceService).getUniverDocInstance(params.unitId);if (!documentModel) {diff --git a/packages/base-docs/src/commands/operations/text-selection.operation.ts b/packages/base-docs/src/commands/operations/text-selection.operation.tsindex 515356cc54..d58d05181e 100644--- a/packages/base-docs/src/commands/operations/text-selection.operation.ts+++ b/packages/base-docs/src/commands/operations/text-selection.operation.ts@@ -13,7 +13,9 @@ export interface ISetTextSelectionsOperationParams {export const SetTextSelectionsOperation: IOperation<ISetTextSelectionsOperationParams> = {id: 'doc.operation.set-selections',+type: CommandType.OPERATION,+handler: (accessor, params) => {const textSelectionManagerService = accessor.get(TextSelectionManagerService);diff --git a/packages/base-docs/src/doc-plugin.ts b/packages/base-docs/src/doc-plugin.tsindex 9b8518a75e..2fac009228 100644--- a/packages/base-docs/src/doc-plugin.ts+++ b/packages/base-docs/src/doc-plugin.ts@@ -36,6 +36,7 @@ import { ReplaceContentCommand } from './commands/commands/replace-content.commaimport { SetDocZoomRatioCommand } from './commands/commands/set-doc-zoom-ratio.command';import { RichTextEditingMutation } from './commands/mutations/core-editing.mutation';import { MoveCursorOperation, MoveSelectionOperation } from './commands/operations/cursor.operation';+import { SelectAllOperation } from './commands/operations/select-all.operation';import { SetDocZoomRatioOperation } from './commands/operations/set-doc-zoom-ratio.operation';import { SetTextSelectionsOperation } from './commands/operations/text-selection.operation';import { DocClipboardController } from './controllers/clipboard.controller';@@ -65,6 +66,7 @@ import {MoveSelectionLeftShortcut,MoveSelectionRightShortcut,MoveSelectionUpShortcut,+ SelectAllShortcut,} from './shortcuts/cursor.shortcut';import { DocCanvasView } from './views/doc-canvas-view';@@ -129,6 +131,7 @@ export class DocPlugin extends Plugin {SetDocZoomRatioCommand,SetDocZoomRatioOperation,SetTextSelectionsOperation,+ SelectAllOperation,] as ICommand[]).forEach((command) => {this._injector.get(ICommandService).registerCommand(command);@@ -143,6 +146,7 @@ export class DocPlugin extends Plugin {MoveSelectionDownShortcut,MoveSelectionLeftShortcut,MoveSelectionRightShortcut,+ SelectAllShortcut,DeleteLeftShortcut,DeleteRightShortcut,BreakLineShortcut,diff --git a/packages/base-docs/src/shortcuts/cursor.shortcut.ts b/packages/base-docs/src/shortcuts/cursor.shortcut.tsindex 0c0f17fc63..9f64f271f2 100644--- a/packages/base-docs/src/shortcuts/cursor.shortcut.ts+++ b/packages/base-docs/src/shortcuts/cursor.shortcut.ts@@ -1,7 +1,8 @@import { IShortcutItem, KeyCode, MetaKeys } from '@univerjs/base-ui';-import { Direction, FOCUSING_DOC } from '@univerjs/core';+import { Direction, FOCUSING_DOC, FOCUSING_EDITOR } from '@univerjs/core';import { MoveCursorOperation, MoveSelectionOperation } from '../commands/operations/cursor.operation';+import { SelectAllOperation } from '../commands/operations/select-all.operation';export const MoveCursorUpShortcut: IShortcutItem = {id: MoveCursorOperation.id,@@ -74,3 +75,10 @@ export const MoveSelectionRightShortcut: IShortcutItem = {direction: Direction.RIGHT,},};++export const SelectAllShortcut: IShortcutItem = {+ id: SelectAllOperation.id,+ binding: KeyCode.A | MetaKeys.CTRL_COMMAND,+ preconditions: (contextService) =>+ contextService.getContextValue(FOCUSING_DOC) || contextService.getContextValue(FOCUSING_EDITOR),+};diff --git a/packages/base-ui/src/services/shortcut/shortcut.service.ts b/packages/base-ui/src/services/shortcut/shortcut.service.tsindex fbf4a8133d..5051c6f83f 100644--- a/packages/base-ui/src/services/shortcut/shortcut.service.ts+++ b/packages/base-ui/src/services/shortcut/shortcut.service.ts@@ -123,7 +123,7 @@ export class DesktopShortcutService extends Disposable implements IShortcutServi}}- private _dispatch(e: KeyboardEvent): boolean {+ private _dispatch(e: KeyboardEvent) {const binding = this._deriveBindingFromEvent(e);if (binding === null) {return false;