diff --git a/hermes.c b/hermes.c index 3b1082b..13ffebe 100644 --- a/hermes.c +++ b/hermes.c @@ -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 '$':