9front - general discussion about 9front
 help / color / mirror / Atom feed
* rio triple click selection
@ 2020-04-12 17:19 ori
  2020-04-12 17:44 ` [9front] " Stanley Lieber
  2020-04-13  5:15 ` ori
  0 siblings, 2 replies; 6+ messages in thread
From: ori @ 2020-04-12 17:19 UTC (permalink / raw)
  To: 9front

To improve plumbing in vt, I recently implemented triple click.
Doubleclick selects an alphanumeric segment. Triple click selects
a non-whitespace segment, making it easy to sleect paths, urls,
and other larger chunks of text.

         tclick
     v-----------v
   x something/bar y
     ^-------^
      dclick
  
This worked out well enough that it seems like a good idea to add
it to rio. Sam and Acme should probably get the same treatment.
Are there any other programs where text selection should be patched
to match?

Here's a patch that does this:

diff -r d0d202a26d24 sys/src/cmd/rio/dat.h
--- a/sys/src/cmd/rio/dat.h	Sun Apr 12 16:12:41 2020 +0200
+++ b/sys/src/cmd/rio/dat.h	Sun Apr 12 10:18:43 2020 -0700
@@ -195,7 +195,7 @@
 void		wcurrent(Window*);
 void		wcut(Window*);
 void		wdelete(Window*, uint, uint);
-void		wdoubleclick(Window*, uint*, uint*);
+void		wstretchsel(Window*, uint*, uint*, int);
 void		wfill(Window*);
 void		wframescroll(Window*, int);
 void		wkeyctl(Window*, Rune);
diff -r d0d202a26d24 sys/src/cmd/rio/fns.h
--- a/sys/src/cmd/rio/fns.h	Sun Apr 12 16:12:41 2020 +0200
+++ b/sys/src/cmd/rio/fns.h	Sun Apr 12 10:18:43 2020 -0700
@@ -9,6 +9,7 @@
 int	max(int, int);
 Rune*	strrune(Rune*, Rune);
 int	isalnum(Rune);
+int	isspace(Rune);
 void	timerstop(Timer*);
 void	timercancel(Timer*);
 Timer*	timerstart(int);
diff -r d0d202a26d24 sys/src/cmd/rio/util.c
--- a/sys/src/cmd/rio/util.c	Sun Apr 12 16:12:41 2020 +0200
+++ b/sys/src/cmd/rio/util.c	Sun Apr 12 10:18:43 2020 -0700
@@ -105,6 +105,13 @@
 	return TRUE;
 }
 
