[hackers][patch] Introduce SEL_LINES to mouse-select linewise

From: Julian Prein <druckdev_AT_protonmail.com>
Date: Tue, 18 Oct 2022 14:33:28 +0000

Hi,

This patch adds a new selection type to mouse-select linewise.

I am unsure if the patch touches too much, but I noticed both "extras"
while writing this patch, and they seemed too small for separate
patches:

The missing enumerator for 0 in the selection_snap enum seemed like a
good idea without disadvantage.

I added the hint to forcemousemod as it made my life harder first when
trying to use the ShiftMask in selmasks (To have bindings closer to
vim).

If they are unwanted, please tell me and I will remove them or split the
patch.

Julian

-- >8 --

Use sel.snap to implement a new selection type SEL_LINES. With it the
mouse selection can be done linewise, similar to vim's linewise visual
mode. Also add a default mask for it to selmasks.

Add a hint to forcemousemod above the definition of selmasks.

Introduce SNAP_NONE to the selection_snap enum that encodes 0. Change
all hard-coded uses of it.
---
 config.def.h | 3 ++-
 st.c         | 9 +++++++--
 st.h         | 4 +++-
 x.c          | 2 +-
 4 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/config.def.h b/config.def.h
index 91ab8cab2c70..bbac6bccd1c7 100644
--- a/config.def.h
+++ b/config.def.h
_AT_@ -459,3 +459,3 @@ static Key key[] = {
  * Button1Mask is always unset, to make masks match between ButtonPress.
- * ButtonRelease and MotionNotify.
+ * ButtonRelease and MotionNotify. forcemousemod is always unset too.
  * If no match is found, regular selection is used.
_AT_@ -464,2 +464,3 @@ static uint selmasks[] = {
 	[SEL_RECTANGULAR] = Mod1Mask,
+	[SEL_LINES] = Mod1Mask | ControlMask,
 };
diff --git a/st.c b/st.c
index 62def59f17cb..31705d21718d 100644
--- a/st.c
+++ b/st.c
_AT_@ -402,3 +402,3 @@ selinit(void)
 	sel.mode = SEL_IDLE;
-	sel.snap = 0;
+	sel.snap = SNAP_NONE;
 	sel.ob.x = -1;
_AT_@ -432,3 +432,3 @@ selstart(int col, int row, int snap)
 
-	if (sel.snap != 0)
+	if (sel.snap != SNAP_NONE)
 		sel.mode = SEL_READY;
_AT_@ -455,2 +455,7 @@ selextend(int col, int row, int type, int done)
 
+	if (type == SEL_LINES)
+		sel.snap = SNAP_LINE;
+	else
+		sel.snap = SNAP_NONE;
+
 	sel.oe.x = col;
diff --git a/st.h b/st.h
index fd3b0d8501e7..bb19480532ff 100644
--- a/st.h
+++ b/st.h
_AT_@ -46,3 +46,4 @@ enum selection_type {
 	SEL_REGULAR = 1,
-	SEL_RECTANGULAR = 2
+	SEL_RECTANGULAR = 2,
+	SEL_LINES = 3
 };
_AT_@ -50,2 +51,3 @@ enum selection_type {
 enum selection_snap {
+	SNAP_NONE = 0,
 	SNAP_WORD = 1,
diff --git a/x.c b/x.c
index 2a3bd384c465..4133a169bfc2 100644
--- a/x.c
+++ b/x.c
_AT_@ -496,3 +496,3 @@ bpress(XEvent *e)
 		} else {
-			snap = 0;
+			snap = SNAP_NONE;
 		}
-- 
2.38.0



Received on Tue Oct 18 2022 - 16:33:28 CEST

This archive was generated by hypermail 2.3.0 : Tue Oct 18 2022 - 16:36:37 CEST