Hi,
One thing from st that bugs me a little: whenever I select some text
with the mouse it remains marked even if I type in the same line and
change its content. The same happens if I keep typing and the window
scrolls, since the selection box does not scroll along with it. In
either case, a new piece of text seems to be selected, but this "new
selection" is of course not copied to the clipboard, which feels
annoying.
This patch solves this problem with a behavior akin to that of
xterm/urxvt: scrolling the selection box with the screen and hiding it
if you type in its line or clear the screen.
Cheers,
Rafa
PS: I tried looking both at xterm and urxvt source for a minute;
almost ripped my eyes off
diff -r 1c8e6796c6fe st.c
--- a/st.c Sun Aug 14 17:15:19 2011 +0200
+++ b/st.c Wed Sep 14 15:38:20 2011 +0200
@@ -231,6 +231,7 @@
static inline int selected(int, int);
static void selcopy(void);
static void selpaste();
+static void scrollsel(int, int);
static int utf8decode(char *, long *);
static int utf8encode(long *, char *);
@@ -801,6 +802,8 @@
term.line[i] = term.line[i-n];
term.line[i-n] = temp;
}
+
+ scrollsel(orig, n);
}
void
@@ -816,6 +819,29 @@
term.line[i] = term.line[i+n];
term.line[i+n] = temp;
}
+
+ scrollsel(orig, -n);
+}
+
+void
+scrollsel(int orig, int n) {
+ if(sel.bx == -1) return;
+ if(BETWEEN(sel.by, orig, term.bot) || BETWEEN(sel.ey, orig, term.bot)) {
+ if((sel.by+=n) > term.bot || (sel.ey+=n) < term.top) {
+ sel.bx=-1;
+ return;
+ }
+ if(sel.byterm.bot) {
+ sel.ey=term.bot;
+ sel.ex=term.col;
+ }
+ sel.b.y=sel.by; sel.b.x=sel.bx;
+ sel.e.y=sel.ey; sel.e.x=sel.ex;
+ }
}
void
@@ -1072,6 +1098,7 @@
break;
/* XXX: (CSI n I) CHT -- Cursor Forward Tabulation tab stops */
case 'J': /* ED -- Clear screen */
+ sel.bx = -1;
switch(escseq.arg[0]) {
case 0: /* below */
tclearregion(term.c.x, term.c.y, term.col-1, term.c.y);
@@ -1377,6 +1404,7 @@
}
}
} else {
+ if(sel.bx != -1 && BETWEEN(term.c.y, sel.by, sel.ey)) sel.bx =
-1;
switch(ascii) {
case '\t':
tputtab();