void cmdscroll(Win *w, int l) { int r; if(l == 0) return; if(l > 0){ for(r = w->toprune; r < w->nrunes && l != 0; r++) if(w->runes[r] == '\n') l--; w->toprune = r; }else{ for(r = w->toprune; r > 0; r--) if(w->runes[r] == '\n' && ++l == 0){ r++; break; } w->toprune = r; } frdelete(&w->fr, 0, w->fr.nchars); frinsert(&w->fr, w->runes + w->toprune, w->runes + w->nrunes, 0); scrollbar(w); }
void textdelete(Text *t, uint q0, uint q1) { uint n, p0, p1; n = q1-q0; if(n == 0) return; runemove(t->rs.r+q0, t->rs.r+q1, t->rs.nr-q1); t->rs.nr -= n; if(q0 < t->q0) t->q0 -= min(n, t->q0-q0); if(q0 < t->q1) t->q1 -= min(n, t->q1-q0); if(q1 <= t->org) t->org -= n; else if(q0 < t->org+t->nchars){ p1 = q1 - t->org; if(p1 > t->nchars) p1 = t->nchars; if(q0 < t->org){ t->org = q0; p0 = 0; }else p0 = q0 - t->org; frdelete(t, p0, p1); textfill(t); } t->rs.r[t->rs.nr] = L'\0'; }
void textdelete(Text *t, uint q0, uint q1, int tofile) { uint n, p0, p1; int i, c; Text *u; if(tofile && t->ncache != 0) error("text.delete"); n = q1-q0; if(n == 0) return; if(tofile){ filedelete(t->file, q0, q1); if(t->what == Body){ t->w->dirty = TRUE; t->w->utflastqid = -1; } if(t->file->ntext > 1) for(i=0; i<t->file->ntext; i++){ u = t->file->text[i]; if(u != t){ u->w->dirty = TRUE; /* always a body */ textdelete(u, q0, q1, FALSE); textsetselect(u, u->q0, u->q1); textscrdraw(u); } } } if(q0 < t->iq1) t->iq1 -= min(n, t->iq1-q0); if(q0 < t->q0) t->q0 -= min(n, t->q0-q0); if(q0 < t->q1) t->q1 -= min(n, t->q1-q0); if(q1 <= t->org) t->org -= n; else if(q0 < t->org+t->fr.nchars){ p1 = q1 - t->org; if(p1 > t->fr.nchars) p1 = t->fr.nchars; if(q0 < t->org){ t->org = q0; p0 = 0; }else p0 = q0 - t->org; frdelete(&t->fr, p0, p1); textfill(t); } if(t->w){ c = 'd'; if(t->what == Body) c = 'D'; winevent(t->w, "%c%d %d 0 0 \n", c, q0, q1); } }
void textsetorigin(Text *t, uint org, int exact) { int i, a, fixup; Rune *r; uint n; if(org>0 && !exact){ /* org is an estimate of the char posn; find a newline */ /* don't try harder than 256 chars */ for(i=0; i<256 && org<t->file->nc; i++){ if(textreadc(t, org) == '\n'){ org++; break; } org++; } } a = org-t->org; fixup = 0; if(a>=0 && a<t->nchars){ frdelete(t, 0, a); fixup = 1; /* frdelete can leave end of last line in wrong selection mode; it doesn't know what follows */ } else if(a<0 && -a<t->nchars){ n = t->org - org; r = runemalloc(n); bufread(t->file, org, r, n); frinsert(t, r, r+n, 0); free(r); }else frdelete(t, 0, t->nchars); t->org = org; textfill(t); textscrdraw(t); textsetselect(t, t->q0, t->q1); if(fixup && t->p1 > t->p0) frdrawsel(t, frptofchar(t, t->p1-1), t->p1-1, t->p1, 1); }
void textreset(Text *t) { t->file->seq = 0; t->eq0 = ~0; /* do t->delete(0, t->nc, TRUE) without building backup stuff */ textsetselect(t, t->org, t->org); frdelete(t, 0, t->nchars); t->org = 0; t->q0 = 0; t->q1 = 0; filereset(t->file); bufreset(t->file); }
static void cmddel(Win *w, int a, int b) { if(a >= b) return; memmove(w->runes + a, w->runes + b, w->nrunes - b); w->nrunes -= b - a; if(w->toprune >= b) w->toprune -= b - a; else{ frdelete(&w->fr, a - w->toprune, b - w->toprune); if(w->toprune >= a) w->toprune = a; } if(a <= w->opoint && w->opoint < b) w->opoint = a; else if(w->opoint >= b) w->opoint -= b - a; }