diff options
Diffstat (limited to 'src/cmd/samterm')
-rw-r--r-- | src/cmd/samterm/main.c | 78 | ||||
-rw-r--r-- | src/cmd/samterm/scroll.c | 26 |
2 files changed, 86 insertions, 18 deletions
diff --git a/src/cmd/samterm/main.c b/src/cmd/samterm/main.c index 5fc42908..78d4fa1b 100644 --- a/src/cmd/samterm/main.c +++ b/src/cmd/samterm/main.c @@ -108,19 +108,21 @@ threadmain(int argc, char *argv[]) continue; } nwhich = flwhich(mousep->xy); - scr = which && ptinrect(mousep->xy, which->scroll); + //scr = which && ptinrect(mousep->xy, which->scroll); + scr = which && (ptinrect(mousep->xy, which->scroll) || mousep->buttons&(8|16)); if(mousep->buttons) flushtyping(1); if(chording && chord==1 && !mousep->buttons) chord = 0; if(chording && chord) chord |= mousep->buttons; - else if(mousep->buttons&1){ + else if(mousep->buttons&(1|8)){ if(nwhich){ if(nwhich!=which) current(nwhich); else if(scr) - scroll(which, 1); + //scroll(which, 1); + scroll(which, (mousep->buttons&8) ? 4 : 1); else{ t=(Text *)which->user1; if(flselect(which)){ @@ -137,9 +139,10 @@ threadmain(int argc, char *argv[]) scroll(which, 2); else menu2hit(); - }else if((mousep->buttons&4)){ + }else if((mousep->buttons&(4|16))){ if(scr) - scroll(which, 3); + //scroll(which, 3); + scroll(which, (mousep->buttons&16) ? 5 : 3); else menu3hit(); } @@ -483,6 +486,48 @@ flushtyping(int clearesc) typeend = -1; } +void +sendcmd(char *c, int n, Text *t) { + Text *to = t; + Rune buf[100]; + Rune *p = buf; + Flayer *l; + long a; + + t = &cmd; + for(l=t->l; l->textfn==0; l++) + ; + current(l); + flushtyping(0); + a = t->rasp.nrunes; + flsetselect(l, a, a); + center(l, a); + + for(int x = 0; x < n; x++){ + chartorune(p++,c++); + } + *p++ = '\n'; + if(typestart < 0) + typestart = a; + if(typeesc < 0) + typeesc = a; + hgrow(t->tag, a, p-buf, 0); + t->lock++; /* pretend we Trequest'ed for hdatarune*/ + hdatarune(t->tag, a, buf, p-buf); + a += p-buf; + l->p0 = a; + l->p1 = a; + typeend = a; + flushtyping(0); + onethird(l, a); + + t = to; + for(l=t->l; l->textfn==0; l++) + ; + current(l); + flushtyping(1); +} + #define BACKSCROLLKEY Kup #define ENDKEY Kend #define ESC 0x1B @@ -497,6 +542,8 @@ flushtyping(int clearesc) #define CUT (Kcmd+'x') #define COPY (Kcmd+'c') #define PASTE (Kcmd+'v') +#define UNDO (Kcmd+'z') +#define REDO (Kcmd+'Z') int nontypingkey(int c) @@ -619,16 +666,29 @@ type(Flayer *l, int res) /* what a bloody mess this is */ center(l, t->rasp.nrunes); }else if(c == LINESTART || c == LINEEND){ flushtyping(1); - if(c == LINESTART) - while(a > 0 && raspc(&t->rasp, a-1)!='\n') + if(c == LINESTART){ + if (a > 0 && raspc(&t->rasp, a-1)=='\n') a--; - else - while(a < t->rasp.nrunes && raspc(&t->rasp, a)!='\n') + else{ + while(a > 0 && raspc(&t->rasp, a-1)!='\n') + a--; + } + }else{ + if(a < t->rasp.nrunes && raspc(&t->rasp, a)=='\n') a++; + else{ + while(a < t->rasp.nrunes && raspc(&t->rasp, a)!='\n') + a++; + } + } l->p0 = l->p1 = a; for(l=t->l; l<&t->l[NL]; l++) if(l->textfn) flsetselect(l, l->p0, l->p1); + }else if(c == UNDO) { + sendcmd("u", 1, t); + }else if(c == REDO) { + sendcmd("u-1", 3, t); }else if(backspacing && !hostlock){ /* backspacing immediately after outcmd(): sorry */ if(l->f.p0>0 && a>0){ diff --git a/src/cmd/samterm/scroll.c b/src/cmd/samterm/scroll.c index 12614751..36173410 100644 --- a/src/cmd/samterm/scroll.c +++ b/src/cmd/samterm/scroll.c @@ -115,7 +115,7 @@ scroll(Flayer *l, int but) draw(scrback, Rect(0,0,Dx(l->scroll), Dy(l->scroll)), l->f.b, nil, l->scroll.min); do{ oin = in; - in = abs(x-mousep->xy.x)<=FLSCROLLWID(l)/2; + in = (but > 3) || (but == 2) || abs(x-mousep->xy.x)<=FLSCROLLWID(l)/2; if(oin && !in) scrunmark(l, r); if(in){ @@ -126,9 +126,11 @@ scroll(Flayer *l, int but) my = s.min.y; if(my >= s.max.y) my = s.max.y; - if(!eqpt(mousep->xy, Pt(x, my))) - moveto(mousectl, Pt(x, my)); - if(but == 1){ + if(!eqpt(mousep->xy, Pt(x, my))) { + if (but <=3) + moveto(mousectl, Pt(x, my)); + } + if(but == 1 || but == 4){ p0 = l->origin-frcharofpt(&l->f, Pt(s.max.x, my)); rt = scrpos(l->scroll, p0, p0+l->f.nchars, tot); y = rt.min.y; @@ -136,7 +138,7 @@ scroll(Flayer *l, int but) y = my; if(y > s.max.y-2) y = s.max.y-2; - }else if(but == 3){ + }else if(but == 3 || but == 5){ p0 = l->origin+frcharofpt(&l->f, Pt(s.max.x, my)); rt = scrpos(l->scroll, p0, p0+l->f.nchars, tot); y = rt.min.y; @@ -147,22 +149,28 @@ scroll(Flayer *l, int but) scrmark(l, r); } } - }while(button(but)); + }while(but <=3 && button(but)); if(in){ h = s.max.y-s.min.y; scrunmark(l, r); p0 = 0; - if(but == 1) + if(but == 1 || but == 4) { p0 = (long)(my-s.min.y)/l->f.font->height+1; - else if(but == 2){ + if(but == 4) + p0 = (long)2; + but = 1; + }else if(but == 2){ if(tot > 1024L*1024L) p0 = ((tot>>10)*(y-s.min.y)/h)<<10; else p0 = tot*(y-s.min.y)/h; - }else if(but == 3){ + }else if(but == 3 || but == 5){ p0 = l->origin+frcharofpt(&l->f, Pt(s.max.x, my)); + if(but == 5) + p0 = l->origin+frcharofpt(&l->f, Pt(s.max.x, s.min.y+l->f.font->height+1)); if(p0 > tot) p0 = tot; + but = 3; } scrorigin(l, but, p0); } |