shithub: riscv

Download patch

ref: 60c34ebb2da2b9716169ae4e6db4816d02c28910
parent: 7feab4dc5913c8d072d57e9cc7cc7b3815037fe8
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Apr 25 11:18:04 EDT 2020

tweak selection criteria

grow selection from point of click, not start of selection region.
starting at the beginning of the selection region causes the match
logic to kick in, which is confusing.

--- 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		textstretchsel(Text*, uint*, uint*, int);
+void		textstretchsel(Text*, uint, uint*, uint*, int);
 void		textfill(Text*);
 void		textframescroll(Text*, int);
 void		textinit(Text*, File*, Rectangle, Reffont*, Image**);
--- a/sys/src/cmd/acme/text.c
+++ b/sys/src/cmd/acme/text.c
@@ -932,7 +932,7 @@
 	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);
+		textstretchsel(t, selectq, &q0, &q1, clickcount);
 		textsetselect(t, q0, q1);
 		flushimage(display, 1);
 		x = mouse->xy.x;
@@ -951,7 +951,7 @@
 		mouse->xy.y = y;
 		q0 = t->q0;	/* may have changed */
 		q1 = t->q1;
-		selectq = q0;
+		selectq = t->org+frcharofpt(t, mouse->xy);;
 	}
 	if(mouse->buttons == b && clickcount == 0){
 		t->Frame.scroll = framescroll;
@@ -971,7 +971,7 @@
 	}
 	if(q0 == q1){
 		if(q0==t->q0 && mouse->msec-clickmsec<500)
-			textstretchsel(t, &q0, &q1, clickcount);
+			textstretchsel(t, selectq, &q0, &q1, clickcount);
 		else
 			clicktext = t;
 		clickmsec = mouse->msec;
@@ -1304,12 +1304,14 @@
 }
 
 void
-textstretchsel(Text *t, uint *q0, uint *q1, int mode)
+textstretchsel(Text *t, uint mp, uint *q0, uint *q1, int mode)
 {
 	int c, i;
 	Rune *r, *l, *p;
 	uint q;
 
+	*q0 = mp;
+	*q1 = mp;
 	for(i=0; left[i]!=nil; i++){
 		q = *q0;
 		l = left[i];
--- a/sys/src/cmd/rio/dat.h
+++ b/sys/src/cmd/rio/dat.h
@@ -195,7 +195,7 @@
 void		wcurrent(Window*);
 void		wcut(Window*);
 void		wdelete(Window*, uint, uint);
-void		wstretchsel(Window*, uint*, uint*, int);
+void		wstretchsel(Window*, uint, uint*, uint*, int);
 void		wfill(Window*);
 void		wframescroll(Window*, int);
 void		wkeyctl(Window*, Rune);
--- a/sys/src/cmd/rio/wind.c
+++ b/sys/src/cmd/rio/wind.c
@@ -1024,7 +1024,7 @@
 		clickcount = 0;
 	if(clickwin == w && clickcount >= 1 && w->mc.msec-clickmsec < 500){
 		mode = (clickcount > 2) ? 2 : clickcount;
-		wstretchsel(w, &q0, &q1, mode);
+		wstretchsel(w, selectq, &q0, &q1, mode);
 		wsetselect(w, q0, q1);
 		x = w->mc.xy.x;
 		y = w->mc.xy.y;
@@ -1042,7 +1042,7 @@
 		w->mc.xy.y = y;
 		q0 = w->q0;	/* may have changed */
 		q1 = w->q1;
-		selectq = q0;
+		selectq = w->org+frcharofpt(w, w->mc.xy);
 	}
 	if(w->mc.buttons == b && clickcount == 0){
 		w->scroll = framescroll;
@@ -1063,7 +1063,7 @@
 	if(q0 == q1){
 		mode = (clickcount > 2) ? 2 : clickcount;
 		if(q0==w->q0 && clickwin==w && w->mc.msec-clickmsec<500)
-			wstretchsel(w, &q0, &q1, mode);
+			wstretchsel(w, selectq, &q0, &q1, mode);
 		else
 			clickwin = w;
 		clickmsec = w->mc.msec;
@@ -1499,12 +1499,14 @@
 }
 
 void
-wstretchsel(Window *w, uint *q0, uint *q1, int mode)
+wstretchsel(Window *w, uint pt, uint *q0, uint *q1, int mode)
 {
 	int c, i;
 	Rune *r, *l, *p;
 	uint q;
 
+	*q0 = pt;
+	*q1 = pt;
 	for(i=0; left[i]!=nil; i++){
 		q = *q0;
 		l = left[i];
--- a/sys/src/cmd/samterm/flayer.c
+++ b/sys/src/cmd/samterm/flayer.c
@@ -250,7 +250,7 @@
 }
 
 int
-flselect(Flayer *l)
+flselect(Flayer *l, ulong *p)
 {
 	static int clickcount;
 	static Point clickpt = {-10, -10};
@@ -261,6 +261,7 @@
 	dt = mousep->msec - l->click;
 	dx = abs(mousep->xy.x - clickpt.x);
 	dy = abs(mousep->xy.y - clickpt.y);
+	*p = frcharofpt(&l->f, mousep->xy) + l->origin;
 
 	l->click = mousep->msec;
 	clickpt = mousep->xy;
@@ -270,7 +271,8 @@
 	clickcount = 0;
 
 	frselect(&l->f, mousectl);
-	l->p0 = l->f.p0+l->origin, l->p1 = l->f.p1+l->origin;
+	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
@@ -36,7 +36,7 @@
 Rectangle flrect(Flayer*, Rectangle);
 void	flrefresh(Flayer*, Rectangle, int);
 void	flresize(Rectangle);
-int	flselect(Flayer*);
+int	flselect(Flayer*, ulong*);
 void	flsetselect(Flayer*, long, long);
 void	flstart(Rectangle);
 void	flupfront(Flayer*);
--- a/sys/src/cmd/samterm/main.c
+++ b/sys/src/cmd/samterm/main.c
@@ -35,6 +35,7 @@
 	Text *t;
 	Rectangle r;
 	Flayer *nwhich;
+	ulong p;
 
 	getscreen(argc, argv);
 	iconinit();
@@ -105,12 +106,12 @@
 					current(nwhich);
 				else{
 					t=(Text *)which->user1;
-					nclick = flselect(which);
+					nclick = flselect(which, &p);
 					if(nclick > 0){
 						if(nclick > 1)
-							outTsl(Ttclick, t->tag, which->p0);
+							outTsl(Ttclick, t->tag, p);
 						else
-							outTsl(Tdclick, t->tag, which->p0);
+							outTsl(Tdclick, t->tag, p);
 						t->lock++;
 					}else if(t!=&cmd)
 						outcmd();