Updates file opening for nonexistent files and fixes cursor binding to right edge on line deletion
This commit is contained in:
parent
96d5cf4dc4
commit
c4558d4329
18
hermes.c
18
hermes.c
|
@ -574,7 +574,7 @@ void editorOpen(char *filepath) {
|
|||
|
||||
editorSelectSyntaxHighlight();
|
||||
|
||||
FILE *fp = fopen(filepath, "r");
|
||||
FILE *fp = fopen(filepath, "a+");
|
||||
if (!fp) die("Open file");
|
||||
|
||||
char *line = NULL;
|
||||
|
@ -672,6 +672,16 @@ void editorScroll() {
|
|||
}
|
||||
}
|
||||
|
||||
void editorAdjustCursorX() {
|
||||
erow *row = (E.cy >= E.numRows) ? NULL : &E.row[E.cy];
|
||||
int rowlen = row ? row->size : 0;
|
||||
if (E.cx > rowlen) {
|
||||
E.cx = rowlen;
|
||||
if (E.mode == CommandMode && rowlen > 0) E.cx--;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void editorDrawVisualBg(struct abuf *ab, int end, int drawx, int drawy, int rowlen) {
|
||||
int cond = end ? ((drawx + E.coloff == E.cx || E.cx == rowlen) && drawy == E.cy) :
|
||||
(drawx + E.coloff == E.vx && drawy == E.vy);
|
||||
|
@ -703,8 +713,10 @@ void editorDrawRows(struct abuf *ab) {
|
|||
abAppend(ab, "~", 1);
|
||||
padding--;
|
||||
}
|
||||
if (E.filename == NULL) {
|
||||
while (padding--) abAppend(ab, " ", 1);
|
||||
abAppend(ab, welcome, welcomelen);
|
||||
}
|
||||
} else {
|
||||
abAppend(ab, "~", 1);
|
||||
}
|
||||
|
@ -827,6 +839,7 @@ void editorDrawMsgBar(struct abuf *ab) {
|
|||
}
|
||||
|
||||
void editorRefreshScreen() {
|
||||
editorAdjustCursorX();
|
||||
editorScroll();
|
||||
|
||||
struct abuf ab = ABUF_INIT;
|
||||
|
@ -1271,6 +1284,7 @@ void editorCommandKp(int c) {
|
|||
if (c == 'a') editorMoveCursor('l');
|
||||
break;
|
||||
case 'd':
|
||||
if (E.numRows < 1) break;
|
||||
if (E.mode == VisualMode) {
|
||||
editorDeleteSelection();
|
||||
E.mode = CommandMode;
|
||||
|
@ -1289,7 +1303,7 @@ void editorCommandKp(int c) {
|
|||
editorDelRow(E.cy);
|
||||
if (E.cy == E.numRows) E.cy--;
|
||||
if (E.cy < 0) E.cy = 0;
|
||||
if (E.cx >= E.row[E.cy].size) E.cx = 0;
|
||||
// if (E.cx >= E.row[E.cy].size) E.cx = E.row[E.cy].size;
|
||||
counter--;
|
||||
}
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue