16 Image *textcols[NCOL];
17 static Rune Ldot[] = { '.', 0 };
20 TABDIR = 3 /* width of tabs in directory windows */
24 textinit(Text *t, File *f, Rectangle r, Reffont *rf, Image *cols[NCOL])
29 t->scrollr.max.x = r.min.x+Scrollwid;
31 r.min.x += Scrollwid+Scrollgap;
36 memmove(t->fr.cols, cols, sizeof t->fr.cols);
37 textredraw(t, r, rf->f, screen, -1);
41 textredraw(Text *t, Rectangle r, Font *f, Image *b, int odx)
46 frinit(&t->fr, r, f, b, t->fr.cols);
48 rr.min.x -= Scrollwid; /* back fill to scroll bar */
49 draw(t->fr.b, rr, t->fr.cols[BACK], nil, ZP);
50 /* use no wider than 3-space tabs in a directory */
54 maxt = min(TABDIR, maxtab);
58 t->fr.maxtab = maxt*stringwidth(f, "0");
59 if(t->what==Body && t->w->isdir && odx!=Dx(t->all)){
60 if(t->fr.maxlines > 0){
62 textcolumnate(t, t->w->dlp, t->w->ndl);
67 textsetselect(t, t->q0, t->q1);
72 textresize(Text *t, Rectangle r)
77 r.max.y -= Dy(r)%t->fr.font->height;
83 t->scrollr.max.x = r.min.x+Scrollwid;
85 r.min.x += Scrollwid+Scrollgap;
87 textredraw(t, r, t->fr.font, screen, odx);
96 filedeltext(t->file, t);
112 dircmp(const void *a, const void *b)
119 n = min(da->nr, db->nr);
120 i = memcmp(da->r, db->r, n*sizeof(Rune));
123 return da->nr - db->nr;
127 textcolumnate(Text *t, Dirlist **dlp, int ndl)
129 int i, j, w, colw, mint, maxt, ncol, nrow;
132 static Rune Lnl[] = { '\n', 0 };
133 static Rune Ltab[] = { '\t', 0 };
135 if(t->file->ntext > 1)
137 mint = stringwidth(t->fr.font, "0");
138 /* go for narrower tabs if set more than 3 wide */
139 t->fr.maxtab = min(maxtab, TABDIR)*mint;
142 for(i=0; i<ndl; i++){
145 if(maxt-w%maxt < mint || w%maxt==0)
155 ncol = max(1, Dx(t->fr.r)/colw);
156 nrow = (ndl+ncol-1)/ncol;
159 for(i=0; i<nrow; i++){
160 for(j=i; j<ndl; j+=nrow){
162 fileinsert(t->file, q1, dl->r, dl->nr);
167 if(maxt-w%maxt < mint){
168 fileinsert(t->file, q1, Ltab, 1);
173 fileinsert(t->file, q1, Ltab, 1);
178 fileinsert(t->file, q1, Lnl, 1);
184 textload(Text *t, uint q0, char *file, int setqid)
188 int fd, i, j, n, ndl, nulls;
194 if(t->ncache!=0 || t->file->b.nc || t->w==nil || t!=&t->w->body || (t->w->isdir && t->file->nname==0))
196 fd = open(file, OREAD);
198 warning(nil, "can't open %s: %r\n", file);
203 warning(nil, "can't fstat %s: %r\n", file);
207 if(d->qid.type & QTDIR){
208 /* this is checked in get() but it's possible the file changed underfoot */
209 if(t->file->ntext > 1){
210 warning(nil, "%s is a directory; can't read with multiple windows on it\n", file);
214 t->w->filemenu = FALSE;
215 if(t->file->name[t->file->nname-1] != '/'){
216 rp = runemalloc(t->file->nname+1);
217 runemove(rp, t->file->name, t->file->nname);
218 rp[t->file->nname] = '/';
219 winsetname(t->w, rp, t->file->nname+1);
225 while((n=dirread(fd, &dbuf)) > 0){
227 dl = emalloc(sizeof(Dirlist));
228 j = strlen(dbuf[i].name);
229 tmp = emalloc(j+1+1);
230 memmove(tmp, dbuf[i].name, j);
231 if(dbuf[i].qid.type & QTDIR)
234 dl->r = bytetorune(tmp, &dl->nr);
235 dl->wid = stringwidth(t->fr.font, tmp);
238 dlp = realloc(dlp, ndl*sizeof(Dirlist*));
243 qsort(dlp, ndl, sizeof(Dirlist*), dircmp);
246 textcolumnate(t, dlp, ndl);
250 t->w->filemenu = TRUE;
251 q1 = q0 + fileload(t->file, q0, fd, &nulls);
254 t->file->dev = d->dev;
255 t->file->mtime = d->mtime;
256 t->file->qidpath = d->qid.path;
260 for(q=q0; q<q1; q+=n){
264 bufread(&t->file->b, q, rp, n);
267 else if(q <= t->org+t->fr.nchars)
268 frinsert(&t->fr, rp, rp+n, q-t->org);
269 if(t->fr.lastlinefull)
273 for(i=0; i<t->file->ntext; i++){
274 u = t->file->text[i];
276 if(u->org > u->file->b.nc) /* will be 0 because of reset(), but safety first */
278 textresize(u, u->all);
279 textbacknl(u, u->org, 0); /* go to beginning of line */
281 textsetselect(u, q0, q0);
284 warning(nil, "%s: NUL bytes elided\n", file);
294 textbsinsert(Text *t, uint q0, Rune *r, uint n, int tofile, int *nrp)
299 if(t->what == Tag){ /* can't happen but safety first: mustn't backspace over file name */
301 textinsert(t, q0, r, n, tofile);
327 textdelete(t, q0, q0+initial, tofile);
330 textinsert(t, q0, tp, n, tofile);
339 textinsert(Text *t, uint q0, Rune *r, uint n, int tofile)
344 if(tofile && t->ncache != 0)
345 error("text.insert");
349 fileinsert(t->file, q0, r, n);
352 t->w->utflastqid = -1;
354 if(t->file->ntext > 1)
355 for(i=0; i<t->file->ntext; i++){
356 u = t->file->text[i];
358 u->w->dirty = TRUE; /* always a body */
359 textinsert(u, q0, r, n, FALSE);
360 textsetselect(u, u->q0, u->q1);
372 else if(q0 <= t->org+t->fr.nchars)
373 frinsert(&t->fr, r, r+n, q0-t->org);
379 winevent(t->w, "%c%d %d 0 %d %.*S\n", c, q0, q0+n, n, n, r);
381 winevent(t->w, "%c%d %d 0 0 \n", c, q0, q0+n, n);
392 if(t->fr.lastlinefull || t->nofill)
402 n = t->file->b.nc-(t->org+t->fr.nchars);
405 if(n > 2000) /* educated guess at reasonable amount */
407 bufread(&t->file->b, t->org+t->fr.nchars, rp, n);
409 * it's expensive to frinsert more than we need, so
412 nl = t->fr.maxlines-t->fr.nlines;
421 frinsert(&t->fr, rp, rp+i, t->fr.nchars);
422 }while(t->fr.lastlinefull == FALSE);
427 textdelete(Text *t, uint q0, uint q1, int tofile)
433 if(tofile && t->ncache != 0)
434 error("text.delete");
439 filedelete(t->file, q0, q1);
442 t->w->utflastqid = -1;
444 if(t->file->ntext > 1)
445 for(i=0; i<t->file->ntext; i++){
446 u = t->file->text[i];
448 u->w->dirty = TRUE; /* always a body */
449 textdelete(u, q0, q1, FALSE);
450 textsetselect(u, u->q0, u->q1);
456 t->q0 -= min(n, t->q0-q0);
458 t->q1 -= min(n, t->q1-q0);
461 else if(q0 < t->org+t->fr.nchars){
463 if(p1 > t->fr.nchars)
470 frdelete(&t->fr, p0, p1);
477 winevent(t->w, "%c%d %d 0 0 \n", c, q0, q1);
482 textconstrain(Text *t, uint q0, uint q1, uint *p0, uint *p1)
484 *p0 = min(q0, t->file->b.nc);
485 *p1 = min(q1, t->file->b.nc);
489 textreadc(Text *t, uint q)
493 if(t->cq0<=q && q<t->cq0+t->ncache)
494 r = t->cache[q-t->cq0];
496 bufread(&t->file->b, q, &r, 1);
501 textbswidth(Text *t, Rune c)
507 /* there is known to be at least one character to erase */
508 if(c == 0x08) /* ^H: erase character */
513 r = textreadc(t, q-1);
514 if(r == '\n'){ /* eat at most one more character */
515 if(q == t->q0) /* eat the newline */
521 if(eq && skipping) /* found one; stop skipping */
523 else if(!eq && !skipping)
532 textfilewidth(Text *t, uint q0, int oneelement)
539 r = textreadc(t, q-1);
542 if(oneelement && r=='/')
550 textcomplete(Text *t)
561 /* control-f: filename completion; works back to white space or / */
562 if(t->q0<t->file->b.nc && textreadc(t, t->q0)>' ') /* must be at end of word */
564 nstr = textfilewidth(t, t->q0, TRUE);
565 str = runemalloc(nstr);
566 npath = textfilewidth(t, t->q0-nstr, FALSE);
567 path = runemalloc(npath);
574 for(i=0; i<nstr; i++)
575 str[i] = textreadc(t, q++);
576 q = t->q0-nstr-npath;
577 for(i=0; i<npath; i++)
578 path[i] = textreadc(t, q++);
579 /* is path rooted? if not, we need to make it relative to window path */
580 if(npath>0 && path[0]=='/')
581 dir = runestr(path, npath);
583 dir = dirname(t, nil, 0);
584 if(dir.nr + 1 + npath > nelem(tmp)){
590 dir.r = runestrdup(Ldot);
592 runemove(tmp, dir.r, dir.nr);
594 runemove(tmp+dir.nr+1, path, npath);
598 dir = cleanrname(dir);
601 s = smprint("%.*S", nstr, str);
602 dirs = smprint("%.*S", dir.nr, dir.r);
603 c = complete(dirs, s);
606 warning(nil, "error attempting completion: %r\n");
611 warning(nil, "%.*S%s%.*S*%s\n",
613 dir.nr>0 && dir.r[dir.nr-1]!='/' ? "/" : "",
615 c->nmatch ? "" : ": no matches in:");
616 for(i=0; i<c->nfile; i++)
617 warning(nil, " %s\n", c->filename[i]);
621 rp = runesmprint("%s", c->string);
633 texttype(Text *t, Rune r)
641 if(t->what!=Body && r=='\n')
649 textshow(t, t->q0-1, t->q0-1, TRUE);
653 if(t->q1 < t->file->b.nc){
655 textshow(t, t->q1+1, t->q1+1, TRUE);
659 n = t->fr.maxlines/3;
662 n = mousescrollsize(t->fr.maxlines);
667 n = 2*t->fr.maxlines/3;
669 q0 = t->org+frcharofpt(&t->fr, Pt(t->fr.r.min.x, t->fr.r.min.y+n*t->fr.font->height));
670 textsetorigin(t, q0, TRUE);
673 n = t->fr.maxlines/3;
676 n = mousescrollsize(t->fr.maxlines);
679 n = 2*t->fr.maxlines/3;
681 q0 = textbacknl(t, t->org, n);
682 textsetorigin(t, q0, TRUE);
685 textshow(t, 0, 0, FALSE);
692 textshow(t, t->file->b.nc, t->file->b.nc, FALSE);
702 cut(t, t, nil, TRUE, TRUE, nil, 0);
705 textshow(t, t->q0, t->q0, 1);
707 case 0x06: /* ^F: complete */
709 rp = textcomplete(t);
713 break; /* fall through to normal insertion case */
716 textsetselect(t, t->eq0, t->q0);
724 case 0x08: /* ^H: erase character */
725 case 0x15: /* ^U: erase line */
726 case 0x17: /* ^W: erase word */
727 if(t->q0 == 0) /* nothing to erase */
729 nnb = textbswidth(t, r);
732 /* if selection is at beginning of window, avoid deleting invisible text */
739 for(i=0; i<t->file->ntext; i++){
740 u = t->file->text[i];
746 error("text.type backspace");
750 textdelete(u, q1-n, q1, FALSE);
753 if(u->eq0==q1 || u->eq0==~0)
756 textdelete(u, q0, q0+nb, TRUE);
758 textsetselect(u, u->q0, u->q1);
760 textsetselect(t, q0, q0);
763 for(i=0; i<t->file->ntext; i++)
764 textfill(t->file->text[i]);
767 if(t->w->autoindent){
768 /* find beginning of previous line using backspace code */
769 nnb = textbswidth(t, 0x15); /* ^U case */
770 rp = runemalloc(nnb + 1);
773 for(i=0; i<nnb; i++){
774 r = textreadc(t, t->q0-nnb+i);
775 if(r != ' ' && r != '\t')
780 break; /* fall through to normal code */
782 /* otherwise ordinary character; just insert, typically in caches of all texts */
783 for(i=0; i<t->file->ntext; i++){
784 u = t->file->text[i];
789 else if(t->q0 != u->cq0+u->ncache)
790 error("text.type cq1");
791 textinsert(u, t->q0, rp, nr, FALSE);
793 textsetselect(u, u->q0, u->q1);
794 if(u->ncache+nr > u->ncachealloc){
795 u->ncachealloc += 10 + nr;
796 u->cache = runerealloc(u->cache, u->ncachealloc);
798 runemove(u->cache+u->ncache, rp, nr);
803 textsetselect(t, t->q0+nr, t->q0+nr);
804 if(r=='\n' && t->w!=nil)
809 textcommit(Text *t, int tofile)
814 fileinsert(t->file, t->cq0, t->cache, t->ncache);
817 t->w->utflastqid = -1;
822 static Text *clicktext;
823 static uint clickmsec;
824 static Text *selecttext;
828 * called from frame library
831 framescroll(Frame *f, int dl)
833 if(f != &selecttext->fr)
834 error("frameselect not right frame");
835 textframescroll(selecttext, dl);
839 textframescroll(Text *t, int dl)
848 q0 = textbacknl(t, t->org, -dl);
849 if(selectq > t->org+t->fr.p0)
850 textsetselect(t, t->org+t->fr.p0, selectq);
852 textsetselect(t, selectq, t->org+t->fr.p0);
854 if(t->org+t->fr.nchars == t->file->b.nc)
856 q0 = t->org+frcharofpt(&t->fr, Pt(t->fr.r.min.x, t->fr.r.min.y+dl*t->fr.font->height));
857 if(selectq > t->org+t->fr.p1)
858 textsetselect(t, t->org+t->fr.p1, selectq);
860 textsetselect(t, selectq, t->org+t->fr.p1);
862 textsetorigin(t, q0, TRUE);
875 * To have double-clicking and chording, we double-click
876 * immediately if it might make sense.
881 selectq = t->org+frcharofpt(&t->fr, mouse->xy);
882 if(clicktext==t && mouse->msec-clickmsec<500)
883 if(q0==q1 && selectq==q0){
884 textdoubleclick(t, &q0, &q1);
885 textsetselect(t, q0, q1);
886 flushimage(display, 1);
889 /* stay here until something interesting happens */
892 while(mouse->buttons==b && abs(mouse->xy.x-x)<3 && abs(mouse->xy.y-y)<3);
893 mouse->xy.x = x; /* in case we're calling frselect */
895 q0 = t->q0; /* may have changed */
899 if(mouse->buttons == b){
900 t->fr.scroll = framescroll;
901 frselect(&t->fr, mousectl);
902 /* horrible botch: while asleep, may have lost selection altogether */
903 if(selectq > t->file->b.nc)
904 selectq = t->org + t->fr.p0;
909 q0 = t->org + t->fr.p0;
910 if(selectq > t->org+t->fr.nchars)
913 q1 = t->org+t->fr.p1;
916 if(q0==t->q0 && clicktext==t && mouse->msec-clickmsec<500){
917 textdoubleclick(t, &q0, &q1);
921 clickmsec = mouse->msec;
925 textsetselect(t, q0, q1);
926 flushimage(display, 1);
927 state = op = 0; /* undo when possible; +1 for cut, -1 for paste */
928 while(mouse->buttons){
932 if(state==0 && op==0 && t->what==Body){
934 filemark(t->w->body.file);
937 if(state==-1 && t->what==Body){
939 textsetselect(t, q0, t->q0);
941 }else if(state != 1 && op != -1){
942 cut(t, t, nil, TRUE, TRUE, nil, 0);
946 if(state==1 && t->what==Body){
948 textsetselect(t, q0, t->q1);
950 }else if(state != -1 && op != 1){
951 paste(t, t, nil, TRUE, FALSE, nil, 0);
958 flushimage(display, 1);
959 while(mouse->buttons == b)
966 textshow(Text *t, uint q0, uint q1, int doselect)
974 textsetselect(t, q0, q1);
977 if(t->w!=nil && t->fr.maxlines==0)
978 colgrow(t->col, t->w, 1);
980 textsetselect(t, q0, q1);
981 qe = t->org+t->fr.nchars;
982 if(t->org<=q0 && (q0<qe || (q0==qe && qe==t->file->b.nc+t->ncache)))
985 if(t->w->nopen[QWevent] > 0)
986 nl = 3*t->fr.maxlines/4;
988 nl = t->fr.maxlines/4;
989 q = textbacknl(t, q0, nl);
990 /* avoid going backwards if trying to go forwards - long lines! */
991 if(!(q0>t->org && q<t->org))
992 textsetorigin(t, q, TRUE);
993 while(q0 > t->org+t->fr.nchars)
994 textsetorigin(t, t->org+1, FALSE);
1000 region(int a, int b)
1010 selrestore(Frame *f, Point pt0, uint p0, uint p1)
1012 if(p1<=f->p0 || p0>=f->p1){
1014 frdrawsel0(f, pt0, p0, p1, f->cols[BACK], f->cols[TEXT]);
1017 if(p0>=f->p0 && p1<=f->p1){
1018 /* entirely inside */
1019 frdrawsel0(f, pt0, p0, p1, f->cols[HIGH], f->cols[HTEXT]);
1023 /* they now are known to overlap */
1025 /* before selection */
1027 frdrawsel0(f, pt0, p0, f->p0, f->cols[BACK], f->cols[TEXT]);
1029 pt0 = frptofchar(f, p0);
1031 /* after selection */
1033 frdrawsel0(f, frptofchar(f, f->p1), f->p1, p1, f->cols[BACK], f->cols[TEXT]);
1036 /* inside selection */
1037 frdrawsel0(f, pt0, p0, p1, f->cols[HIGH], f->cols[HTEXT]);
1041 textsetselect(Text *t, uint q0, uint q1)
1045 /* t->fr.p0 and t->fr.p1 are always right; t->q0 and t->q1 may be off */
1048 /* compute desired p0,p1 from q0,q1 */
1055 if(p0 > t->fr.nchars)
1057 if(p1 > t->fr.nchars)
1059 if(p0==t->fr.p0 && p1==t->fr.p1)
1061 /* screen disagrees with desired selection */
1062 if(t->fr.p1<=p0 || p1<=t->fr.p0 || p0==p1 || t->fr.p1==t->fr.p0){
1063 /* no overlap or too easy to bother trying */
1064 frdrawsel(&t->fr, frptofchar(&t->fr, t->fr.p0), t->fr.p0, t->fr.p1, 0);
1065 frdrawsel(&t->fr, frptofchar(&t->fr, p0), p0, p1, 1);
1068 /* overlap; avoid unnecessary painting */
1070 /* extend selection backwards */
1071 frdrawsel(&t->fr, frptofchar(&t->fr, p0), p0, t->fr.p0, 1);
1072 }else if(p0 > t->fr.p0){
1073 /* trim first part of selection */
1074 frdrawsel(&t->fr, frptofchar(&t->fr, t->fr.p0), t->fr.p0, p0, 0);
1077 /* extend selection forwards */
1078 frdrawsel(&t->fr, frptofchar(&t->fr, t->fr.p1), t->fr.p1, p1, 1);
1079 }else if(p1 < t->fr.p1){
1080 /* trim last part of selection */
1081 frdrawsel(&t->fr, frptofchar(&t->fr, p1), p1, t->fr.p1, 0);
1090 * Release the button in less than DELAY ms and it's considered a null selection
1091 * if the mouse hardly moved, regardless of whether it crossed a char boundary.
1099 xselect(Frame *f, Mousectl *mc, Image *col, uint *p1p) /* when called, button is down */
1101 uint p0, p1, q, tmp;
1103 Point mp, pt0, pt1, qt;
1112 frtick(f, frptofchar(f, f->p0), 0);
1113 p0 = p1 = frcharofpt(f, mp);
1114 pt0 = frptofchar(f, p0);
1115 pt1 = frptofchar(f, p1);
1119 q = frcharofpt(f, mc->m.xy);
1123 if(reg != region(q, p0)){ /* crossed starting point; reset */
1125 selrestore(f, pt0, p0, p1);
1127 selrestore(f, pt1, p1, p0);
1130 reg = region(q, p0);
1132 frdrawsel0(f, pt0, p0, p1, col, display->white);
1134 qt = frptofchar(f, q);
1137 frdrawsel0(f, pt1, p1, q, col, display->white);
1140 selrestore(f, qt, q, p1);
1143 selrestore(f, pt1, p1, q);
1145 frdrawsel0(f, qt, q, p1, col, display->white);
1152 flushimage(f->display, 1);
1154 }while(mc->m.buttons == b);
1155 if(mc->m.msec-msec < DELAY && p0!=p1
1156 && abs(mp.x-mc->m.xy.x)<MINMOVE
1157 && abs(mp.y-mc->m.xy.y)<MINMOVE) {
1159 selrestore(f, pt0, p0, p1);
1161 selrestore(f, pt1, p1, p0);
1169 pt0 = frptofchar(f, p0);
1172 selrestore(f, pt0, p0, p1);
1175 frtick(f, frptofchar(f, f->p0), 1);
1176 flushimage(f->display, 1);
1182 textselect23(Text *t, uint *q0, uint *q1, Image *high, int mask)
1187 p0 = xselect(&t->fr, mousectl, high, &p1);
1188 buts = mousectl->m.buttons;
1189 if((buts & mask) == 0){
1194 while(mousectl->m.buttons)
1195 readmouse(mousectl);
1200 textselect2(Text *t, uint *q0, uint *q1, Text **tp)
1205 buts = textselect23(t, q0, q1, but2col, 4);
1208 if(buts & 1){ /* pick up argument */
1216 textselect3(Text *t, uint *q0, uint *q1)
1220 h = (textselect23(t, q0, q1, but3col, 1|2) == 0);
1224 static Rune left1[] = { '{', '[', '(', '<', 0xab, 0 };
1225 static Rune right1[] = { '}', ']', ')', '>', 0xbb, 0 };
1226 static Rune left2[] = { '\n', 0 };
1227 static Rune left3[] = { '\'', '"', '`', 0 };
1245 textdoubleclick(Text *t, uint *q0, uint *q1)
1251 for(i=0; left[i]!=nil; i++){
1255 /* try matching character to left, looking right */
1259 c = textreadc(t, q-1);
1260 p = runestrchr(l, c);
1262 if(textclickmatch(t, c, r[p-l], 1, &q))
1266 /* try matching character to right, looking left */
1267 if(q == t->file->b.nc)
1270 c = textreadc(t, q);
1271 p = runestrchr(r, c);
1273 if(textclickmatch(t, c, l[p-r], -1, &q)){
1274 *q1 = *q0+(*q0<t->file->b.nc && c=='\n');
1276 if(c!='\n' || q!=0 || textreadc(t, 0)=='\n')
1282 /* try filling out word to right */
1283 while(*q1<t->file->b.nc && isalnum(textreadc(t, *q1)))
1285 /* try filling out word to left */
1286 while(*q0>0 && isalnum(textreadc(t, *q0-1)))
1291 textclickmatch(Text *t, int cl, int cr, int dir, uint *q)
1299 if(*q == t->file->b.nc)
1301 c = textreadc(t, *q);
1307 c = textreadc(t, *q);
1315 return cl=='\n' && nest==1;
1319 textbacknl(Text *t, uint p, uint n)
1323 /* look for start of this line if n==0 */
1324 if(n==0 && p>0 && textreadc(t, p-1)!='\n')
1327 while(i-->0 && p>0){
1328 --p; /* it's at a newline now; back over it */
1331 /* at 128 chars, call it a line anyway */
1332 for(j=128; --j>0 && p>0; p--)
1333 if(textreadc(t, p-1)=='\n')
1340 textsetorigin(Text *t, uint org, int exact)
1346 if(org>0 && !exact){
1347 /* org is an estimate of the char posn; find a newline */
1348 /* don't try harder than 256 chars */
1349 for(i=0; i<256 && org<t->file->b.nc; i++){
1350 if(textreadc(t, org) == '\n'){
1359 if(a>=0 && a<t->fr.nchars){
1360 frdelete(&t->fr, 0, a);
1361 fixup = 1; /* frdelete can leave end of last line in wrong selection mode; it doesn't know what follows */
1363 else if(a<0 && -a<t->fr.nchars){
1366 bufread(&t->file->b, org, r, n);
1367 frinsert(&t->fr, r, r+n, 0);
1370 frdelete(&t->fr, 0, t->fr.nchars);
1374 textsetselect(t, t->q0, t->q1);
1375 if(fixup && t->fr.p1 > t->fr.p0)
1376 frdrawsel(&t->fr, frptofchar(&t->fr, t->fr.p1-1), t->fr.p1-1, t->fr.p1, 1);
1384 /* do t->delete(0, t->nc, TRUE) without building backup stuff */
1385 textsetselect(t, t->org, t->org);
1386 frdelete(&t->fr, 0, t->fr.nchars);
1391 bufreset(&t->file->b);