ref: 715c88f570f49e7c6729e2c3a71b819ae64a12d9
parent: 528348b9001de1db8461c81137bdee1615e3da5a
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Mon Feb 17 13:19:02 EST 2020
plan9: fix selection after pasting with a mouse
--- a/plan9.c
+++ b/plan9.c
@@ -826,10 +826,10 @@
Keyboardctl kctl;
Mouse m;
char tmp[256];
- int oldw, oldh, w, h, n;
+ int oldw, oldh, w, h, n, oldbuttons;
long seed;
- bool inverse, mselecting;
- int movex, movey;
+ bool inverse;
+ Point move;
bool shiftdown, complete, ctldown;
Alt a[Numchan+1] = {
[Cchar] = { nil, &key.rune, CHANRCV },
@@ -939,9 +939,9 @@
shiftdown = false;
altdown = false;
complete = true;
- mselecting = false;
- movex = 1;
- movey = 1;
+ move.x = 1;
+ move.y = 1;
+ oldbuttons = 0;
for (;;) {
redraw(complete);
@@ -956,8 +956,7 @@
case Cmouse:
if (m.buttons == 1) {
- if (!mselecting) {
- mselecting = true;
+ if (oldbuttons == 0) {
cur = ptmouse(m.xy);
sel.min = cur;
sel.max = cur;
@@ -973,10 +972,10 @@
else
sel.min.y = cur.y;
}
+ oldbuttons = m.buttons;
break;
}
- if (m.buttons == 0)
- mselecting = false;
+ oldbuttons = m.buttons;
if (m.buttons == 3) { /* cut */
selcopy();
@@ -983,7 +982,6 @@
selset('.');
} else if (m.buttons == 5) { /* paste */
selpaste();
- mselecting = false;
} else if (m.buttons == 4) { /* menu */
menu3i[Menu3dotstyle] = tmp;
menu3i[Menu3rulerstyle] = 1 + menu3i[Menu3dotstyle] + sprintf(tmp, "%s dots", style[(dotstyle+1) % Numstyles]);
@@ -1028,8 +1026,7 @@
break;
case Kctl:
ctldown = key.down;
- movex = ctldown ? rulers.x : 1;
- movey = ctldown ? rulers.y : 1;
+ move = Pt(ctldown ? rulers.x : 1, ctldown ? rulers.y : 1);
break;
case Kup:
case Kdown:
@@ -1048,40 +1045,40 @@
case Cchar:
switch (key.rune) {
case 0x0b: /* C-k */
- movey = 1;
+ move.y = 1;
case Kup:
if (shiftdown || mode == Mselect)
- selext(0, -movey);
+ selext(0, -move.y);
else {
if (altdown || mode == Mslide)
- selmove(0, -movey);
- curmove(0, -movey);
+ selmove(0, -move.y);
+ curmove(0, -move.y);
}
break;
case '\n': /* C-j */
- movey = 1;
+ move.y = 1;
case Kdown:
if (shiftdown || mode == Mselect)
- selext(0, movey);
+ selext(0, move.y);
else {
if (altdown || mode == Mslide)
- selmove(0, movey);
- curmove(0, movey);
+ selmove(0, move.y);
+ curmove(0, move.y);
}
break;
case Kbs: /* C-h */
- movex = 1;
+ move.x = 1;
case Kleft:
if (shiftdown || mode == Mselect) {
- selext(-movex, 0);
+ selext(-move.x, 0);
} else {
if (altdown || mode == Mslide)
- selmove(-movex, 0);
- curmove(-movex, 0);
+ selmove(-move.x, 0);
+ curmove(-move.x, 0);
}
break;
case 0x0c: /* C-l */
- movex = 1;
+ move.x = 1;
if (shiftdown) { /* FIXME this conflicts with vim keys btw */
selmap(tolower);
break;
@@ -1088,11 +1085,11 @@
}
case Kright:
if (shiftdown || mode == Mselect)
- selext(movex, 0);
+ selext(move.x, 0);
else {
if (altdown || mode == Mslide)
- selmove(movex, 0);
- curmove(movex, 0);
+ selmove(move.x, 0);
+ curmove(move.x, 0);
}
break;
case Ksoh: /* C-a */