improve support for backspace

I still don't understand the entire state space here, so I'm trying to
err on the side of improving discoverability of the `ctrl-h` escape
hatch. Without requiring too wide a window to show all hotkeys on the
menu.
This commit is contained in:
Kartik K. Agaram 2021-12-03 18:05:25 -08:00
parent 4c196576aa
commit 31af4bd1fd
4 changed files with 24 additions and 19 deletions

View File

@ -122,7 +122,15 @@ a say in its future direction.
call to `assume_default_colors()` in function `main()` at the bottom of
`src/lua.c`. If you do this, you'll likely also need to tweak other colors
for legibility. Look for calls to `FG()`, `BG()` and `COLOR_PAIR()`.
```
* Backspace is known to not work in some configurations. As a workaround,
typing `ctrl-h` tends to work in those situations.
* Keys outside the main keyboard area are mostly not supported. This includes
the delete key when it's set away from the main keyboard area. (Macs call
the backspace key “delete”; it should behave like backspace. As
a consequence the menu sometimes mentions keys that don't work, just to
encourage people to try options.)
## What's with the name?

View File

@ -674,6 +674,8 @@ static void editorMenu(void) {
draw_menu_item("^b", "big picture");
draw_menu_item("^f", "find");
draw_menu_item("^/", "(un)comment line");
draw_menu_item("^h", "back up cursor");
draw_menu_item("^l", "end of line");
attrset(A_NORMAL);
}
@ -830,7 +832,7 @@ static void editorFind() {
mvprintw(LINES-2, 0, "Find: %s", query);
int c = getch();
if (c == TELIVA_BACKSPACE) {
if (c == KEY_BACKSPACE || c == DELETE || c == CTRL_H) {
if (qlen != 0) query[--qlen] = '\0';
last_match = -1;
} else if (c == ESC || c == ENTER) {
@ -1033,7 +1035,7 @@ static void editorGo(lua_State* L) {
mvprintw(LINES-2, 0, "Go to: %s", query);
int c = getch();
if (c == TELIVA_BACKSPACE) {
if (c == KEY_BACKSPACE || c == DELETE || c == CTRL_H) {
if (qlen != 0) query[--qlen] = '\0';
} else if (c == ESC || c == ENTER) {
editorSetStatusMessage("");
@ -1095,7 +1097,9 @@ static void editorProcessKeypress(lua_State* L) {
case CTRL_F:
editorFind();
break;
case TELIVA_BACKSPACE:
case KEY_BACKSPACE:
case DELETE:
case CTRL_H:
editorDelChar();
break;
case KEY_NPAGE:

View File

@ -451,8 +451,8 @@ static void recent_changes_menu (int cursor, int history_array_size) {
draw_string_on_menu("older");
/* draw_menu_item("↑/backspace", "newer"); */
attroff(A_REVERSE);
mvaddstr(LINES-1, menu_column, " ↑/" TELIVA_BACKSPACE_KEY_NAME " ");
menu_column += (strlen(TELIVA_BACKSPACE_KEY_NAME) + 4);
mvaddstr(LINES-1, menu_column, " ↑/backspace/delete/^h ");
menu_column += 23;
attron(A_REVERSE);
draw_string_on_menu("newer");
draw_menu_item("^e", "edit/add note");
@ -616,7 +616,9 @@ void recent_changes_view (lua_State *L) {
if (cursor > 1) --cursor;
break;
case KEY_UP:
case TELIVA_BACKSPACE:
case KEY_BACKSPACE:
case DELETE:
case CTRL_H:
if (cursor < history_array_size) ++cursor;
break;
case CTRL_E:
@ -649,6 +651,7 @@ static void big_picture_menu (void) {
menu_column = 2;
draw_menu_item("Esc", "go back");
draw_menu_item("Enter", "submit");
draw_menu_item("^h", "back up cursor");
draw_menu_item("^u", "clear");
draw_menu_item("^r", "recent changes");
attrset(A_NORMAL);
@ -811,7 +814,7 @@ restart:
mvaddch(LINES-2, x, ' ');
mvprintw(LINES-2, 0, "Edit: %s", query);
int c = getch();
if (c == TELIVA_BACKSPACE) {
if (c == KEY_BACKSPACE || c == DELETE || c == CTRL_H) {
if (qlen != 0) query[--qlen] = '\0';
} else if (c == ESC) {
return;

View File

@ -11,11 +11,6 @@ enum KEY_ACTION {
CTRL_F = 6,
CTRL_G = 7,
CTRL_H = 8,
#if __APPLE__
TELIVA_BACKSPACE = 127, /* delete */
#else
TELIVA_BACKSPACE = KEY_BACKSPACE,
#endif
TAB = 9,
ENTER = 10,
CTRL_K = 11,
@ -27,12 +22,7 @@ enum KEY_ACTION {
CTRL_X = 24,
ESC = 27,
CTRL_SLASH = 31,
DELETE = 127,
};
#if __APPLE__
#define TELIVA_BACKSPACE_KEY_NAME "delete/backspace"
#else
#define TELIVA_BACKSPACE_KEY_NAME "backspace"
#endif
#endif