]> Sergey Matveev's repositories - st.git/commitdiff
line_snap_delimiter patch line_snap_delimiter
authorSergey Matveev <stargrave@stargrave.org>
Mon, 10 Jan 2022 11:32:00 +0000 (14:32 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sun, 6 Nov 2022 12:27:15 +0000 (15:27 +0300)
config.def.h
st.c
st.h

index 8d49106cc7267a076eb797afd82ef18ea64e13aa..f86667ebd529d4ddc2fc066bdea21a2b35efaa2b 100644 (file)
@@ -35,6 +35,7 @@ static float chscale = 1.0;
  * More advanced example: L" `'\"()[]{}"
  */
 wchar_t *worddelimiters = L" ";
+wchar_t *snap_line_delimiters = L"│";
 
 /* selection timeouts (in milliseconds) */
 static unsigned int doubleclicktimeout = 300;
diff --git a/st.c b/st.c
index 62def59f17cbf1bfd841210453ba29e5578d5610..2e85b84df31233b81f703f0a45a6f695877a408c 100644 (file)
--- a/st.c
+++ b/st.c
@@ -42,6 +42,7 @@
 #define ISCONTROLC1(c)         (BETWEEN(c, 0x80, 0x9f))
 #define ISCONTROL(c)           (ISCONTROLC0(c) || ISCONTROLC1(c))
 #define ISDELIM(u)             (u && wcschr(worddelimiters, u))
+#define IS_SNAP_LINE_DELIM(u) (u && wcschr(snap_line_delimiters, u))
 
 enum term_mode {
        MODE_WRAP        = 1 << 0,
@@ -556,12 +557,31 @@ selsnap(int *x, int *y, int direction)
                }
                break;
        case SNAP_LINE:
+               /*
+                * Don't snap past a line snap delimiter
+                * (see 'snap_line_delimiters' in config.h)
+                */
+               for(;;) {
+                       newx = *x + direction;
+
+                       if (!BETWEEN(newx, 0, term.col - 1)) {
+                               break;
+                       }
+
+                       gp = &term.line[*y][newx];
+
+                       if(IS_SNAP_LINE_DELIM(gp->u)) {
+                               break;
+                       }
+
+                       *x = newx;
+               }
+
                /*
                 * Snap around if the the previous line or the current one
                 * has set ATTR_WRAP at its end. Then the whole next or
                 * previous line will be selected.
                 */
-               *x = (direction < 0) ? 0 : term.col - 1;
                if (direction < 0) {
                        for (; *y > 0; *y += direction) {
                                if (!(term.line[*y-1][term.col-1].mode
diff --git a/st.h b/st.h
index fd3b0d8501e71a08cc7718be0a670510c3fa60e5..c4b993071e9c7aba3a8ec678217e80cba1573b1b 100644 (file)
--- a/st.h
+++ b/st.h
@@ -117,6 +117,7 @@ extern char *scroll;
 extern char *stty_args;
 extern char *vtiden;
 extern wchar_t *worddelimiters;
+extern wchar_t *snap_line_delimiters;
 extern int allowaltscreen;
 extern int allowwindowops;
 extern char *termname;