+int
+isspace(Rune c)
+{
+	return c == 0 || c == ' ' || c == '\t' ||
+		c == '\n' || c == '\r' || c == '\v';
+}
+
 Rune*
 strrune(Rune *s, Rune c)
 {
diff -r d0d202a26d24 sys/src/cmd/rio/wind.c
--- a/sys/src/cmd/rio/wind.c	Sun Apr 12 16:12:41 2020 +0200
+++ b/sys/src/cmd/rio/wind.c	Sun Apr 12 10:18:43 2020 -0700
@@ -962,6 +962,7 @@
 
 static Window	*clickwin;
 static uint	clickmsec;
+static uint	clickcount;
 static Window	*selectwin;
 static uint	selectq;
 
@@ -1007,7 +1008,7 @@
 wselect(Window *w)
 {
 	uint q0, q1;
-	int b, x, y, first;
+	int b, x, y, dx, dy, mode, first;
 
 	first = 1;
 	selectwin = w;
@@ -1018,23 +1019,31 @@
 	q0 = w->q0;
 	q1 = w->q1;
 	selectq = w->org+frcharofpt(w, w->mc.xy);
-	if(clickwin==w && w->mc.msec-clickmsec<500)
-	if(q0==q1 && selectq==w->q0){
-		wdoubleclick(w, &q0, &q1);
+	clickcount++;
+	if(w->mc.msec-clickmsec >= 500 || clickwin != w)
+		clickcount = 0;
+	if(clickwin == w && clickcount > 1 && w->mc.msec-clickmsec < 500){
+		mode = (clickcount > 2) ? 2 : clickcount;
+		wstretchsel(w, &q0, &q1, mode);
 		wsetselect(w, q0, q1);
 		x = w->mc.xy.x;
 		y = w->mc.xy.y;
 		/* stay here until something interesting happens */
-		do
+		while(1){
 			readmouse(&w->mc);
-		while(w->mc.buttons==b && abs(w->mc.xy.x-x)<3 && abs(w->mc.xy.y-y)<3);
+			dx = abs(w->mc.xy.x-x);
+			dy = abs(w->mc.xy.y-y);
+			if(w->mc.buttons != b || dx >= 3 && dy >= 3)
+				break;
+			clickcount++;
+		}
 		w->mc.xy.x = x;	/* in case we're calling frselect */
 		w->mc.xy.y = y;
 		q0 = w->q0;	/* may have changed */
 		q1 = w->q1;
 		selectq = q0;
 	}
-	if(w->mc.buttons == b){
+	if(w->mc.buttons == b && clickcount == 0){
 		w->scroll = framescroll;
 		frselect(w, &w->mc);
 		/* horrible botch: while asleep, may have lost selection altogether */
@@ -1051,15 +1060,14 @@
 			q1 = w->org+w->p1;
 	}
 	if(q0 == q1){
+		mode = (clickcount > 2) ? 2 : clickcount;
 		if(q0==w->q0 && clickwin==w && w->mc.msec-clickmsec<500){
-			wdoubleclick(w, &q0, &q1);
-			clickwin = nil;
+			wstretchsel(w, &q0, &q1, mode);
 		}else{
 			clickwin = w;
 			clickmsec = w->mc.msec;
 		}
-	}else
-		clickwin = nil;
+	}
 	wsetselect(w, q0, q1);
 	while(w->mc.buttons){
 		w->mc.msec = 0;
@@ -1079,7 +1087,8 @@
 		wscrdraw(w);
 		while(w->mc.buttons == b)
 			readmouse(&w->mc);
-		clickwin = nil;
+		if(w->mc.msec-clickmsec >= 500)
+			clickwin = nil;
 	}
 }
 
@@ -1483,8 +1492,14 @@
 	nil
 };
 
+int
+inmode(Rune r, int mode)
+{
+	return (mode == 1) ? isalnum(r) : r && !isspace(r);
+}
+
 void
-wdoubleclick(Window *w, uint *q0, uint *q1)
+wstretchsel(Window *w, uint *q0, uint *q1, int mode)
 {
 	int c, i;
 	Rune *r, *l, *p;
@@ -1522,10 +1537,10 @@
 		}
 	}
 	/* try filling out word to right */
-	while(*q1<w->nr && isalnum(w->r[*q1]))
+	while(*q1<w->nr && inmode(w->r[*q1], mode))
 		(*q1)++;
 	/* try filling out word to left */
-	while(*q0>0 && isalnum(w->r[*q0-1]))
+	while(*q0>0 && inmode(w->r[*q0-1], mode))
 		(*q0)--;
 }
 



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [9front] rio triple click selection
  2020-04-12 17:19 rio triple click selection ori
@ 2020-04-12 17:44 ` Stanley Lieber
  2020-04-13  5:15 ` ori
  1 sibling, 0 replies; 6+ messages in thread
From: Stanley Lieber @ 2020-04-12 17:44 UTC (permalink / raw)
  To: 9front

On April 12, 2020 1:19:56 PM EDT, ori@eigenstate.org wrote:
>To improve plumbing in vt, I recently implemented triple click.
>Doubleclick selects an alphanumeric segment. Triple click selects
>a non-whitespace segment, making it easy to sleect paths, urls,
>and other larger chunks of text.
>
>         tclick
>     v-----------v
>   x something/bar y
>     ^-------^
>      dclick
>  
>This worked out well enough that it seems like a good idea to add
>it to rio. Sam and Acme should probably get the same treatment.
>Are there any other programs where text selection should be patched
>to match?
>
>Here's a patch that does this:
>
>diff -r d0d202a26d24 sys/src/cmd/rio/dat.h
>--- a/sys/src/cmd/rio/dat.h	Sun Apr 12 16:12:41 2020 +0200
>+++ b/sys/src/cmd/rio/dat.h	Sun Apr 12 10:18:43 2020 -0700
>@@ -195,7 +195,7 @@
> void		wcurrent(Window*);
> void		wcut(Window*);
> void		wdelete(Window*, uint, uint);
>-void		wdoubleclick(Window*, uint*, uint*);
>+void		wstretchsel(Window*, uint*, uint*, int);
> void		wfill(Window*);
> void		wframescroll(Window*, int);
> void		wkeyctl(Window*, Rune);
>diff -r d0d202a26d24 sys/src/cmd/rio/fns.h
>--- a/sys/src/cmd/rio/fns.h	Sun Apr 12 16:12:41 2020 +0200
>+++ b/sys/src/cmd/rio/fns.h	Sun Apr 12 10:18:43 2020 -0700
>@@ -9,6 +9,7 @@
> int	max(int, int);
> Rune*	strrune(Rune*, Rune);
> int	isalnum(Rune);
>+int	isspace(Rune);
> void	timerstop(Timer*);
> void	timercancel(Timer*);
> Timer*	timerstart(int);
>diff -r d0d202a26d24 sys/src/cmd/rio/util.c
>--- a/sys/src/cmd/rio/util.c	Sun Apr 12 16:12:41 2020 +0200
>+++ b/sys/src/cmd/rio/util.c	Sun Apr 12 10:18:43 2020 -0700
>@@ -105,6 +105,13 @@
> 	return TRUE;
> }
> 
>+int
>+isspace(Rune c)
>+{
>+	return c == 0 || c == ' ' || c == '\t' ||
>+		c == '\n' || c == '\r' || c == '\v';
>+}
>+
> Rune*
> strrune(Rune *s, Rune c)
> {
>diff -r d0d202a26d24 sys/src/cmd/rio/wind.c
>--- a/sys/src/cmd/rio/wind.c	Sun Apr 12 16:12:41 2020 +0200
>+++ b/sys/src/cmd/rio/wind.c	Sun Apr 12 10:18:43 2020 -0700
>@@ -962,6 +962,7 @@
> 
> static Window	*clickwin;
> static uint	clickmsec;
>+static uint	clickcount;
> static Window	*selectwin;
> static uint	selectq;
> 
>@@ -1007,7 +1008,7 @@
> wselect(Window *w)
> {
> 	uint q0, q1;
>-	int b, x, y, first;
>+	int b, x, y, dx, dy, mode, first;
> 
> 	first = 1;
> 	selectwin = w;
>@@ -1018,23 +1019,31 @@
> 	q0 = w->q0;
> 	q1 = w->q1;
> 	selectq = w->org+frcharofpt(w, w->mc.xy);
>-	if(clickwin==w && w->mc.msec-clickmsec<500)
>-	if(q0==q1 && selectq==w->q0){
>-		wdoubleclick(w, &q0, &q1);
>+	clickcount++;
>+	if(w->mc.msec-clickmsec >= 500 || clickwin != w)
>+		clickcount = 0;
>+	if(clickwin == w && clickcount > 1 && w->mc.msec-clickmsec < 500){
>+		mode = (clickcount > 2) ? 2 : clickcount;
>+		wstretchsel(w, &q0, &q1, mode);
> 		wsetselect(w, q0, q1);
> 		x = w->mc.xy.x;
> 		y = w->mc.xy.y;
> 		/* stay here until something interesting happens */
>-		do
>+		while(1){
> 			readmouse(&w->mc);
>-		while(w->mc.buttons==b && abs(w->mc.xy.x-x)<3 &&
>abs(w->mc.xy.y-y)<3);
>+			dx = abs(w->mc.xy.x-x);
>+			dy = abs(w->mc.xy.y-y);
>+			if(w->mc.buttons != b || dx >= 3 && dy >= 3)
>+				break;
>+			clickcount++;
>+		}
> 		w->mc.xy.x = x;	/* in case we're calling frselect */
> 		w->mc.xy.y = y;
> 		q0 = w->q0;	/* may have changed */
> 		q1 = w->q1;
> 		selectq = q0;
> 	}
>-	if(w->mc.buttons == b){
>+	if(w->mc.buttons == b && clickcount == 0){
> 		w->scroll = framescroll;
> 		frselect(w, &w->mc);
>		/* horrible botch: while asleep, may have lost selection altogether
>*/
>@@ -1051,15 +1060,14 @@
> 			q1 = w->org+w->p1;
> 	}
> 	if(q0 == q1){
>+		mode = (clickcount > 2) ? 2 : clickcount;
> 		if(q0==w->q0 && clickwin==w && w->mc.msec-clickmsec<500){
>-			wdoubleclick(w, &q0, &q1);
>-			clickwin = nil;
>+			wstretchsel(w, &q0, &q1, mode);
> 		}else{
> 			clickwin = w;
> 			clickmsec = w->mc.msec;
> 		}
>-	}else
>-		clickwin = nil;
>+	}
> 	wsetselect(w, q0, q1);
> 	while(w->mc.buttons){
> 		w->mc.msec = 0;
>@@ -1079,7 +1087,8 @@
> 		wscrdraw(w);
> 		while(w->mc.buttons == b)
> 			readmouse(&w->mc);
>-		clickwin = nil;
>+		if(w->mc.msec-clickmsec >= 500)
>+			clickwin = nil;
> 	}
> }
> 
>@@ -1483,8 +1492,14 @@
> 	nil
> };
> 
>+int
>+inmode(Rune r, int mode)
>+{
>+	return (mode == 1) ? isalnum(r) : r && !isspace(r);
>+}
>+
> void
>-wdoubleclick(Window *w, uint *q0, uint *q1)
>+wstretchsel(Window *w, uint *q0, uint *q1, int mode)
> {
> 	int c, i;
> 	Rune *r, *l, *p;
>@@ -1522,10 +1537,10 @@
> 		}
> 	}
> 	/* try filling out word to right */
>-	while(*q1<w->nr && isalnum(w->r[*q1]))
>+	while(*q1<w->nr && inmode(w->r[*q1], mode))
> 		(*q1)++;
> 	/* try filling out word to left */
>-	while(*q0>0 && isalnum(w->r[*q0-1]))
>+	while(*q0>0 && inmode(w->r[*q0-1], mode))
> 		(*q0)--;
> }
> 

