Hardware keyboard
The keys CodePad handles on each platform, and how to drive the same table from JavaScript.
CodePad handles the keys in the following table on any hardware keyboard, whether it's a Bluetooth or USB keyboard, a Chromebook, an iPad keyboard, or the Mac keyboard on the simulator. Every other key goes to the platform. Letters and symbols type like the soft keyboard: brackets close on their own, and typing groups into one undo step.
| Action | Android | iOS |
|---|---|---|
| Move by one character, where an emoji counts as one | Left, Right | Left, Right |
| Move by one word | Ctrl+Left, Ctrl+Right | Option+Left, Option+Right |
| Move up or down one row, back to the same column after a shorter line | Up, Down | Up, Down |
| Move by one screen of text | Page Up, Page Down | Page Up, Page Down |
| Line start, line end | Home, End | Home, End, Cmd+Left, Cmd+Right |
| Document start, document end | Ctrl+Home, Ctrl+End | Cmd+Home, Cmd+End, Cmd+Up, Cmd+Down |
| Extend the selection | Shift with any of the above | Shift with any of the above |
| Newline through the indenter | Enter, numpad Enter | Enter |
| Indent the caret or the selected lines | Tab | Tab |
| Outdent the selected lines | Shift+Tab | Shift+Tab |
| Delete backward (an empty auto closed pair goes in one go) | Backspace | Backspace |
| Delete forward | Delete | Forward Delete (Fn+Delete on a Mac keyboard) |
| Undo | Ctrl+Z | Cmd+Z |
| Redo | Ctrl+Shift+Z, Ctrl+Y | Shift+Cmd+Z |
| Select all | Ctrl+A | Cmd+A |
| Copy, cut, paste | Ctrl+C, Ctrl+X, Ctrl+V, the dedicated keys | Cmd+C, Cmd+X, Cmd+V |
| Collapse the selection to the caret | Escape | Escape |
When readOnly is on, movement, selection, select all, copy and Escape still work, and the editing keys do nothing. Moving by word skips spaces, then jumps over a run of ASCII letters, digits and _. Any other character, such as é or an emoji, is a step of its own. A paste reports the origin input in onChange, and undo and redo report undo and redo.
Android leaves Alt and Meta combinations and Ctrl+Tab to the system. iOS leaves Control combinations, and Option with any key other than Left and Right, to the system. When the editor and iOS both handle a key, the editor's command runs.
Undo on iOS
On iOS, Cmd+Z, shake to undo and the three-finger undo gestures undo the same steps as undo() and redo(). On Android, the keys in the table and the ref methods are the way to undo.
The same table from JavaScript
moveCaret(direction, { select }) drives the movement rows, so a toolbar can match the keyboard:
| Direction | Android | iOS |
|---|---|---|
left, right | Left, Right | Left, Right |
wordLeft, wordRight | Ctrl+Left, Ctrl+Right | Option+Left, Option+Right |
lineStart, lineEnd | Home, End | Home, End |
documentStart, documentEnd | Ctrl+Home, Ctrl+End | Cmd+Home, Cmd+End |
up, down | Up, Down | Up, Down |
pageUp, pageDown | Page Up, Page Down | Page Up, Page Down |
typeText('\n'), indent(), outdent(), deleteBackward() and deleteForward() cover Enter, Tab, Shift+Tab, Backspace and Delete. The keyboard guide has the toolbar recipe.
Testing without a keyboard
On an Android emulator with hw.keyboard=yes the host keyboard types into the editor, and adb shell input keyevent sends keys from a script. On the iOS simulator the Mac keyboard types into the editor, and with Connect Hardware Keyboard on, the Cmd and Option shortcuts work too.