bool copy_indent; /* copy the indent level from the previous line on new lines */
uint transid; /* tracks the last used transaction id for log entries */
void (*errfn)(char*); /* callback for error messages */
- size_t nlines;
+ size_t nlines; /* tracks number of lines in the buffer */
+ size_t outpoint; /* tracks the point separating output from input for command buffers */
} Buf;
/* cursor/selection representation */
buf->redo = NULL;
buf->errfn = errfn;
buf->nlines = 0;
+ buf->outpoint = 0;
assert(buf->bufstart);
}
static void delete(Buf* buf, size_t off) {
Rune rune = buf_get(buf, off);
+ if (off < buf->outpoint) buf->outpoint--;
if (rune == RUNE_CRLF || rune == '\n')
buf->nlines--;
syncgap(buf, off);
static size_t insert(Buf* buf, size_t off, Rune rune) {
size_t rcount = 1;
syncgap(buf, off);
+ if (off < buf->outpoint) buf->outpoint++;
if (rune == '\n') buf->nlines++;
if (buf->crlf && rune == '\n' && buf_get(buf, off-1) == '\r') {
rcount = 0;
int CmdFD = -1;
char* ShellCmd[] = { NULL, NULL };
-size_t Point = 0;
static int SearchDir = DOWN;
static char* SearchTerm = NULL;
if (!fdready(CmdFD)) return;
if ((n = read(CmdFD, buf, sizeof(buf))) < 0)
die("read() subprocess :");
-
while (i < n) {
Rune rune = 0;
size_t length = 0;
while (!utf8decode(&rune, &length, buf[i++]));
-// buf_insert(win_buf(EDIT), false, Point++, rune), r++;
- view_insert(win_view(EDIT), false, rune), r++;
+ view_insert(win_view(EDIT), false, rune);
}
-// win_view(EDIT)->selection.beg += r;
-// win_view(EDIT)->selection.end += r;
+ win_buf(EDIT)->outpoint = win_view(EDIT)->selection.end;
}
void onshutdown(void) {
static void oninput(Rune rune) {
view_insert(win_view(FOCUSED), false, rune);
if (win_getregion() == EDIT) {
- Point++;
- size_t bend = win_view(EDIT)->selection.end;
- size_t point = buf_end(win_buf(EDIT)) - Point;
- if (rune == '\n' && bend > point) {
- Sel range = { .beg = point, .end = bend };
+ size_t point = win_buf(EDIT)->outpoint;
+ size_t pos = win_view(EDIT)->selection.end;
+ if (rune == '\n' && pos > point) {
+ Sel range = { .beg = point, .end = pos };
char* str = view_getstr(win_view(EDIT), &range);
write(CmdFD, str, strlen(str)-1);
free(str);
- Point -= (range.end - range.beg);
- } else if (bend <= point) {
- Point--;
}
}
}