diff --git a/hermes.c b/hermes.c index 2a18d72..150a83b 100644 --- a/hermes.c +++ b/hermes.c @@ -698,8 +698,10 @@ void editorDrawRows(struct abuf *ab) { unsigned char *hl = &E.row[filerow].hl[E.coloff]; int current_color = -1; if (E.mode == VisualMode && len <= 0 && filerow == E.cy) { + int col = EDITOR_BG_COLOR; + if (E.cy < E.vy || (E.cx < E.vx && E.cy == E.vy)) col = VISUAL_BG_COLOR; char vbuf[16]; - int vclen = snprintf(vbuf, sizeof(vbuf), "\033[48;5;%dm", EDITOR_BG_COLOR); + int vclen = snprintf(vbuf, sizeof(vbuf), "\033[48;5;%dm", col); abAppend(ab, vbuf, vclen); } int j; @@ -726,14 +728,18 @@ void editorDrawRows(struct abuf *ab) { current_color = -1; } if (E.mode == VisualMode && j + E.coloff == E.vx && filerow == E.vy) { + int col = VISUAL_BG_COLOR; + if (E.cy < E.vy || (E.cx < E.vx && E.cy == E.vy)) col = EDITOR_BG_COLOR; char vbuf[16]; - int vclen = snprintf(vbuf, sizeof(vbuf), "\033[48;5;%dm", VISUAL_BG_COLOR); + int vclen = snprintf(vbuf, sizeof(vbuf), "\033[48;5;%dm", col); abAppend(ab, vbuf, vclen); } abAppend(ab, &c[j], 1); if (E.mode == VisualMode && (j + E.coloff == E.cx || E.cx == len || !filerow) && filerow == E.cy) { + int col = EDITOR_BG_COLOR; + if (E.cy < E.vy || (E.cx < E.vx && E.cy == E.vy)) col = VISUAL_BG_COLOR; char vbuf[16]; - int vclen = snprintf(vbuf, sizeof(vbuf), "\033[48;5;%dm", EDITOR_BG_COLOR); + int vclen = snprintf(vbuf, sizeof(vbuf), "\033[48;5;%dm", col); abAppend(ab, vbuf, vclen); } } else { @@ -745,14 +751,18 @@ void editorDrawRows(struct abuf *ab) { abAppend(ab, buf, clen); } if (E.mode == VisualMode && j + E.coloff == E.vx && filerow == E.vy) { + int col = VISUAL_BG_COLOR; + if (E.cy < E.vy || (E.cx < E.vx && E.cy == E.vy)) col = EDITOR_BG_COLOR; char vbuf[16]; - int vclen = snprintf(vbuf, sizeof(vbuf), "\033[48;5;%dm", VISUAL_BG_COLOR); + int vclen = snprintf(vbuf, sizeof(vbuf), "\033[48;5;%dm", col); abAppend(ab, vbuf, vclen); } abAppend(ab, &c[j], 1); if (E.mode == VisualMode && (j + E.coloff == E.cx || E.cx == len || !filerow) && filerow == E.cy) { + int col = EDITOR_BG_COLOR; + if (E.cy < E.vy || (E.cx < E.vx && E.cy == E.vy)) col = VISUAL_BG_COLOR; char vbuf[16]; - int vclen = snprintf(vbuf, sizeof(vbuf), "\033[48;5;%dm", EDITOR_BG_COLOR); + int vclen = snprintf(vbuf, sizeof(vbuf), "\033[48;5;%dm", col); abAppend(ab, vbuf, vclen); } } @@ -895,6 +905,27 @@ void editorNextWord() { } } +void editorDeleteSelection() { + int sx = E.cx; + int sy = E.cy; + int ex = E.vx; + int ey = E.vy; + if (E.cy < E.vy || (E.cx < E.vx && E.cy == E.vy)) { + sx = E.vx; + sy = E.vy; + ex = E.cx; + ey = E.cy; + E.cx = sx; + E.cy = sy; + } + + if (sx < E.row[sy].size) + E.cx++; + while (E.cx != ex || E.cy != ey) { + editorDeleteChar(); + } +} + void editorEndOfWord() { int x = E.cx; int y = E.cy; @@ -1175,8 +1206,14 @@ void editorCommandKp(int c) { break; case 'd': if (!deleting) { - deleting++; - return; + if (E.mode == VisualMode) { + editorDeleteSelection(); + E.mode = CommandMode; + break; + } else { + deleting++; + return; + } } else { int sz = E.row[E.cy].size + 1; char *buf = malloc(sz);