Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
10e3427740 | ||
|
|
779b0808e0 |
@@ -342,14 +342,25 @@ void editorRefreshScreen() {
|
|||||||
/*** input ***/
|
/*** input ***/
|
||||||
|
|
||||||
void editorMoveCursor(int key) {
|
void editorMoveCursor(int key) {
|
||||||
|
// Cursor can be one past the end of the file.
|
||||||
|
erow *row= (E.cy >= E.numrows) ? NULL : &E.row[E.cy];
|
||||||
|
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case ARROW_LEFT:
|
case ARROW_LEFT:
|
||||||
if (E.cx != 0) {
|
if (E.cx != 0) {
|
||||||
E.cx--;
|
E.cx--;
|
||||||
|
} else if (E.cy > 0) { // Go to previous line on left at start.
|
||||||
|
E.cy--;
|
||||||
|
E.cx = E.row[E.cy].size;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ARROW_RIGHT:
|
case ARROW_RIGHT:
|
||||||
E.cx++;
|
if (row && E.cx < row->size) {
|
||||||
|
E.cx++;
|
||||||
|
} else if (row && E.cx == row->size) { // Go to next line on right at end.
|
||||||
|
E.cy++;
|
||||||
|
E.cx = 0;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case ARROW_UP:
|
case ARROW_UP:
|
||||||
if (E.cy != 0) {
|
if (E.cy != 0) {
|
||||||
@@ -362,6 +373,13 @@ void editorMoveCursor(int key) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cursor could have moved past the end as a result of the scroll action.
|
||||||
|
row = (E.cy >= E.numrows) ? NULL : &E.row[E.cy];
|
||||||
|
int rowlen = row ? row->size : 0;
|
||||||
|
if (E.cx > rowlen) {
|
||||||
|
E.cx = rowlen;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void editorProcessKeypress() {
|
void editorProcessKeypress() {
|
||||||
|
|||||||
Reference in New Issue
Block a user