Sorry for double positing but I got everything working except the KEY_END case in the switch statement. In KEY_END the e.cx variable (cursor X position) is way off the screen.
I'll post the new relevant code here...
Code:
case KEY_END:
startx = editor_getoffset(&e, e.cy + e.skiprows);
endx = editor_getoffset(&e, (e.cy + e.skiprows) + 1);
if(e.cx < (e.cols - 1) &&
(e.cx + e.skipcols) < (endx - startx)) {
int len = (endx - startx);
int skipcols = (len - 1) / e.cols;
e.skipcols = (len >= e.cols ? skipcols: 0);
// Problem with the line below.
e.cx = len > 0 ? (len - 1) + skipcols : 0;
e.dirty = true;
}
break;