Reworked multipliers and deletion
This commit is contained in:
parent
2574c8e911
commit
39f37d7ffd
220
hermes.c
220
hermes.c
|
@ -1157,9 +1157,28 @@ void editorCommandKp(int c) {
|
||||||
case 'k':
|
case 'k':
|
||||||
case 'h':
|
case 'h':
|
||||||
case 'l':
|
case 'l':
|
||||||
while (counter > 0) {
|
{
|
||||||
editorMoveCursor(c);
|
int vx = E.cx;
|
||||||
counter--;
|
int vy = E.cy;
|
||||||
|
while (counter > 0) {
|
||||||
|
editorMoveCursor(c);
|
||||||
|
counter--;
|
||||||
|
}
|
||||||
|
if (!deleting) break;
|
||||||
|
E.vx = vx;
|
||||||
|
E.vy = vy;
|
||||||
|
if (c == 'h' && E.vx > 0) E.vx--;
|
||||||
|
if (c == 'j') {
|
||||||
|
E.vx = 0;
|
||||||
|
E.cx = E.row[E.cy].size - 1;
|
||||||
|
}
|
||||||
|
if (c == 'k') {
|
||||||
|
E.vx = E.row[E.vy].size - 1;
|
||||||
|
E.cx = 0;
|
||||||
|
}
|
||||||
|
if (c == 'l' && E.cx > 0) E.cx--;
|
||||||
|
editorDeleteSelection();
|
||||||
|
if (c == 'k' || c == 'j') editorDelRow(E.cy);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '\033':
|
case '\033':
|
||||||
|
@ -1169,6 +1188,7 @@ void editorCommandKp(int c) {
|
||||||
{
|
{
|
||||||
int c = editorReadKey();
|
int c = editorReadKey();
|
||||||
if (c) {
|
if (c) {
|
||||||
|
if (c == '\033') break;
|
||||||
E.mode = InputMode;
|
E.mode = InputMode;
|
||||||
editorMoveCursor(ARROW_RIGHT);
|
editorMoveCursor(ARROW_RIGHT);
|
||||||
editorDeleteChar();
|
editorDeleteChar();
|
||||||
|
@ -1179,67 +1199,42 @@ void editorCommandKp(int c) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'g':
|
case 'g':
|
||||||
if (deleting) {
|
{
|
||||||
int totlen = 0;
|
int vx = E.cx;
|
||||||
int j;
|
int vy = E.cy;
|
||||||
for (j = 0; j <= E.cy; j++)
|
|
||||||
totlen += E.row[j].size + 1;
|
|
||||||
|
|
||||||
char *buf = malloc(totlen);
|
|
||||||
char *p = buf;
|
|
||||||
|
|
||||||
int count = E.cy;
|
|
||||||
E.cy = 0;
|
|
||||||
E.rowoff = 0;
|
|
||||||
while (count >= 0) {
|
|
||||||
memcpy(p, E.row[E.cy].chars, E.row[E.cy].size);
|
|
||||||
p += E.row[E.cy].size;
|
|
||||||
*p = '\r';
|
|
||||||
p++;
|
|
||||||
|
|
||||||
deleting = 1;
|
|
||||||
editorCommandKp('d');
|
|
||||||
count--;
|
|
||||||
}
|
|
||||||
editorUpdatePaste(buf, totlen);
|
|
||||||
} else {
|
|
||||||
E.cy = 0;
|
E.cy = 0;
|
||||||
E.cx = 0;
|
E.cx = 0;
|
||||||
E.rowoff = 0;
|
E.rowoff = 0;
|
||||||
|
if (!deleting) break;
|
||||||
|
E.vx = vx;
|
||||||
|
E.vy = vy;
|
||||||
|
int extraRow = 0;
|
||||||
|
E.vx--;
|
||||||
|
if (E.vx < 0) {
|
||||||
|
if (E.vy < 1) break;
|
||||||
|
E.vy--;
|
||||||
|
E.vx = E.row[E.vy].size - 1;
|
||||||
|
extraRow = 1;
|
||||||
|
}
|
||||||
|
editorDeleteSelection();
|
||||||
|
if (extraRow) editorDelRow(0);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'G':
|
case 'G':
|
||||||
if (deleting) {
|
{
|
||||||
int totlen = 0;
|
int vx = E.cx;
|
||||||
int j;
|
int vy = E.cy;
|
||||||
for (j = E.cy; j < E.numRows; j++)
|
E.cy = E.numRows - 1;
|
||||||
totlen += E.row[j].size + 1;
|
|
||||||
|
|
||||||
char *buf = malloc(totlen);
|
|
||||||
char *p = buf;
|
|
||||||
|
|
||||||
int count = E.numRows - E.cy - 1;
|
|
||||||
if (count < 0) count = 0;
|
|
||||||
while (count >= 0) {
|
|
||||||
memcpy(p, E.row[E.cy].chars, E.row[E.cy].size);
|
|
||||||
p += E.row[E.cy].size;
|
|
||||||
*p = '\r';
|
|
||||||
p++;
|
|
||||||
|
|
||||||
deleting = 1;
|
|
||||||
editorCommandKp('d');
|
|
||||||
count--;
|
|
||||||
}
|
|
||||||
editorUpdatePaste(buf, totlen);
|
|
||||||
} else {
|
|
||||||
if (E.numRows > E.screenRows) {
|
|
||||||
E.cy = E.numRows - 1;
|
|
||||||
E.rowoff = E.numRows - E.screenRows - 1;
|
|
||||||
} else {
|
|
||||||
E.cy = E.numRows - 1;
|
|
||||||
}
|
|
||||||
E.cx = E.row[E.cy].size - 1;
|
E.cx = E.row[E.cy].size - 1;
|
||||||
if (E.cx < 0) E.cx = 0;
|
if (E.cx < 0) E.cx = 0;
|
||||||
|
|
||||||
|
if (!deleting) {
|
||||||
|
if (E.numRows > E.screenRows) E.rowoff = E.numRows - E.screenRows - 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
E.vx = vx;
|
||||||
|
E.vy = vy;
|
||||||
|
editorDeleteSelection();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '\r':
|
case '\r':
|
||||||
|
@ -1247,8 +1242,6 @@ void editorCommandKp(int c) {
|
||||||
counter--;
|
counter--;
|
||||||
if (counter > E.numRows - 1) {
|
if (counter > E.numRows - 1) {
|
||||||
E.cy = E.numRows - 1;
|
E.cy = E.numRows - 1;
|
||||||
} else if (counter < 0) {
|
|
||||||
E.cy = 0;
|
|
||||||
} else {
|
} else {
|
||||||
E.cy = counter;
|
E.cy = counter;
|
||||||
}
|
}
|
||||||
|
@ -1293,19 +1286,21 @@ void editorCommandKp(int c) {
|
||||||
deleting++;
|
deleting++;
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
int sz = E.row[E.cy].size + 1;
|
int start_x = E.cx;
|
||||||
char *buf = malloc(sz);
|
int start_y = E.cy;
|
||||||
strcpy(buf, E.row[E.cy].chars);
|
int end_x, end_y;
|
||||||
buf[sz - 1] = '\r';
|
end_y = E.cy + counter;
|
||||||
editorUpdatePaste(buf, sz);
|
if (end_y >= E.numRows) end_y = E.numRows - 1;
|
||||||
free(buf);
|
end_x = E.row[end_y].size - 1;
|
||||||
|
editorCopyRange(0, start_y, end_x, end_y);
|
||||||
while (counter > 0) {
|
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;
|
||||||
// if (E.cx >= E.row[E.cy].size) E.cx = E.row[E.cy].size;
|
|
||||||
counter--;
|
counter--;
|
||||||
}
|
}
|
||||||
|
E.cx = start_x;
|
||||||
|
if (E.cx >= E.row[E.cy].size) E.cx = E.row[E.cy].size - 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case '$':
|
case '$':
|
||||||
|
@ -1329,26 +1324,23 @@ void editorCommandKp(int c) {
|
||||||
break;
|
break;
|
||||||
case 'w':
|
case 'w':
|
||||||
{
|
{
|
||||||
int start_x = E.cx;
|
int vx = E.cx;
|
||||||
int start_y = E.cy;
|
int vy = E.cy;
|
||||||
while (counter > 0) {
|
while (counter > 0) {
|
||||||
editorNextWord();
|
editorNextWord();
|
||||||
counter--;
|
counter--;
|
||||||
}
|
}
|
||||||
if (!deleting) break;
|
if (!deleting) break;
|
||||||
int end_x, end_y;
|
E.vx = vx;
|
||||||
|
E.vy = vy;
|
||||||
if (E.cx == 0) {
|
if (E.cx == 0) {
|
||||||
if (E.cy == 0) break;
|
if (E.cy == 0) break;
|
||||||
end_y = E.cy - 1;
|
E.cy--;
|
||||||
end_x = E.row[E.cy].size - 1;
|
E.cx = E.row[E.cy].size - 1;
|
||||||
} else {
|
} else {
|
||||||
end_x = E.cx - 1;
|
E.cx--;
|
||||||
end_y = E.cy;
|
|
||||||
}
|
|
||||||
editorCopyRange(start_x, start_y, end_x, end_y);
|
|
||||||
while (E.cx != start_x || E.cy != start_y) {
|
|
||||||
editorDeleteChar();
|
|
||||||
}
|
}
|
||||||
|
editorDeleteSelection();
|
||||||
if (E.cx > E.row[E.cy].size - 1) E.cx = E.row[E.cy].size - 1;
|
if (E.cx > E.row[E.cy].size - 1) E.cx = E.row[E.cy].size - 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -1378,54 +1370,50 @@ void editorCommandKp(int c) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'b':
|
case 'b':
|
||||||
while (counter > 0) {
|
{
|
||||||
if (deleting) {
|
int start_x = E.cx;
|
||||||
int start_x = E.cx;
|
int start_y = E.cy;
|
||||||
int start_y = E.cy;
|
if (start_x > 0) {
|
||||||
editorPrevWord();
|
start_x--;
|
||||||
int end_x = E.cx;
|
} else if (start_y > 0) {
|
||||||
int end_y = E.cy;
|
start_y--;
|
||||||
E.cx = start_x;
|
start_x = E.row[start_y].size - 1;
|
||||||
E.cy = start_y;
|
|
||||||
editorUpdatePaste(&E.row[E.cy].chars[end_x], start_x - end_x);
|
|
||||||
while (E.cy != end_y || E.cx != end_x) {
|
|
||||||
editorDeleteChar();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
editorPrevWord();
|
|
||||||
}
|
}
|
||||||
counter--;
|
while (counter > 0) {
|
||||||
|
editorPrevWord();
|
||||||
|
counter--;
|
||||||
|
}
|
||||||
|
if (!deleting) break;
|
||||||
|
|
||||||
|
E.vx = start_x;
|
||||||
|
E.vy = start_y;
|
||||||
|
editorDeleteSelection();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
while (counter > 0) {
|
{
|
||||||
if (deleting) {
|
int vx = E.cx;
|
||||||
int start_x = E.cx;
|
int vy = E.cy;
|
||||||
int start_y = E.cy;
|
while (counter > 0) {
|
||||||
editorEndOfWord();
|
|
||||||
editorUpdatePaste(&E.row[E.cy].chars[start_x], E.cx - start_x);
|
|
||||||
while (E.cy != start_y || E.cx != start_x) {
|
|
||||||
editorDeleteChar();
|
|
||||||
}
|
|
||||||
E.mode = InputMode;
|
|
||||||
editorMoveCursor(ARROW_RIGHT);
|
|
||||||
editorDeleteChar();
|
|
||||||
E.mode = CommandMode;
|
|
||||||
if (E.cx == E.row[E.cy].size) editorMoveCursor(ARROW_LEFT);
|
|
||||||
} else {
|
|
||||||
editorEndOfWord();
|
editorEndOfWord();
|
||||||
|
counter--;
|
||||||
}
|
}
|
||||||
counter--;
|
if (!deleting) break;
|
||||||
|
E.vx = vx;
|
||||||
|
E.vy = vy;
|
||||||
|
editorDeleteSelection();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '^':
|
case '^':
|
||||||
if (deleting) {
|
{
|
||||||
editorUpdatePaste(&E.row[E.cy].chars[0], E.cx);
|
int vx = E.cx;
|
||||||
while (E.cx > 0) {
|
|
||||||
editorDeleteChar();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
E.cx = 0;
|
E.cx = 0;
|
||||||
|
if (deleting) {
|
||||||
|
E.vx = vx;
|
||||||
|
E.vy = E.cy;
|
||||||
|
if (E.vx > 0) E.vx--;
|
||||||
|
editorDeleteSelection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
|
@ -1437,9 +1425,9 @@ void editorCommandKp(int c) {
|
||||||
break;
|
break;
|
||||||
case 'V':
|
case 'V':
|
||||||
if (E.mode == CommandMode) {
|
if (E.mode == CommandMode) {
|
||||||
E.vx = 0;
|
E.vx = E.row[E.cy].size - 1;
|
||||||
E.vy = E.cy;
|
E.vy = E.cy;
|
||||||
E.cx = E.row[E.cy].size - 1;
|
E.cx = 0;
|
||||||
E.mode = VisualMode;
|
E.mode = VisualMode;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue