triple click selection in rio
same as sam and vt, three clicks selects a whitespace-delimited line.
This commit is contained in:
parent
f616a0c1bd
commit
6f44393958
4 changed files with 43 additions and 20 deletions
|
@ -195,7 +195,7 @@ void wclosewin(Window*);
|
||||||
void wcurrent(Window*);
|
void wcurrent(Window*);
|
||||||
void wcut(Window*);
|
void wcut(Window*);
|
||||||
void wdelete(Window*, uint, uint);
|
void wdelete(Window*, uint, uint);
|
||||||
void wdoubleclick(Window*, uint*, uint*);
|
void wstretchsel(Window*, uint*, uint*, int);
|
||||||
void wfill(Window*);
|
void wfill(Window*);
|
||||||
void wframescroll(Window*, int);
|
void wframescroll(Window*, int);
|
||||||
void wkeyctl(Window*, Rune);
|
void wkeyctl(Window*, Rune);
|
||||||
|
|
|
@ -9,6 +9,7 @@ int min(int, int);
|
||||||
int max(int, int);
|
int max(int, int);
|
||||||
Rune* strrune(Rune*, Rune);
|
Rune* strrune(Rune*, Rune);
|
||||||
int isalnum(Rune);
|
int isalnum(Rune);
|
||||||
|
int isspace(Rune);
|
||||||
void timerstop(Timer*);
|
void timerstop(Timer*);
|
||||||
void timercancel(Timer*);
|
void timercancel(Timer*);
|
||||||
Timer* timerstart(int);
|
Timer* timerstart(int);
|
||||||
|
|
|
@ -105,6 +105,13 @@ isalnum(Rune c)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
isspace(Rune c)
|
||||||
|
{
|
||||||
|
return c == 0 || c == ' ' || c == '\t' ||
|
||||||
|
c == '\n' || c == '\r' || c == '\v';
|
||||||
|
}
|
||||||
|
|
||||||
Rune*
|
Rune*
|
||||||
strrune(Rune *s, Rune c)
|
strrune(Rune *s, Rune c)
|
||||||
{
|
{
|
||||||
|
|
|
@ -962,6 +962,7 @@ wdelete(Window *w, uint q0, uint q1)
|
||||||
|
|
||||||
static Window *clickwin;
|
static Window *clickwin;
|
||||||
static uint clickmsec;
|
static uint clickmsec;
|
||||||
|
static uint clickcount;
|
||||||
static Window *selectwin;
|
static Window *selectwin;
|
||||||
static uint selectq;
|
static uint selectq;
|
||||||
|
|
||||||
|
@ -1007,7 +1008,7 @@ void
|
||||||
wselect(Window *w)
|
wselect(Window *w)
|
||||||
{
|
{
|
||||||
uint q0, q1;
|
uint q0, q1;
|
||||||
int b, x, y, first;
|
int b, x, y, dx, dy, mode, first;
|
||||||
|
|
||||||
first = 1;
|
first = 1;
|
||||||
selectwin = w;
|
selectwin = w;
|
||||||
|
@ -1018,23 +1019,32 @@ wselect(Window *w)
|
||||||
q0 = w->q0;
|
q0 = w->q0;
|
||||||
q1 = w->q1;
|
q1 = w->q1;
|
||||||
selectq = w->org+frcharofpt(w, w->mc.xy);
|
selectq = w->org+frcharofpt(w, w->mc.xy);
|
||||||
if(clickwin==w && w->mc.msec-clickmsec<500)
|
clickcount++;
|
||||||
if(q0==q1 && selectq==w->q0){
|
if(w->mc.msec-clickmsec >= 500 || clickwin != w || clickcount > 3)
|
||||||
wdoubleclick(w, &q0, &q1);
|
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);
|
wsetselect(w, q0, q1);
|
||||||
x = w->mc.xy.x;
|
x = w->mc.xy.x;
|
||||||
y = w->mc.xy.y;
|
y = w->mc.xy.y;
|
||||||
/* stay here until something interesting happens */
|
/* stay here until something interesting happens */
|
||||||
do
|
while(1){
|
||||||
readmouse(&w->mc);
|
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++;
|
||||||
|
clickmsec = w->mc.msec;
|
||||||
|
}
|
||||||
w->mc.xy.x = x; /* in case we're calling frselect */
|
w->mc.xy.x = x; /* in case we're calling frselect */
|
||||||
w->mc.xy.y = y;
|
w->mc.xy.y = y;
|
||||||
q0 = w->q0; /* may have changed */
|
q0 = w->q0; /* may have changed */
|
||||||
q1 = w->q1;
|
q1 = w->q1;
|
||||||
selectq = q0;
|
selectq = q0;
|
||||||
}
|
}
|
||||||
if(w->mc.buttons == b){
|
if(w->mc.buttons == b && clickcount == 0){
|
||||||
w->scroll = framescroll;
|
w->scroll = framescroll;
|
||||||
frselect(w, &w->mc);
|
frselect(w, &w->mc);
|
||||||
/* horrible botch: while asleep, may have lost selection altogether */
|
/* horrible botch: while asleep, may have lost selection altogether */
|
||||||
|
@ -1051,15 +1061,13 @@ wselect(Window *w)
|
||||||
q1 = w->org+w->p1;
|
q1 = w->org+w->p1;
|
||||||
}
|
}
|
||||||
if(q0 == q1){
|
if(q0 == q1){
|
||||||
if(q0==w->q0 && clickwin==w && w->mc.msec-clickmsec<500){
|
mode = (clickcount > 2) ? 2 : clickcount;
|
||||||
wdoubleclick(w, &q0, &q1);
|
if(q0==w->q0 && clickwin==w && w->mc.msec-clickmsec<500)
|
||||||
clickwin = nil;
|
wstretchsel(w, &q0, &q1, mode);
|
||||||
}else{
|
else
|
||||||
clickwin = w;
|
clickwin = w;
|
||||||
clickmsec = w->mc.msec;
|
clickmsec = w->mc.msec;
|
||||||
}
|
}
|
||||||
}else
|
|
||||||
clickwin = nil;
|
|
||||||
wsetselect(w, q0, q1);
|
wsetselect(w, q0, q1);
|
||||||
while(w->mc.buttons){
|
while(w->mc.buttons){
|
||||||
w->mc.msec = 0;
|
w->mc.msec = 0;
|
||||||
|
@ -1079,6 +1087,7 @@ wselect(Window *w)
|
||||||
wscrdraw(w);
|
wscrdraw(w);
|
||||||
while(w->mc.buttons == b)
|
while(w->mc.buttons == b)
|
||||||
readmouse(&w->mc);
|
readmouse(&w->mc);
|
||||||
|
if(w->mc.msec-clickmsec >= 500)
|
||||||
clickwin = nil;
|
clickwin = nil;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1483,8 +1492,14 @@ Rune *right[] = {
|
||||||
nil
|
nil
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
inmode(Rune r, int mode)
|
||||||
|
{
|
||||||
|
return (mode == 1) ? isalnum(r) : r && !isspace(r);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
wdoubleclick(Window *w, uint *q0, uint *q1)
|
wstretchsel(Window *w, uint *q0, uint *q1, int mode)
|
||||||
{
|
{
|
||||||
int c, i;
|
int c, i;
|
||||||
Rune *r, *l, *p;
|
Rune *r, *l, *p;
|
||||||
|
@ -1522,10 +1537,10 @@ wdoubleclick(Window *w, uint *q0, uint *q1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* try filling out word to right */
|
/* try filling out word to right */
|
||||||
while(*q1<w->nr && isalnum(w->r[*q1]))
|
while(*q1<w->nr && inmode(w->r[*q1], mode))
|
||||||
(*q1)++;
|
(*q1)++;
|
||||||
/* try filling out word to left */
|
/* try filling out word to left */
|
||||||
while(*q0>0 && isalnum(w->r[*q0-1]))
|
while(*q0>0 && inmode(w->r[*q0-1], mode))
|
||||||
(*q0)--;
|
(*q0)--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue