ref: f616a0c1bd161c8d3a4765a9d171403974011922
parent: 614b18484cb754c4ba936d143016b558845073b1
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Apr 25 04:57:26 EDT 2020
triple click selection in sam three clicks selects a whitespace-delimited line.
--- a/sys/src/cmd/sam/mesg.c
+++ b/sys/src/cmd/sam/mesg.c
@@ -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);
--- a/sys/src/cmd/sam/mesg.h
+++ b/sys/src/cmd/sam/mesg.h
@@ -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;
/*
--- a/sys/src/cmd/sam/moveto.c
+++ b/sys/src/cmd/sam/moveto.c
@@ -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--;
}
--- a/sys/src/cmd/sam/sam.h
+++ b/sys/src/cmd/sam/sam.h
@@ -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);
--- a/sys/src/cmd/samterm/flayer.c
+++ b/sys/src/cmd/samterm/flayer.c
@@ -252,15 +252,23 @@
int
flselect(Flayer *l)
{
+ static int clickcount;
+ static Point clickpt = {-10, -10};
+ int dt, dx, dy;
+
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 &&
- l->f.p0==frcharofpt(&l->f, mousep->xy)){
- l->click = 0;
- return 1;
- }
+ 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 && dt < Clicktime && clickcount < 3)
+ return ++clickcount;
+ clickcount = 0;
+
frselect(&l->f, mousectl);
l->p0 = l->f.p0+l->origin, l->p1 = l->f.p1+l->origin;
return 0;
--- a/sys/src/cmd/samterm/flayer.h
+++ b/sys/src/cmd/samterm/flayer.h
@@ -5,7 +5,7 @@
}Vis;
enum{
- Clicktime=1000, /* one second */
+ Clicktime=500, /* milliseconds */
};
typedef struct Flayer Flayer;
--- a/sys/src/cmd/samterm/main.c
+++ b/sys/src/cmd/samterm/main.c
@@ -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();