mothra.

sl


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [9front] rio triple click selection
  2020-04-12 17:19 rio triple click selection ori
  2020-04-12 17:44 ` [9front] " Stanley Lieber
@ 2020-04-13  5:15 ` ori
  2020-04-25  5:48   ` ori
  1 sibling, 1 reply; 6+ messages in thread
From: ori @ 2020-04-13  5:15 UTC (permalink / raw)
  To: ori, 9front

> Sam and Acme should probably get the same treatment.

Here's sam. I also dropped the double click threshold from 1 second(!!).

diff -r d0d202a26d24 sys/src/cmd/sam/mesg.c
--- a/sys/src/cmd/sam/mesg.c	Sun Apr 12 16:12:41 2020 +0200
+++ b/sys/src/cmd/sam/mesg.c	Sun Apr 12 22:15:33 2020 -0700
@@ -54,7 +54,7 @@
 	[Hsnarflen]	"Hsnarflen",
 	[Hack]		"Hack",
 	[Hexit]		"Hexit",
-	[Hplumb]		"Hplumb",
+	[Hplumb]	"Hplumb",
 };
 
 char *tname[] = {
@@ -76,11 +76,12 @@
 	[Tsearch]	"Tsearch",
 	[Tsend]		"Tsend",
 	[Tdclick]	"Tdclick",
+	[Ttclick]	"Ttclick",
 	[Tstartsnarf]	"Tstartsnarf",
 	[Tsetsnarf]	"Tsetsnarf",
 	[Tack]		"Tack",
 	[Texit]		"Texit",
-	[Tplumb]		"Tplumb",
+	[Tplumb]	"Tplumb",
 };
 
 void
@@ -458,9 +459,10 @@
 		break;
 
 	case Tdclick:
+	case Ttclick:
 		f = whichfile(inshort());
 		p1 = inlong();
-		doubleclick(f, p1);
+		stretchsel(f, p1, type == Ttclick);
 		f->tdot.p1 = f->tdot.p2 = p1;
 		telldot(f);
 		outTs(Hunlockfile, f->tag);
diff -r d0d202a26d24 sys/src/cmd/sam/mesg.h
--- a/sys/src/cmd/sam/mesg.h	Sun Apr 12 16:12:41 2020 +0200
+++ b/sys/src/cmd/sam/mesg.h	Sun Apr 12 22:15:33 2020 -0700
@@ -1,5 +1,6 @@
 /* VERSION 1 introduces plumbing
 	2 increases SNARFSIZE from 4096 to 32000
+	3 adds a triple click
  */
 #define	VERSION	2
 
@@ -34,6 +35,7 @@
 	Tack,		/* acknowledge Hack */
 	Texit,		/* exit */
 	Tplumb,		/* send plumb message */
+	Ttclick,	/* triple click */
 	TMAX,
 }Tmesg;
 /*
diff -r d0d202a26d24 sys/src/cmd/sam/moveto.c
--- a/sys/src/cmd/sam/moveto.c	Sun Apr 12 16:12:41 2020 +0200
+++ b/sys/src/cmd/sam/moveto.c	Sun Apr 12 22:15:33 2020 -0700
@@ -61,7 +61,7 @@
 }
 
 int
-alnum(int c)
+isalnum(int c)
 {
 	/*
 	 * Hard to get absolutely right.  Use what we know about ASCII
@@ -78,6 +78,19 @@
 }
 
 int
+isspace(Rune c)
+{
+	return c == 0 || c == ' ' || c == '\t' ||
+		c == '\n' || c == '\r' || c == '\v';
+}
+
+int
+inmode(Rune r, int mode)
+{
+	return (mode == 0) ? isalnum(r) : r && !isspace(r);
+}
+
+int
 clickmatch(File *f, int cl, int cr, int dir, Posn *p)
 {
 	int c;
@@ -119,8 +132,15 @@
 	return 0;
 }
 
+/*
+ * Stretches a selection out over current text,
+ * selecting matching range if possible.
+ * If there's no matching range, mode 0 selects
+ * a single alphanumeric region. Mode 1 selects
+ * a non-whitespace region.
+ */
 void
-doubleclick(File *f, Posn p1)
+stretchsel(File *f, Posn p1, int mode)
 {
 	int c, i;
 	Rune *r, *l;
@@ -163,11 +183,11 @@
 	}
 	/* try filling out word to right */
 	p = p1;
-	while(p < f->nc && alnum(filereadc(f, p++)))
+	while(p < f->nc && inmode(filereadc(f, p++), mode))
 		f->dot.r.p2++;
 	/* try filling out word to left */
 	p = p1;
-	while(--p >= 0 && alnum(filereadc(f, p)))
+	while(--p >= 0 && inmode(filereadc(f, p), mode))
 		f->dot.r.p1--;
 }
 
diff -r d0d202a26d24 sys/src/cmd/sam/sam.h
--- a/sys/src/cmd/sam/sam.h	Sun Apr 12 16:12:41 2020 +0200
+++ b/sys/src/cmd/sam/sam.h	Sun Apr 12 22:15:33 2020 -0700
@@ -241,7 +241,7 @@
 void	delete(File*);
 void	delfile(File*);
 void	dellist(List*, int);
-void	doubleclick(File*, Posn);
+void	stretchsel(File*, Posn, int);
 void	dprint(char*, ...);
 void	edit(File*, int);
 void	*emalloc(ulong);
diff -r d0d202a26d24 sys/src/cmd/samterm/flayer.c
--- a/sys/src/cmd/samterm/flayer.c	Sun Apr 12 16:12:41 2020 +0200
+++ b/sys/src/cmd/samterm/flayer.c	Sun Apr 12 22:15:33 2020 -0700
@@ -252,19 +252,53 @@
 int
 flselect(Flayer *l)
 {
+	static int clickcount;
+	static Point clickpt = {-10, -10};
+	int dt, dx, dy;
+
+	if(l->visible!=All)
+		flupfront(l);
+	dt = l->click = mousep->msec;
+	dx = abs(mousep->xy.x - clickpt.x);
+	dy = abs(mousep->xy.y - clickpt.y);
+
+	l->click = mousep->msec;
+	clickpt = mousep->xy;
+
+	if(dx < 3 && dy < 3){
+		clickcount++;
+		if(dt >= Clicktime || clickcount >= 3)
+			clickcount = 0;
+		if(clickcount > 0)
+			return clickcount;
+	}
+
+	frselect(&l->f, mousectl);
+	l->p0 = l->f.p0+l->origin, l->p1 = l->f.p1+l->origin;
+	return 0;
+}
+
+#ifdef NOPE
+int
+flselect(Flayer *l)
+{
 	if(l->visible!=All)
 		flupfront(l);
 	if(l->f.p0==l->f.p1)
-		if(mousep->msec-l->click<Clicktime && l->f.p0+l->origin==l->p0 && 
+		if(mousep->msec-l->click >= Clicktime)
+			clickcount = 0;
+		clickcount++;
+		if(clickcount > 0 && l->f.p0+l->origin==l->p0 && 
 			l->f.p0==frcharofpt(&l->f, mousep->xy)){
 			l->click = 0;
-			return 1;
+			return clickcount > 2 ? 2 : clickcount;
 		}
 	l->click = mousep->msec;
 	frselect(&l->f, mousectl);
 	l->p0 = l->f.p0+l->origin, l->p1 = l->f.p1+l->origin;
 	return 0;
 }
+#endif
 
 void
 flsetselect(Flayer *l, long p0, long p1)
diff -r d0d202a26d24 sys/src/cmd/samterm/flayer.h
--- a/sys/src/cmd/samterm/flayer.h	Sun Apr 12 16:12:41 2020 +0200
+++ b/sys/src/cmd/samterm/flayer.h	Sun Apr 12 22:15:33 2020 -0700
@@ -5,7 +5,7 @@
 }Vis;
 
 enum{
-	Clicktime=1000,		/* one second */
+	Clicktime=300,		/* milliseconds */
 };
 
 typedef struct Flayer Flayer;
diff -r d0d202a26d24 sys/src/cmd/samterm/main.c
--- a/sys/src/cmd/samterm/main.c	Sun Apr 12 16:12:41 2020 +0200
+++ b/sys/src/cmd/samterm/main.c	Sun Apr 12 22:15:33 2020 -0700
@@ -31,7 +31,7 @@
 void
 threadmain(int argc, char *argv[])
 {
-	int i, got, scr, chord;
+	int i, got, nclick, scr, chord;
 	Text *t;
 	Rectangle r;
 	Flayer *nwhich;
@@ -105,8 +105,12 @@
 					current(nwhich);
 				else{
 					t=(Text *)which->user1;
-					if(flselect(which)){
-						outTsl(Tdclick, t->tag, which->p0);
+					nclick = flselect(which);
+					if(nclick > 0){
+						if(nclick > 1)
+							outTsl(Ttclick, t->tag, which->p0);
+						else
+							outTsl(Tdclick, t->tag, which->p0);
 						t->lock++;
 					}else if(t!=&cmd)
 						outcmd();



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [9front] rio triple click selection
  2020-04-13  5:15 ` ori
