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: use shift arrow key to select content in cell (#534)

Ran Luoad30e2129fe7
diff --git a/packages/ui-plugin-sheets/src/controllers/editor/end-edit.controller.ts b/packages/ui-plugin-sheets/src/controllers/editor/end-edit.controller.ts
index 73db848f2b..7825cf9bc9 100644
--- a/packages/ui-plugin-sheets/src/controllers/editor/end-edit.controller.ts
+++ b/packages/ui-plugin-sheets/src/controllers/editor/end-edit.controller.ts
@@ -1,4 +1,4 @@
-import { MoveCursorOperation } from '@univerjs/base-docs';
+import { MoveCursorOperation, MoveSelectionOperation } from '@univerjs/base-docs';
import { FormulaEngineService, matchToken } from '@univerjs/base-formula-engine';
import { IMouseEvent, IPointerEvent, IRenderManagerService } from '@univerjs/base-render';
import { SetRangeValuesCommand } from '@univerjs/base-sheets';
@@ -265,8 +265,8 @@ export class EndEditController extends Disposable {
this.disposeWithMe(
this._commandService.onCommandExecuted((command: ICommandInfo) => {
if (updateCommandList.includes(command.id)) {
- const params = command.params as IEditorBridgeServiceVisibleParam;
- const { keycode } = params;
+ const params = command.params as IEditorBridgeServiceVisibleParam & { isShift: boolean };
+ const { keycode, isShift } = params;
/**
* After the user enters the editor and actively moves the editor selection area with the mouse,
@@ -274,7 +274,7 @@ export class EndEditController extends Disposable {
* but move the cursor within the editor instead.
*/
if (keycode != null && this._isCursorChange === CursorChange.CursorChange) {
- this._moveInEditor(keycode);
+ this._moveInEditor(keycode, isShift);
return;
}
@@ -284,7 +284,8 @@ export class EndEditController extends Disposable {
);
}
- private _moveInEditor(keycode: KeyCode) {
+ // TODO: @JOCS, is it necessary to move these commands MoveSelectionOperation\MoveCursorOperation to shortcut? and use multi-commands?
+ private _moveInEditor(keycode: KeyCode, isShift: boolean) {
let direction = Direction.LEFT;
if (keycode === KeyCode.ARROW_DOWN) {
direction = Direction.DOWN;
@@ -294,9 +295,15 @@ export class EndEditController extends Disposable {
direction = Direction.RIGHT;
}
- this._commandService.executeCommand(MoveCursorOperation.id, {
- direction,
- });
+ if (isShift) {
+ this._commandService.executeCommand(MoveSelectionOperation.id, {
+ direction,
+ });
+ } else {
+ this._commandService.executeCommand(MoveCursorOperation.id, {
+ direction,
+ });
+ }
}
private _getEditorObject() {
diff --git a/packages/ui-plugin-sheets/src/controllers/sheet-ui.controller.ts b/packages/ui-plugin-sheets/src/controllers/sheet-ui.controller.ts
index 27e3dfe318..381220e72f 100644
--- a/packages/ui-plugin-sheets/src/controllers/sheet-ui.controller.ts
+++ b/packages/ui-plugin-sheets/src/controllers/sheet-ui.controller.ts
@@ -141,7 +141,7 @@ import {
EditorCursorTabShortcut,
EditorDeleteLeftShortcut,
EditorDeleteLeftShortcutInActive,
- generateArrowSelectionShortCuItem,
+ generateArrowSelectionShortCutItem,
} from './shortcuts/editor.shortcut';
import { SetColHiddenShortcutItem, SetRowHiddenShortcutItem } from './shortcuts/operation.shortcut';
import {
@@ -354,7 +354,7 @@ export class SheetUIController extends Disposable {
// cell content editing shortcuts
ClearSelectionValueShortcutItem,
- ...generateArrowSelectionShortCuItem(),
+ ...generateArrowSelectionShortCutItem(),
EditorCursorEnterShortcut,
EditorCursorTabShortcut,
EditorBreakLineShortcut,
diff --git a/packages/ui-plugin-sheets/src/controllers/shortcuts/editor.shortcut.ts b/packages/ui-plugin-sheets/src/controllers/shortcuts/editor.shortcut.ts
index 5e72c5ddbe..c9128db621 100644
--- a/packages/ui-plugin-sheets/src/controllers/shortcuts/editor.shortcut.ts
+++ b/packages/ui-plugin-sheets/src/controllers/shortcuts/editor.shortcut.ts
@@ -18,8 +18,9 @@ export const ARROW_SELECTION_KEYCODE_LIST = [
export const MOVE_SELECTION_KEYCODE_LIST = [KeyCode.ENTER, KeyCode.TAB, ...ARROW_SELECTION_KEYCODE_LIST];
-export function generateArrowSelectionShortCuItem() {
+export function generateArrowSelectionShortCutItem() {
const shortcutList: IShortcutItem[] = [];
+
for (const keycode of ARROW_SELECTION_KEYCODE_LIST) {
shortcutList.push({
id: SetCellEditVisibleArrowOperation.id,
@@ -29,9 +30,23 @@ export function generateArrowSelectionShortCuItem() {
visible: false,
eventType: DeviceInputEventType.Keyboard,
keycode,
+ isShift: false,
+ },
+ });
+
+ shortcutList.push({
+ id: SetCellEditVisibleArrowOperation.id,
+ binding: keycode | MetaKeys.SHIFT,
+ preconditions: (contextService) => whenEditorDidNotInputFormulaActivated(contextService),
+ staticParameters: {
+ visible: false,
+ eventType: DeviceInputEventType.Keyboard,
+ keycode,
+ isShift: true,
},
});
}
+
return shortcutList;
}