diff options
author | Ori Bernstein <ori@eigenstate.org> | 2020-04-25 08:59:14 -0700 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2020-04-25 08:59:14 -0700 |
commit | 8bc290cc0f60487fc5e8f2411a36c123dda1376f (patch) | |
tree | f240a38b7a05f574eabf48f78e81db959f308fbc /sys | |
parent | 6f4439395837e0699fc8e77b318058a6dd0e28c0 (diff) |
triple click selection in acme
see the last 2 commits.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/src/cmd/acme/dat.h | 2 | ||||
-rw-r--r-- | sys/src/cmd/acme/fns.h | 1 | ||||
-rw-r--r-- | sys/src/cmd/acme/text.c | 48 | ||||
-rw-r--r-- | sys/src/cmd/acme/util.c | 7 |
4 files changed, 40 insertions, 18 deletions
diff --git a/sys/src/cmd/acme/dat.h b/sys/src/cmd/acme/dat.h index 5daf89e04..9e8fe26ec 100644 --- a/sys/src/cmd/acme/dat.h +++ b/sys/src/cmd/acme/dat.h @@ -203,7 +203,7 @@ void textcolumnate(Text*, Dirlist**, int); void textcommit(Text*, int); void textconstrain(Text*, uint, uint, uint*, uint*); void textdelete(Text*, uint, uint, int); -void textdoubleclick(Text*, uint*, uint*); +void textstretchsel(Text*, uint*, uint*, int); void textfill(Text*); void textframescroll(Text*, int); void textinit(Text*, File*, Rectangle, Reffont*, Image**); diff --git a/sys/src/cmd/acme/fns.h b/sys/src/cmd/acme/fns.h index 2a2508087..5b5b7ac21 100644 --- a/sys/src/cmd/acme/fns.h +++ b/sys/src/cmd/acme/fns.h @@ -54,6 +54,7 @@ void get(Text*, Text*, Text*, int, int, Rune*, int); void put(Text*, Text*, Text*, int, int, Rune*, int); void putfile(File*, int, int, Rune*, int); void fontx(Text*, Text*, Text*, int, int, Rune*, int); +int isspace(Rune); int isalnum(Rune); void execute(Text*, uint, uint, int, Text*); int search(Text*, Rune*, uint); diff --git a/sys/src/cmd/acme/text.c b/sys/src/cmd/acme/text.c index 246a2cd70..1987644b2 100644 --- a/sys/src/cmd/acme/text.c +++ b/sys/src/cmd/acme/text.c @@ -868,6 +868,7 @@ textcommit(Text *t, int tofile) static Text *clicktext; static uint clickmsec; +static int clickcount; static Text *selecttext; static uint selectq; @@ -915,7 +916,7 @@ void textselect(Text *t) { uint q0, q1; - int b, x, y; + int b, x, y, dx, dy; int state; selecttext = t; @@ -927,24 +928,32 @@ textselect(Text *t) q0 = t->q0; q1 = t->q1; selectq = t->org+frcharofpt(t, mouse->xy); - if(clicktext==t && mouse->msec-clickmsec<500) - if(q0==q1 && selectq==q0){ - textdoubleclick(t, &q0, &q1); + clickcount++; + if(mouse->msec-clickmsec >= 500 || selecttext != t || clickcount > 3) + clickcount = 0; + if(clickcount >= 1 && selecttext==t && mouse->msec-clickmsec < 500){ + textstretchsel(t, &q0, &q1, clickcount); textsetselect(t, q0, q1); flushimage(display, 1); x = mouse->xy.x; y = mouse->xy.y; /* stay here until something interesting happens */ - do + while(1){ readmouse(mousectl); - while(mouse->buttons==b && abs(mouse->xy.x-x)<3 && abs(mouse->xy.y-y)<3); + dx = abs(mouse->xy.x - x); + dy = abs(mouse->xy.y - y); + if(mouse->buttons != b || dx >= 3 || dy >= 3) + break; + clickcount++; + clickmsec = mouse->msec; + } mouse->xy.x = x; /* in case we're calling frselect */ mouse->xy.y = y; q0 = t->q0; /* may have changed */ q1 = t->q1; selectq = q0; } - if(mouse->buttons == b){ + if(mouse->buttons == b && clickcount == 0){ t->Frame.scroll = framescroll; frselect(t, mousectl); /* horrible botch: while asleep, may have lost selection altogether */ @@ -961,13 +970,11 @@ textselect(Text *t) q1 = t->org+t->p1; } if(q0 == q1){ - if(q0==t->q0 && clicktext==t && mouse->msec-clickmsec<500){ - textdoubleclick(t, &q0, &q1); - clicktext = nil; - }else{ + if(q0==t->q0 && mouse->msec-clickmsec<500) + textstretchsel(t, &q0, &q1, clickcount); + else clicktext = t; - clickmsec = mouse->msec; - } + clickmsec = mouse->msec; }else clicktext = nil; textsetselect(t, q0, q1); @@ -1006,7 +1013,8 @@ textselect(Text *t) flushimage(display, 1); while(mouse->buttons == b) readmouse(mousectl); - clicktext = nil; + if(mouse->msec-clickmsec >= 500) + clicktext = nil; } } @@ -1289,8 +1297,14 @@ Rune *right[] = { nil }; +int +inmode(Rune r, int mode) +{ + return (mode == 1) ? isalnum(r) : r && !isspace(r); +} + void -textdoubleclick(Text *t, uint *q0, uint *q1) +textstretchsel(Text *t, uint *q0, uint *q1, int mode) { int c, i; Rune *r, *l, *p; @@ -1328,10 +1342,10 @@ textdoubleclick(Text *t, uint *q0, uint *q1) } } /* try filling out word to right */ - while(*q1<t->file->nc && isalnum(textreadc(t, *q1))) + while(*q1<t->file->nc && inmode(textreadc(t, *q1), mode)) (*q1)++; /* try filling out word to left */ - while(*q0>0 && isalnum(textreadc(t, *q0-1))) + while(*q0>0 && inmode(textreadc(t, *q0-1), mode)) (*q0)--; } diff --git a/sys/src/cmd/acme/util.c b/sys/src/cmd/acme/util.c index 44f77192e..eeed13239 100644 --- a/sys/src/cmd/acme/util.c +++ b/sys/src/cmd/acme/util.c @@ -302,6 +302,13 @@ bytetorune(char *s, int *ip) } int +isspace(Rune c) +{ + return c == 0 || c == ' ' || c == '\t' || + c == '\n' || c == '\r' || c == '\v'; +} + +int isalnum(Rune c) { /* |