From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mimir.eigenstate.org ([206.124.132.107]) by ewsd; Thu Apr 9 09:06:47 EDT 2020 Received: from abbatoir.fios-router.home (pool-162-83-132-245.nycmny.fios.verizon.net [162.83.132.245]) by mimir.eigenstate.org (OpenSMTPD) with ESMTPSA id 1b8b80ee (TLSv1.2:ECDHE-RSA-AES256-SHA:256:NO); Thu, 9 Apr 2020 06:06:32 -0700 (PDT) Message-ID: <9D7F8C1E1CC78D19A9F91B2878C1547C@eigenstate.org> To: iru.muzgo@gmail.com, 9front@9front.org Subject: Re: [9front] vt plumbing: empty selection Date: Thu, 9 Apr 2020 06:06:30 -0700 From: ori@eigenstate.org In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: JSON over AJAX pipelining just-in-time controller > sorry 1 * UTFmax > That, plus some debug printing. Updated: diff -r 3bcb5998f222 sys/src/cmd/vt/main.c --- a/sys/src/cmd/vt/main.c Wed Apr 08 23:48:09 2020 +0200 +++ b/sys/src/cmd/vt/main.c Thu Apr 09 06:06:11 2020 -0700 @@ -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,44 @@ 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 + 1, p.y); + if(c == 0 || c == ' ' || c == '\t' || c == '\n') + break; + } + if(s == nil || x0 == x1) + return nil; + s = malloc((x1 - x0 + 1)*UTFmax); + e = selrange(s, x0, p.y, x1, p.y); + 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 +1147,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 +1207,7 @@ return; case Mplumb: - plumbsel(); + plumbsel(p); return; case Mpage: /* pause and clear at end of screen */