Simple backspacing.

This commit is contained in:
Saumya Bhatnagar 2018-05-31 04:54:49 +05:30
parent 8070f56845
commit e9954b62a4
2 changed files with 23 additions and 2 deletions

BIN
editor

Binary file not shown.

View File

@ -278,6 +278,17 @@ void editorRowInsertChar(editorrow* erow, int at, char c) {
E.dirty++;
}
void editorRowDelChar(editorrow* erow, int at) {
if (at < 0 || at > erow->length) {
return;
}
memmove(&erow->text[at], &erow->text[at+1], erow->length - at);
erow->length--;
editorUpdateRow(erow);
E.dirty++;
}
/*** editor operations ***/
void editorInsertChar(int c) {
@ -289,6 +300,15 @@ void editorInsertChar(int c) {
E.cursorX++;
}
void editorDelChar() {
if (E.cursorY == E.screenrows) {
return;
}
editorRowDelChar(&E.erow[E.cursorY], E.cursorX-1);
E.cursorX--;
}
/*** file I/O ***/
void editorOpen(char * file) {
@ -589,7 +609,8 @@ void editorProcessKey() {
case BACKSPACE:
case DEL_KEY:
case CTRL_KEY('h'):
/* TODO */
if (c == DEL_KEY) editorMoveCursor(ARROW_RIGHT);
editorDelChar();
break;
case CTRL_KEY('l'): // do nothing for escape key and Ctrl+L
case '\x1b':
@ -600,7 +621,7 @@ void editorProcessKey() {
default:
editorInsertChar(c);
}
quit_times = EDITOR_QUIT_TIMES;
}