@ 2020-04-25  5:48   ` ori
  2020-04-25 12:44     ` Ethan Gardener
  2020-04-25 14:00     ` cinap_lenrek
  0 siblings, 2 replies; 6+ messages in thread
From: ori @ 2020-04-25  5:48 UTC (permalink / raw)
  To: ori, 9front

>> Sam and Acme should probably get the same treatment.

Alright, here's acme -- going to give the acme one a day or so
to rest, and then if nobody objects, I'm going to commit all
of the above.

diff -r ecfd8ed5d6ea sys/src/cmd/acme/dat.h
--- a/sys/src/cmd/acme/dat.h	Wed Apr 22 19:57:25 2020 +0200
+++ b/sys/src/cmd/acme/dat.h	Fri Apr 24 22:47:28 2020 -0700
@@ -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**);
diff -r ecfd8ed5d6ea sys/src/cmd/acme/fns.h
--- a/sys/src/cmd/acme/fns.h	Wed Apr 22 19:57:25 2020 +0200
+++ b/sys/src/cmd/acme/fns.h	Fri Apr 24 22:47:28 2020 -0700
@@ -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);
diff -r ecfd8ed5d6ea sys/src/cmd/acme/text.c
--- a/sys/src/cmd/acme/text.c	Wed Apr 22 19:57:25 2020 +0200
+++ b/sys/src/cmd/acme/text.c	Fri Apr 24 22:47:28 2020 -0700
@@ -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,24 +928,32 @@
 	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 @@
 			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)--;
 }
 
diff -r ecfd8ed5d6ea sys/src/cmd/acme/util.c
--- a/sys/src/cmd/acme/util.c	Wed Apr 22 19:57:25 2020 +0200
+++ b/sys/src/cmd/acme/util.c	Fri Apr 24 22:47:28 2020 -0700
@@ -302,6 +302,13 @@
 }
 
 int
+isspace(Rune c)
+{
+	return c == 0 || c == ' ' || c == '\t' ||
+		c == '\n' || c == '\r' || c == '\v';
+}
+
+int
 isalnum(Rune c)
 {
 	/*



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [9front] rio triple click selection
  2020-04-25  5:48   ` ori
