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