delete next word complete, delete prev in progress.
This commit is contained in:
85
main.c
85
main.c
@@ -124,7 +124,9 @@ int get_winsz(int *rows, int *cols);
|
|||||||
void goto_line(void);
|
void goto_line(void);
|
||||||
int cursor_at_eol(void);
|
int cursor_at_eol(void);
|
||||||
void find_next_word(void);
|
void find_next_word(void);
|
||||||
|
void delete_next_word(void);
|
||||||
void find_prev_word(void);
|
void find_prev_word(void);
|
||||||
|
void delete_prev_word(void);
|
||||||
void delete_row(int at);
|
void delete_row(int at);
|
||||||
void row_append_row(struct erow *row, char *s, int len);
|
void row_append_row(struct erow *row, char *s, int len);
|
||||||
void row_insert_ch(struct erow *row, int at, int16_t c);
|
void row_insert_ch(struct erow *row, int at, int16_t c);
|
||||||
@@ -535,7 +537,6 @@ find_next_word(void)
|
|||||||
move_cursor(ARROW_RIGHT);
|
move_cursor(ARROW_RIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
editor_set_status("%d, %d done", editor.curx, editor.cury);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -549,6 +550,34 @@ find_next_word(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
delete_next_word(void)
|
||||||
|
{
|
||||||
|
while (cursor_at_eol()) {
|
||||||
|
move_cursor(ARROW_RIGHT);
|
||||||
|
deletech();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isalnum(editor.row[editor.cury].line[editor.curx])) {
|
||||||
|
while (!isspace(editor.row[editor.cury].line[editor.curx]) && !cursor_at_eol()) {
|
||||||
|
move_cursor(ARROW_RIGHT);
|
||||||
|
deletech();
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isspace(editor.row[editor.cury].line[editor.curx])) {
|
||||||
|
while (isspace(editor.row[editor.cury].line[editor.curx])) {
|
||||||
|
move_cursor(ARROW_RIGHT);
|
||||||
|
deletech();
|
||||||
|
}
|
||||||
|
|
||||||
|
delete_next_word();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
find_prev_word(void)
|
find_prev_word(void)
|
||||||
{
|
{
|
||||||
@@ -580,6 +609,36 @@ find_prev_word(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
delete_prev_word(void)
|
||||||
|
{
|
||||||
|
/* Clean up any empty lines. */
|
||||||
|
if (editor.curx == 0) {
|
||||||
|
if (editor.cury == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (editor.curx == 0) {
|
||||||
|
deletech();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* snarf up whitespace */
|
||||||
|
while (isspace(editor.row[editor.cury].line[editor.curx])) {
|
||||||
|
move_cursor(ARROW_RIGHT);
|
||||||
|
deletech();
|
||||||
|
}
|
||||||
|
|
||||||
|
while (editor.curx > 0 && !isalnum(editor.row[editor.cury].line[editor.curx])) {
|
||||||
|
deletech();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isalnum(editor.row[editor.cury].line[editor.curx])) {
|
||||||
|
move_cursor(ARROW_RIGHT);
|
||||||
|
deletech();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
delete_row(int at)
|
delete_row(int at)
|
||||||
@@ -661,6 +720,9 @@ insertch(int16_t c)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* deletech
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
deletech(void)
|
deletech(void)
|
||||||
{
|
{
|
||||||
@@ -1268,8 +1330,6 @@ process_normal(int16_t c)
|
|||||||
void
|
void
|
||||||
process_escape(int16_t c)
|
process_escape(int16_t c)
|
||||||
{
|
{
|
||||||
struct erow *row = &editor.row[editor.cury];
|
|
||||||
|
|
||||||
editor_set_status("hi");
|
editor_set_status("hi");
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
@@ -1281,22 +1341,17 @@ process_escape(int16_t c)
|
|||||||
editor.cury = 0;
|
editor.cury = 0;
|
||||||
editor.curx = 0;
|
editor.curx = 0;
|
||||||
break;
|
break;
|
||||||
case 'f':
|
|
||||||
find_next_word();
|
|
||||||
break;
|
|
||||||
case 'b':
|
case 'b':
|
||||||
find_prev_word();
|
find_prev_word();
|
||||||
break;
|
break;
|
||||||
|
case 'd':
|
||||||
|
delete_next_word();
|
||||||
|
break;
|
||||||
|
case 'f':
|
||||||
|
find_next_word();
|
||||||
|
break;
|
||||||
case BACKSPACE:
|
case BACKSPACE:
|
||||||
if (isalnum(row->line[editor.curx])) {
|
delete_prev_word();
|
||||||
editor_set_status("is alnum");
|
|
||||||
while (editor.curx > 0 && isalnum(row->line[editor.curx])) {
|
|
||||||
process_normal(BACKSPACE);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
editor_set_status("not alnum");
|
|
||||||
process_normal(BACKSPACE);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
editor_set_status("unknown ESC key: %04x", c);
|
editor_set_status("unknown ESC key: %04x", c);
|
||||||
|
|||||||
Reference in New Issue
Block a user