Fixes single line delete

This commit is contained in:
sloum 2020-03-14 13:55:50 -07:00
parent 01e0f008d4
commit 91476f21d5
1 changed files with 24 additions and 11 deletions

View File

@ -1349,21 +1349,34 @@ void editorCommandKp(int c) {
deleting++;
return;
} else {
int start_x = E.cx;
int start_y = E.cy;
int end_x, end_y;
end_y = E.cy + counter;
if (end_y >= E.numRows) end_y = E.numRows - 1;
end_x = E.row[end_y].size - 1;
editorCopyRange(0, start_y, end_x, end_y);
while (counter > 0) {
if (counter <= 1) {
int sz = E.row[E.cy].size + 1;
char *buf = malloc(sz);
strcpy(buf, E.row[E.cy].chars);
buf[sz - 1] = '\r';
editorUpdatePaste(buf, sz);
free(buf);
editorDelRow(E.cy);
if (E.cy == E.numRows) E.cy--;
if (E.cy < 0) E.cy = 0;
counter--;
if (E.cx >= E.row[E.cy].size) E.cx = 0;
} else {
int start_x = E.cx;
int start_y = E.cy;
int end_x, end_y;
end_y = E.cy + counter;
if (end_y >= E.numRows) end_y = E.numRows - 1;
end_x = E.row[end_y].size - 1;
editorCopyRange(0, start_y, end_x, end_y);
while (counter > 0) {
editorDelRow(E.cy);
if (E.cy == E.numRows) E.cy--;
if (E.cy < 0) E.cy = 0;
counter--;
}
E.cx = start_x;
if (E.cx >= E.row[E.cy].size) E.cx = E.row[E.cy].size - 1;
}
E.cx = start_x;
if (E.cx >= E.row[E.cy].size) E.cx = E.row[E.cy].size - 1;
break;
}
case '$':