ref: 8bc290cc0f60487fc5e8f2411a36c123dda1376f
parent: 6f4439395837e0699fc8e77b318058a6dd0e28c0
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Apr 25 04:59:14 EDT 2020
triple click selection in acme see the last 2 commits.
--- a/sys/src/cmd/acme/dat.h
+++ b/sys/src/cmd/acme/dat.h
@@ -203,7 +203,7 @@
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**);
--- a/sys/src/cmd/acme/fns.h
+++ b/sys/src/cmd/acme/fns.h
@@ -54,6 +54,7 @@
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);
--- a/sys/src/cmd/acme/text.c
+++ b/sys/src/cmd/acme/text.c
@@ -868,6 +868,7 @@
static Text *clicktext;
static uint clickmsec;
+static int clickcount;
static Text *selecttext;
static uint selectq;
@@ -915,7 +916,7 @@
textselect(Text *t)
{
uint q0, q1;
- int b, x, y;
+ int b, x, y, dx, dy;
int state;
selecttext = t;
@@ -927,17 +928,25 @@
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 */
@@ -944,7 +953,7 @@
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 @@
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 @@
flushimage(display, 1);
while(mouse->buttons == b)
readmouse(mousectl);
- clicktext = nil;
+ if(mouse->msec-clickmsec >= 500)
+ clicktext = nil;
}
}
@@ -1289,8 +1297,14 @@
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 @@
}
}
/* 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)--;
}
--- a/sys/src/cmd/acme/util.c
+++ b/sys/src/cmd/acme/util.c
@@ -302,6 +302,13 @@
}
int
+isspace(Rune c)
+{
+ return c == 0 || c == ' ' || c == '\t' ||
+ c == '\n' || c == '\r' || c == '\v';
+}
+
+int
isalnum(Rune c)
{
/*