@ 2020-04-25 12:44     ` Ethan Gardener
  2020-04-25 14:00     ` cinap_lenrek
  1 sibling, 0 replies; 6+ messages in thread
From: Ethan Gardener @ 2020-04-25 12:44 UTC (permalink / raw)
  To: 9front, ori

On Sat, Apr 25, 2020, at 6:48 AM, ori@eigenstate.org wrote:
> >> Sam and Acme should probably get the same treatment.
> 
> Alright, here's acme -- going to give the acme one a day or so
> to rest, and then if nobody objects, I'm going to commit all
> of the above.

Thanks Ori! This would be good for Forth if I ever get around to writing it under 9front. All the same, if anyone finds a nicer way to do it than triple-clicking, I'd really like that. ;) I'm sure it could be added easily after this patch goes in.

Good call on dropping Sam's double-click time. I think Acme needs doing too, but I might be thinking of a non-9front Acme or I might be just that quick at clicking. Of course, all interfaces would be better if we could get rid of double-click with the requisite guesswork at an appropriate time and associated interference with rapid single clicks, but that's a whole other story and I'm not sure even I could adapt to it now. ;)


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [9front] rio triple click selection
  2020-04-25  5:48   ` ori
  2020-04-25 12:44     ` Ethan Gardener
@ 2020-04-25 14:00     ` cinap_lenrek
  1 sibling, 0 replies; 6+ messages in thread
From: cinap_lenrek @ 2020-04-25 14:00 UTC (permalink / raw)
  To: 9front

> Alright, here's acme -- going to give the acme one a day or so
> to rest, and then if nobody objects, I'm going to commit all
> of the above.

looks good!

--
cinap


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-04-25 14:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-12 17:19 rio triple click selection ori
2020-04-12 17:44 ` [9front] " Stanley Lieber
2020-04-13  5:15 ` ori
2020-04-25  5:48   ` ori
2020-04-25 12:44     ` Ethan Gardener
2020-04-25 14:00     ` cinap_lenrek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).