Guide API
Skip to main content

ctrl_to_arrow

Function ctrl_to_arrow 

Source
pub fn ctrl_to_arrow(ke: KeyEvent) -> KeyEvent
Expand description

Map WordStar Ctrl-letter navigation keys to their arrow/nav equivalents.

In the decomposed key model, a Ctrl-letter is Key::Char(letter) with modifiers.ctrl set. The 11-entry table maps:

Ctrl+→ Key
SLeft
DRight
EUp
XDown
AHome
FEnd
GDelete
VInsert
RPageUp
CPageDown
HBackspace

The letter is matched case-insensitively. On a match the resulting KeyEvent has all modifiers cleared (only the base arrow/nav key is returned). Any key that does not match — including literal arrow keys, non-Char keys, or Char keys without ctrl — is returned unchanged.

When to call: pass an incoming KeyDown event through this function before dispatching it for navigation — e.g. in InputLine::handle_event and Editor::handle_event — so that applications supporting WordStar-style navigation can use either arrow keys or the traditional Ctrl-letter chords. Widgets that do not want WordStar mode (e.g. plain text fields that use Ctrl letters for cut/copy/paste) should skip this call.

§Turbo Vision heritage

Ports ctrlToArrow (drivers2.cpp).