summaryrefslogtreecommitdiff
path: root/sys/src/cmd/sam
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2020-04-25 08:57:26 -0700
committerOri Bernstein <ori@eigenstate.org>2020-04-25 08:57:26 -0700
commitf616a0c1bd161c8d3a4765a9d171403974011922 (patch)
tree7ca8c48d9e4c286f5519226e424661d6d613b1fe /sys/src/cmd/sam
parent614b18484cb754c4ba936d143016b558845073b1 (diff)
triple click selection in sam
three clicks selects a whitespace-delimited line.
Diffstat (limited to 'sys/src/cmd/sam')
-rw-r--r--sys/src/cmd/sam/mesg.c8
-rw-r--r--sys/src/cmd/sam/mesg.h2
-rw-r--r--sys/src/cmd/sam/moveto.c28
-rw-r--r--sys/src/cmd/sam/sam.h2
4 files changed, 32 insertions, 8 deletions
diff --git a/sys/src/cmd/sam/mesg.c b/sys/src/cmd/sam/mesg.c
index 7d390fd13..40ccfd665 100644
--- a/sys/src/cmd/sam/mesg.c
+++ b/sys/src/cmd/sam/mesg.c
@@ -54,7 +54,7 @@ char *hname[] = {
[Hsnarflen] "Hsnarflen",
[Hack] "Hack",
[Hexit] "Hexit",
- [Hplumb] "Hplumb",
+ [Hplumb] "Hplumb",
};
char *tname[] = {
@@ -76,11 +76,12 @@ char *tname[] = {
[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 @@ inmesg(Tmesg type)
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 --git a/sys/src/cmd/sam/mesg.h b/sys/src/cmd/sam/mesg.h
index 6e34f664a..c8f3bbcc8 100644
--- 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 @@ typedef enum Tmesg
Tack, /* acknowledge Hack */
Texit, /* exit */
Tplumb, /* send plumb message */
+ Ttclick, /* triple click */
TMAX,
}Tmesg;
/*
diff --git a/sys/src/cmd/sam/moveto.c b/sys/src/cmd/sam/moveto.c
index 0584c1378..1f5515971 100644
--- a/sys/src/cmd/sam/moveto.c
+++ b/sys/src/cmd/sam/moveto.c
@@ -61,7 +61,7 @@ lookorigin(File *f, Posn p0, Posn ls)
}
int
-alnum(int c)
+isalnum(int c)
{
/*
* Hard to get absolutely right. Use what we know about ASCII
@@ -78,6 +78,19 @@ alnum(int c)
}
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 @@ strrune(Rune *s, Rune c)
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 @@ doubleclick(File *f, Posn p1)
}
/* 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 --git a/sys/src/cmd/sam/sam.h b/sys/src/cmd/sam/sam.h
index 9839f8add..ae79a4bba 100644
--- a/sys/src/cmd/sam/sam.h
+++ b/sys/src/cmd/sam/sam.h
@@ -241,7 +241,7 @@ File *current(File*);
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);