pinosaur
/
st.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix empty selection highlighting bug.
[st.git]
/
st.c
diff --git
a/st.c
b/st.c
index
300cab6
..
3eb66fa
100644
(file)
--- a/
st.c
+++ b/
st.c
@@
-162,6
+162,12
@@
enum window_state {
WIN_FOCUSED = 2
};
WIN_FOCUSED = 2
};
+enum selection_mode {
+ SEL_IDLE = 0,
+ SEL_EMPTY = 1,
+ SEL_READY = 2
+};
+
enum selection_type {
SEL_REGULAR = 1,
SEL_RECTANGULAR = 2
enum selection_type {
SEL_REGULAR = 1,
SEL_RECTANGULAR = 2
@@
-453,7
+459,7
@@
static inline bool selected(int, int);
static char *getsel(void);
static void selcopy(Time);
static void selscroll(int, int);
static char *getsel(void);
static void selcopy(Time);
static void selscroll(int, int);
-static void selsnap(int
, int
*, int *, int);
+static void selsnap(int *, int *, int);
static int x2col(int);
static int y2row(int);
static void getbuttoninfo(XEvent *);
static int x2col(int);
static int y2row(int);
static void getbuttoninfo(XEvent *);
@@
-643,7
+649,7
@@
void
selinit(void) {
memset(&sel.tclick1, 0, sizeof(sel.tclick1));
memset(&sel.tclick2, 0, sizeof(sel.tclick2));
selinit(void) {
memset(&sel.tclick1, 0, sizeof(sel.tclick1));
memset(&sel.tclick2, 0, sizeof(sel.tclick2));
- sel.mode =
0
;
+ sel.mode =
SEL_IDLE
;
sel.ob.x = -1;
sel.primary = NULL;
sel.clipboard = NULL;
sel.ob.x = -1;
sel.primary = NULL;
sel.clipboard = NULL;
@@
-685,18
+691,18
@@
void
selnormalize(void) {
int i;
selnormalize(void) {
int i;
- if(sel.ob.y == sel.oe.y || sel.type == SEL_RECTANGULAR) {
- sel.nb.x = MIN(sel.ob.x, sel.oe.x);
- sel.ne.x = MAX(sel.ob.x, sel.oe.x);
- } else {
+ if(sel.type == SEL_REGULAR && sel.ob.y != sel.oe.y) {
sel.nb.x = sel.ob.y < sel.oe.y ? sel.ob.x : sel.oe.x;
sel.ne.x = sel.ob.y < sel.oe.y ? sel.oe.x : sel.ob.x;
sel.nb.x = sel.ob.y < sel.oe.y ? sel.ob.x : sel.oe.x;
sel.ne.x = sel.ob.y < sel.oe.y ? sel.oe.x : sel.ob.x;
+ } else {
+ sel.nb.x = MIN(sel.ob.x, sel.oe.x);
+ sel.ne.x = MAX(sel.ob.x, sel.oe.x);
}
sel.nb.y = MIN(sel.ob.y, sel.oe.y);
sel.ne.y = MAX(sel.ob.y, sel.oe.y);
}
sel.nb.y = MIN(sel.ob.y, sel.oe.y);
sel.ne.y = MAX(sel.ob.y, sel.oe.y);
- selsnap(
sel.snap,
&sel.nb.x, &sel.nb.y, -1);
- selsnap(
sel.snap,
&sel.ne.x, &sel.ne.y, +1);
+ selsnap(&sel.nb.x, &sel.nb.y, -1);
+ selsnap(&sel.ne.x, &sel.ne.y, +1);
/* expand selection over line breaks */
if (sel.type == SEL_RECTANGULAR)
/* expand selection over line breaks */
if (sel.type == SEL_RECTANGULAR)
@@
-710,6
+716,9
@@
selnormalize(void) {
bool
selected(int x, int y) {
bool
selected(int x, int y) {
+ if(sel.mode == SEL_EMPTY)
+ return false;
+
if(sel.type == SEL_RECTANGULAR)
return BETWEEN(y, sel.nb.y, sel.ne.y)
&& BETWEEN(x, sel.nb.x, sel.ne.x);
if(sel.type == SEL_RECTANGULAR)
return BETWEEN(y, sel.nb.y, sel.ne.y)
&& BETWEEN(x, sel.nb.x, sel.ne.x);
@@
-720,12
+729,12
@@
selected(int x, int y) {
}
void
}
void
-selsnap(int
mode, int
*x, int *y, int direction) {
+selsnap(int *x, int *y, int direction) {
int newx, newy, xt, yt;
bool delim, prevdelim;
Glyph *gp, *prevgp;
int newx, newy, xt, yt;
bool delim, prevdelim;
Glyph *gp, *prevgp;
- switch(
mode
) {
+ switch(
sel.snap
) {
case SNAP_WORD:
/*
* Snap around if the word wraps around at the end or
case SNAP_WORD:
/*
* Snap around if the word wraps around at the end or
@@
-772,15
+781,15
@@
selsnap(int mode, int *x, int *y, int direction) {
* previous line will be selected.
*/
*x = (direction < 0) ? 0 : term.col - 1;
* previous line will be selected.
*/
*x = (direction < 0) ? 0 : term.col - 1;
- if(direction < 0
&& *y > 0
) {
+ if(direction < 0) {
for(; *y > 0; *y += direction) {
if(!(term.line[*y-1][term.col-1].mode
& ATTR_WRAP)) {
break;
}
}
for(; *y > 0; *y += direction) {
if(!(term.line[*y-1][term.col-1].mode
& ATTR_WRAP)) {
break;
}
}
- } else if(direction > 0
&& *y < term.row-1
) {
- for(; *y < term.row; *y += direction) {
+ } else if(direction > 0) {
+ for(; *y < term.row
-1
; *y += direction) {
if(!(term.line[*y][term.col-1].mode
& ATTR_WRAP)) {
break;
if(!(term.line[*y][term.col-1].mode
& ATTR_WRAP)) {
break;
@@
-897,7
+906,7
@@
bpress(XEvent *e) {
/* Clear previous selection, logically and visually. */
selclear(NULL);
/* Clear previous selection, logically and visually. */
selclear(NULL);
- sel.mode =
1
;
+ sel.mode =
SEL_EMPTY
;
sel.type = SEL_REGULAR;
sel.oe.x = sel.ob.x = x2col(e->xbutton.x);
sel.oe.y = sel.ob.y = y2row(e->xbutton.y);
sel.type = SEL_REGULAR;
sel.oe.x = sel.ob.x = x2col(e->xbutton.x);
sel.oe.y = sel.ob.y = y2row(e->xbutton.y);
@@
-915,14
+924,9
@@
bpress(XEvent *e) {
}
selnormalize();
}
selnormalize();
- /*
- * Draw selection, unless it's regular and we don't want to
- * make clicks visible
- */
- if(sel.snap != 0) {
- sel.mode++;
- tsetdirt(sel.nb.y, sel.ne.y);
- }
+ if(sel.snap != 0)
+ sel.mode = SEL_READY;
+ tsetdirt(sel.nb.y, sel.ne.y);
sel.tclick2 = sel.tclick1;
sel.tclick1 = now;
}
sel.tclick2 = sel.tclick1;
sel.tclick1 = now;
}
@@
-1078,8
+1082,8
@@
selrequest(XEvent *e) {
xev.selection = xsre->selection;
xev.target = xsre->target;
xev.time = xsre->time;
xev.selection = xsre->selection;
xev.target = xsre->target;
xev.time = xsre->time;
-
if (xsre->property == None)
- xsre->property = xsre->target;
+ if (xsre->property == None)
+
xsre->property = xsre->target;
/* reject */
xev.property = None;
/* reject */
xev.property = None;
@@
-1128,8
+1132,8
@@
xsetsel(char *str, Time t) {
sel.primary = str;
XSetSelectionOwner(xw.dpy, XA_PRIMARY, xw.win, t);
sel.primary = str;
XSetSelectionOwner(xw.dpy, XA_PRIMARY, xw.win, t);
-
if (XGetSelectionOwner(xw.dpy, XA_PRIMARY) != xw.win)
- selclear(0);
+ if (XGetSelectionOwner(xw.dpy, XA_PRIMARY) != xw.win)
+
selclear(0);
}
void
}
void
@@
-1142,13
+1146,12
@@
brelease(XEvent *e) {
if(e->xbutton.button == Button2) {
selpaste(NULL);
} else if(e->xbutton.button == Button1) {
if(e->xbutton.button == Button2) {
selpaste(NULL);
} else if(e->xbutton.button == Button1) {
- if(sel.mode < 2) {
- selclear(NULL);
- } else {
+ if(sel.mode == SEL_READY) {
getbuttoninfo(e);
selcopy(e->xbutton.time);
getbuttoninfo(e);
selcopy(e->xbutton.time);
- }
- sel.mode = 0;
+ } else
+ selclear(NULL);
+ sel.mode = SEL_IDLE;
tsetdirt(sel.nb.y, sel.ne.y);
}
}
tsetdirt(sel.nb.y, sel.ne.y);
}
}
@@
-1165,7
+1168,7
@@
bmotion(XEvent *e) {
if(!sel.mode)
return;
if(!sel.mode)
return;
- sel.mode
++
;
+ sel.mode
= SEL_READY
;
oldey = sel.oe.y;
oldex = sel.oe.x;
oldsby = sel.nb.y;
oldey = sel.oe.y;
oldex = sel.oe.x;
oldsby = sel.nb.y;