ref: ebb3e31118724ff3a655815abc333992ac7287ed
parent: a7dab2728bde8eea68ddfdfadfad08a00b1f7c68
author: Ori Bernstein <[email protected]>
date: Sat Apr 11 07:56:04 EDT 2020
vt plumbing: don't require selection Plumbing text in vt requires selecting the text that you want to plumb precisely. This patch makes plumbing behave the same way that it does in rio.
--- a/sys/src/cmd/vt/main.c
+++ b/sys/src/cmd/vt/main.c
@@ -170,7 +170,7 @@
void escapedump(int,uchar *,int);
void paste(void);
void snarfsel(void);
-void plumbsel(void);
+void plumbsel(Point);
static Channel *pidchan;
@@ -982,13 +982,47 @@
free(s);
}
+/*
+ * Grabs the non-whitespace text around a character
+ * cell, matching the behavior in rio for plumbing.
+ * Does not modify the selection.
+ */
+char*
+surrounding(Point p)
+{
+ int c, x0, x1;
+ char *s, *e;
+
+ for(x0 = p.x; x0 > 0; x0--){
+ c = *onscreenr(x0 - 1, p.y);
+ if(c == 0 || c == ' ' || c == '\t' || c == '\n')
+ break;
+ }
+ for(x1 = p.x; x1 <= xmax; x1++){
+ c = *onscreenr(x1, p.y);
+ if(c == 0 || c == ' ' || c == '\t' || c == '\n')
+ break;
+ }
+ if(x0 == x1)
+ return nil;
+ s = malloc((x1 - x0 + 1)*UTFmax);
+ if(s == nil)
+ return nil;
+ e = selrange(s, x0, p.y, x1, p.y);
+ *e = 0;
+ return s;
+}
+
void
-plumbsel(void)
+plumbsel(Point p)
{
char *s, wdir[1024];
int plumb;
- if((s = selection()) == nil)
+ s = selection();
+ if(s == nil || *s == 0)
+ s = surrounding(p);
+ if(s == nil)
return;
if(getwd(wdir, sizeof wdir) == nil){
free(s);
@@ -1116,6 +1150,9 @@
void
readmenu(void)
{
+ Point p;
+
+ p = pos(mc->xy);
if(button3()) {
menu3.item[1] = ttystate[cs->raw].crnl ? "cr" : "crnl";
menu3.item[2] = ttystate[cs->raw].nlcr ? "nl" : "nlcr";
@@ -1173,7 +1210,7 @@
return;
case Mplumb:
- plumbsel();
+ plumbsel(p);
return;
case Mpage: /* pause and clear at end of screen */