Command stacking
This commit is contained in:
parent
a92c9cd07a
commit
f072889a49
2 changed files with 33 additions and 4 deletions
10
config.h
10
config.h
|
@ -46,11 +46,17 @@ enum keys {
|
|||
PAGE_DOWN
|
||||
};
|
||||
|
||||
enum actions {
|
||||
COUNTING,
|
||||
DELETE
|
||||
};
|
||||
|
||||
enum modes {
|
||||
NORMAL,
|
||||
INSERT,
|
||||
VISUAL,
|
||||
COMMAND
|
||||
COMMAND,
|
||||
PENDING0,
|
||||
};
|
||||
|
||||
enum highlight {
|
||||
|
@ -121,4 +127,4 @@ language_t langs[] = {
|
|||
#define LANGS_LEN (sizeof(langs) / sizeof(langs[0]))
|
||||
|
||||
#define CTRL_KEY(k) ((k) & 0x1f)
|
||||
#define COLOR_LEN 19
|
||||
#define MAX_COMMAND_SIZE 512
|
||||
|
|
27
vip.c
27
vip.c
|
@ -23,6 +23,9 @@ int rows, cols;
|
|||
editor_t editor[9];
|
||||
int editors = 0;
|
||||
editor_t *cur_editor;
|
||||
int action = DEFAULT;
|
||||
char cmd[MAX_COMMAND_SIZE];
|
||||
int cmd_len = 0;
|
||||
|
||||
void draw_status_bar(void);
|
||||
void refresh_screen(void);
|
||||
|
@ -1076,6 +1079,12 @@ int main(int argc, char **argv)
|
|||
insert_new_line();
|
||||
break;
|
||||
|
||||
case '1': case '2': case '3': case '4': case '5': case '6': case '7':
|
||||
case '8': case '9':
|
||||
action = COUNTING;
|
||||
cmd[cmd_len++] = c;
|
||||
break;
|
||||
|
||||
case HOME_KEY:
|
||||
cur_editor->x = 0;
|
||||
break;
|
||||
|
@ -1211,7 +1220,16 @@ int main(int argc, char **argv)
|
|||
|
||||
case 'j': /* PASSTHROUGH */
|
||||
if (cur_editor->mode != INSERT) {
|
||||
move_xy(ARROW_DOWN);
|
||||
if (action == COUNTING) {
|
||||
for (int i = 0; i < atoi(cmd); i++) {
|
||||
move_xy(ARROW_DOWN);
|
||||
}
|
||||
action = DEFAULT;
|
||||
cmd_len = 0;
|
||||
memset(&cmd, 0, MAX_COMMAND_SIZE);
|
||||
} else {
|
||||
move_xy(ARROW_DOWN);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1243,7 +1261,12 @@ int main(int argc, char **argv)
|
|||
|
||||
case '0': /* PASSTHROUGH */
|
||||
if (cur_editor->mode == NORMAL) {
|
||||
cur_editor->x = 0;
|
||||
if (cmd_len == 0) {
|
||||
cur_editor->x = 0;
|
||||
} else {
|
||||
action = COUNTING;
|
||||
cmd[cmd_len++] = c;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue