Various minor bug cleanups.

This commit is contained in:
2025-11-29 21:33:45 -08:00
parent 3de5ec68f8
commit b41946c470
18 changed files with 803 additions and 620 deletions

View File

@@ -95,38 +95,23 @@ map_key_to_command(const int ch, bool &k_prefix, bool &esc_meta, MappedInput &ou
out = {true, CommandId::Refresh, "", 0};
return true;
}
if (ch == CTRL('L')) {
out = {true, CommandId::Refresh, "", 0};
// Tab (note: terminals encode Tab and C-i as the same code 9)
if (ch == '\t') {
k_prefix = false;
out.hasCommand = true;
out.id = CommandId::InsertText;
out.arg = "\t";
out.count = 0;
return true;
}
if (ch == CTRL('S')) {
out = {true, CommandId::FindStart, "", 0};
return true;
}
// Emacs-style movement aliases
if (ch == CTRL('N')) { // C-n: down
out = {true, CommandId::MoveDown, "", 0};
return true;
}
if (ch == CTRL('P')) { // C-p: up
out = {true, CommandId::MoveUp, "", 0};
return true;
}
if (ch == CTRL('F')) { // C-f: right/forward
out = {true, CommandId::MoveRight, "", 0};
return true;
}
if (ch == CTRL('B')) { // C-b: left/back
out = {true, CommandId::MoveLeft, "", 0};
return true;
}
if (ch == CTRL('A')) {
out = {true, CommandId::MoveHome, "", 0};
return true;
}
if (ch == CTRL('E')) {
out = {true, CommandId::MoveEnd, "", 0};
return true;
// Generic Control-chord lookup (after handling special prefixes/cancel)
if (ch >= 1 && ch <= 26) {
int ascii_key = 'a' + (ch - 1);
CommandId id;
if (KLookupCtrlCommand(ascii_key, id)) {
out = {true, id, "", 0};
return true;
}
}
// Enter
@@ -142,18 +127,15 @@ map_key_to_command(const int ch, bool &k_prefix, bool &esc_meta, MappedInput &ou
return true;
}
// If previous key was ESC, interpret as meta
// If previous key was ESC, interpret as meta and use ESC keymap
if (esc_meta) {
esc_meta = false;
int ascii_key = ch;
if (ascii_key >= 'A' && ascii_key <= 'Z')
ascii_key = ascii_key - 'A' + 'a';
if (ascii_key == 'b') {
out = {true, CommandId::WordPrev, "", 0};
return true;
}
if (ascii_key == 'f') {
out = {true, CommandId::WordNext, "", 0};
CommandId id;
if (KLookupEscCommand(ascii_key, id)) {
out = {true, id, "", 0};
return true;
}
// Unhandled meta key: no command
@@ -161,29 +143,29 @@ map_key_to_command(const int ch, bool &k_prefix, bool &esc_meta, MappedInput &ou
return true;
}
if (k_prefix) {
k_prefix = false; // single next key only
// Determine if this is a control chord (e.g., C-x) and normalize
bool ctrl = false;
int ascii_key = ch;
if (ch >= 1 && ch <= 26) {
ctrl = true;
ascii_key = 'a' + (ch - 1);
}
// For letters, normalize to lowercase ASCII
ascii_key = KLowerAscii(ascii_key);
if (k_prefix) {
k_prefix = false; // single next key only
// Determine if this is a control chord (e.g., C-x) and normalize
bool ctrl = false;
int ascii_key = ch;
if (ch >= 1 && ch <= 26) {
ctrl = true;
ascii_key = 'a' + (ch - 1);
}
// For letters, normalize to lowercase ASCII
ascii_key = KLowerAscii(ascii_key);
CommandId id;
if (KLookupKCommand(ascii_key, ctrl, id)) {
out = {true, id, "", 0};
} else {
// Show unknown k-command message with the typed character
char c = (ascii_key >= 0x20 && ascii_key <= 0x7e) ? static_cast<char>(ascii_key) : '?';
std::string arg(1, c);
out = {true, CommandId::UnknownKCommand, arg, 0};
}
return true;
}
CommandId id;
if (KLookupKCommand(ascii_key, ctrl, id)) {
out = {true, id, "", 0};
} else {
// Show unknown k-command message with the typed character
char c = (ascii_key >= 0x20 && ascii_key <= 0x7e) ? static_cast<char>(ascii_key) : '?';
std::string arg(1, c);
out = {true, CommandId::UnknownKCommand, arg, 0};
}
return true;
}
// Printable ASCII
if (ch >= 0x20 && ch <= 0x7E) {