# Keyboard Navigation Shortcuts

An explanation of the different built-in keyboard navigation shortcuts in SpreadJS, including limitations and the additional keyboard shortcuts project

## Content

You can change the active cell or selected cells with the mouse or keyboard keys. You can also use keyboard keys to make changes to the cell data.

The end-user can use the following default, keyboard keys:

| KEY | ACTION |
| --- | ------ |
| Ctrl+Z | `undo` |
| Ctrl+Y | `redo` |
| Ctrl + Down | `navigationBottom` |
| Down | `navigationDown` |
| End | `navigationEnd` |
| Ctrl+Right | `navigationEnd` |
| Ctrl+Home | `goToSheetBeginning` |
| Home | `navigationHome` |
| Ctrl+Left | `navigationHome2` |
| Ctrl+End | `goToSheetBottomRight` |
| Left | `navigationLeft` |
| Tab | `moveToNextCell` |
| PageDown | `navigationPageDown` |
| PageUp | `navigationPageUp` |
| Ctrl+PageUp | `NavigationPreviousSheet` |
| Ctrl+PageDown | `NavigationNextSheet` |
| Shift+Tab | `moveToPreviousCell` |
| Right | `navigationRight` |
| Ctrl+Up | `navigationTop` |
| Up | `navigationUp` |
| Delete | `clear` |
| Back | `clearAndEditing` |
| Enter | `commitInputNavigationDown` (commit and move down) |
| Shift+Enter | `commitInputNavigationUp` |
| ESC | `cancelInput` |
| Shift+Left | `selectionLeft` |
| Shift+Right | `selectionRight` |
| Shift+Up | `selectionUp` |
| Shift+Down | `selectionDown` |
| Shift+Home | `selectionHome` |
| Ctrl+Shift+Left | `selectionHome` |
| Shift+End | `selectionEnd` |
| Ctrl+Shift+Right | `selectionEnd` |
| Shift+PageUp | `selectionPageUp` |
| Shift+PageDown | `selectionPageDown` |
| Ctrl+Shift+Up | `selectionTop` |
| Ctrl+Shift+Down | `selectionBottom` |
| Ctrl+Shift+Home | `selectionFirst` |
| Ctrl+Shift+End | `selectionLast` |
| Ctrl+C | `Copy` |
| Ctrl+X | `Cut` |
| Ctrl+V | `Paste` |
| Alt+Enter | `InputNewLine` |

>type=note
> **Note:** The Ctrl+PageUp and Ctrl+PageDown keyboard shortcuts only work when there is no conflict with the host environment.
> Additional information about copy and paste actions using keyboard shortcuts:
>
> * SpreadJS does not have direct access to the system clipboard.
> * When using Ctrl+C to copy in SpreadJS, it will perform both outside copy and internal copy.
> * When using Ctrl+V to paste in SpreadJS, it will decide whether to do outside paste or internal paste.
> * When using the context menu or the command manager, SpreadJS always does an internal copy and internal paste because it cannot access the system clipboard.

## Make Enter Commit Without Moving

By default, the `Enter` key is bound to the `commitInputNavigationDown` command, which:

* Commits the edited value
* Moves the active cell down

Starting from SpreadJS v19.2, a built-in command named `commitInput` is available.
The `commitInput` command:

* Commits the edited value
* Ends edit mode
* Keeps the active cell in place
* Has no default shortcut binding

### Scenario 1: Enter Commits Only (No Movement)

If you want the `Enter` key to commit the value but **not move the active cell**, follow these steps:
Step 1: Remove the default Enter behavior

```javascript
var commandManager = spread.commandManager();

commandManager.setShortcutKey(
  null,
  GC.Spread.Commands.Key.enter,
  false, false, false, false
);
```

Step 2: Bind Enter to `commitInput`

```javascript
commandManager.setShortcutKey(
  "commitInput",
  GC.Spread.Commands.Key.enter,
  false, false, false, false
);
```

### Result

* When editing a cell → Value is committed and the active cell stays in place.
* When not editing → Enter does nothing.

### Scenario 2: Commit When Editing, Move Down Otherwise

If you want:

* Editing → Commit only
* Not editing → Move down

You can bind both `commitInput` and a reused `navigationDown` command.

```javascript
var commandManager = spread.commandManager();

// Remove default Enter behavior
commandManager.setShortcutKey(
  null,
  GC.Spread.Commands.Key.enter,
  false, false, false, false
);

// Register navigationDown with a new name
commandManager.register(
  "navigationDownForEnter",
  GC.Spread.Sheets.Commands.navigationDown
);

// Bind navigationDownForEnter first
commandManager.setShortcutKey(
  "navigationDownForEnter",
  GC.Spread.Commands.Key.enter,
  false, false, false, false
);

// Bind commitInput
commandManager.setShortcutKey(
  "commitInput",
  GC.Spread.Commands.Key.enter,
  false, false, false, false
);
```

### Result

| State | Behavior |
| ----- | -------- |
| Editing | Commit value and stay in the same cell |
| Not Editing | Move active cell down |

### Execute commitInput Directly

You can also execute the command programmatically:

```javascript
spread.commandManager().execute({
  cmd: "commitInput",
  sheetName: spread.getActiveSheet().name()
});
```

## Additional Keyboard Shortcuts

SpreadJS supports some additional keyboard shortcut commands. These shortcuts can be included in your project as an extension by downloading and using the **Keyboard Shortcuts** project available [here](https://github.com/GrapeCity/spreadjs-resources). You can also add custom shortcuts based on this project.

| KEY | ACTION |
| --- | ------ |
| Shift + Space | `selectEntireRow` |
| Ctrl + Space | `selectEntireColumn` |
| Ctrl + "-" | `deleteEntireRowOrColumn` |
| Ctrl + 9 | `hideSelectRows` |
| Ctrl + [ | `goToPrecedent` |
| Ctrl + ] | `goToDependent` |
| Ctrl + ; | `setDate` |
| Alt + = | `autoSumSelectRange` |
| Alt + Shift + Right Arrow | `groupSelectRange` |
| Alt + Shift + Left Arrow | `ungroupSelectRange` |
| Alt + ; | `selectVisibleCells` |
| Ctrl + D | `CopyCellDown` |
| Ctrl + R | `CopyCellRight` |
| Ctrl + Shift + "+" | `InsertRowsOrColumns` |
| Ctrl + A | `SelectAll` |
| Ctrl + B | `setCellBold` |
| Ctrl + I | `setCellItalicize` |
| Ctrl + U | `setCellUnderline` |
| Ctrl + Shift + % | `setNumberToPrecent` |
| Ctrl + Arrow | `navigationNextnonEmpty ` |
| Ctrl + Shift + Arrow | `selectRangenonEmpty ` |
| Ctrl + Shift + + | `insertRange` |
| Ctrl + - | `deleteRange` |

>type=note
> **Notes**:
>
> * The shortcut library is integrated into the Designer library and is included in the Designer library build output, so users won't need to link shortcut library files separately.
> * Ctrl + Arrow and Ctrl + Shift + Arrow do not support redo and undo actions.
> * These shortcuts do not support MAC OS.
> * These shortcuts do not support TableSheet and GanttSheet.