Skip to main content

Hardware keyboard

CodePad handles the keys below from any hardware keyboard: Bluetooth or USB, a Chromebook, an iPad keyboard, or the Mac keyboard on the simulator. Every other key goes to the platform, and printable keys type through the normal path, with auto close and typing coalescing.

ActionAndroidiOS
Move by one grapheme clusterLeft, RightLeft, Right
Move by one wordCtrl+Left, Ctrl+RightOption+Left, Option+Right
Move by one visual row, keeping the goal columnUp, DownUp, Down
Move by one viewport heightPage Up, Page DownPage Up, Page Down
Line start, line endHome, EndHome, End, Cmd+Left, Cmd+Right
Document start, document endCtrl+Home, Ctrl+EndCmd+Home, Cmd+End, Cmd+Up, Cmd+Down
Extend the selectionShift with any of the aboveShift with any of the above
Newline through the indenterEnter, numpad EnterEnter
Indent the caret or the selected linesTabTab
Outdent the selected linesShift+TabShift+Tab
Delete backward (an empty auto closed pair goes in one go)BackspaceBackspace
Delete forwardDeleteForward Delete (Fn+Delete on a Mac keyboard)
UndoCtrl+ZCmd+Z
RedoCtrl+Shift+Z, Ctrl+YShift+Cmd+Z
Select allCtrl+ACmd+A
Copy, cut, pasteCtrl+C, Ctrl+X, Ctrl+V, the dedicated keysCmd+C, Cmd+X, Cmd+V
Collapse the selection to the caretEscapeEscape

Under readOnly, movement, selection, select all, copy and Escape still work, and the editing keys do nothing. Word movement uses runs of [A-Za-z0-9_] and falls back to the platform's word breaks. A paste reports origin input in onChange, and undo and redo report undo and redo.

Android leaves Alt and Meta combinations and Ctrl+Tab to the platform. iOS leaves Control combinations, and Option with any key other than Left and Right, to UIKit. The editor's commands win over UIKit's own text navigation.

The undo stack on iOS​

The editor's history is the responder chain's undoManager, so Cmd+Z, shake to undo and the three finger gestures run the same undo groups as undo() and redo(). On Android the history is reached through the key table and the ref.

The same table from JavaScript​

moveCaret(direction, { select }) drives the movement rows, so a toolbar can match the keyboard:

DirectionAndroidiOS
left, rightLeft, RightLeft, Right
wordLeft, wordRightCtrl+Left, Ctrl+RightOption+Left, Option+Right
lineStart, lineEndHome, EndHome, End
documentStart, documentEndCtrl+Home, Ctrl+EndCmd+Home, Cmd+End
up, downUp, DownUp, Down
pageUp, pageDownPage Up, Page DownPage 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, Cmd and Option chords reach the table.