billiob pushed a commit to branch master.

http://git.enlightenment.org/apps/terminology.git/commit/?id=6957ecb642e86f15bcc022a709d0b28e2be2ccbc

commit 6957ecb642e86f15bcc022a709d0b28e2be2ccbc
Author: Boris Faure <[email protected]>
Date:   Thu Nov 17 23:30:57 2016 +0100

    link detection: rewrite moving around the grid
    
    There are difference between the grid and the backlog.
    In the backlog, full lines are stored (and thus can be larger than the
    width of the terminal).
---
 src/bin/termiolink.c | 90 ++++++++++++++++++++++++++++++++++------------------
 1 file changed, 59 insertions(+), 31 deletions(-)

diff --git a/src/bin/termiolink.c b/src/bin/termiolink.c
index a69c7d6..c1f88f5 100644
--- a/src/bin/termiolink.c
+++ b/src/bin/termiolink.c
@@ -74,7 +74,7 @@ _txt_at(Termpty *ty, int *x, int *y, char *txt, int *txtlenp)
    if (!cells || !w)
      goto bad;
    if ((*x >= w))
-     *x = w-1;
+     goto empty;
    cell = cells[*x];
    if ((cell.codepoint == 0) && (cell.att.dblwidth))
      {
@@ -85,15 +85,15 @@ _txt_at(Termpty *ty, int *x, int *y, char *txt, int 
*txtlenp)
      }
 
    if (cell.codepoint == 0)
-     {
+     goto empty;
+
+   *txtlenp = codepoint_to_utf8(cell.codepoint, txt);
+
+   return 0;
+
+empty:
         txt[0] = '\0';
         *txtlenp = 0;
-     }
-   else
-     {
-        *txtlenp = codepoint_to_utf8(cell.codepoint, txt);
-     }
-
    return 0;
 
 bad:
@@ -111,14 +111,32 @@ _txt_prev_at(Termpty *ty, int *x, int *y, char *txt, int 
*txtlenp)
 
    (*x)--;
    if ((*x) < 0)
+     {
         (*y)--;
-   cells = termpty_cellrow_get(ty, *y, &w);
-   if (!cells || !w)
-     goto bad;
-   if (((*x) < 0) || ((*x) >= w))
-     *x = w-1;
+        *x = ty->w-1;
+        cells = termpty_cellrow_get(ty, *y, &w);
+        if (!cells || !w)
+          goto bad;
+        if ((*x) >= w)
+          goto empty;
+        cell = cells[*x];
+        /* Either the cell is in the normal screen and needs to have
+         * autowrapped flag or is in the backlog and its length is larger than
+         * the screen, spanning multiple lines */
+        if (((!cell.att.autowrapped) && (*y) >= 0)
+            || (w < ty->w))
+          goto empty;
+     }
+   else
+     {
+        cells = termpty_cellrow_get(ty, *y, &w);
+        if (!cells || !w)
+          goto bad;
+        if ((*x) >= w)
+          goto empty;
 
-   cell = cells[*x];
+        cell = cells[*x];
+     }
    if ((cell.codepoint == 0) && (cell.att.dblwidth))
      {
         (*x)--;
@@ -128,17 +146,17 @@ _txt_prev_at(Termpty *ty, int *x, int *y, char *txt, int 
*txtlenp)
      }
 
    if (cell.codepoint == 0)
-     {
-        txt[0] = '\0';
-        *txtlenp = 0;
-     }
-   else
-     {
-        *txtlenp = codepoint_to_utf8(cell.codepoint, txt);
-     }
+     goto empty;
+
+   *txtlenp = codepoint_to_utf8(cell.codepoint, txt);
 
    return 0;
 
+empty:
+   txt[0] = '\0';
+   *txtlenp = 0;
+   return 0;
+
 bad:
    *txtlenp = 0;
    txt[0] = '\0';
@@ -156,9 +174,16 @@ _txt_next_at(Termpty *ty, int *x, int *y, char *txt, int 
*txtlenp)
    cells = termpty_cellrow_get(ty, *y, &w);
    if (!cells || !w)
      goto bad;
-   if (*x >= w)
+   if ((*x) >= w)
      {
         (*y)++;
+        if ((*x) <= ty->w)
+          {
+             cell = cells[w-1];
+             if (!cell.att.autowrapped)
+               goto empty;
+          }
+
         *x = 0;
         cells = termpty_cellrow_get(ty, *y, &w);
         if (!cells || !w)
@@ -171,6 +196,9 @@ _txt_next_at(Termpty *ty, int *x, int *y, char *txt, int 
*txtlenp)
         (*x)++;
         if (*x >= w)
           {
+             cell = cells[w-1];
+             if (!cell.att.autowrapped && w == ty->w)
+               goto empty;
              (*y)++;
              *x = 0;
              cells = termpty_cellrow_get(ty, *y, &w);
@@ -182,15 +210,15 @@ _txt_next_at(Termpty *ty, int *x, int *y, char *txt, int 
*txtlenp)
 
    cell = cells[*x];
    if (cell.codepoint == 0)
-     {
-        txt[0] = '\0';
-        *txtlenp = 0;
-     }
-   else
-     {
-        *txtlenp = codepoint_to_utf8(cell.codepoint, txt);
-     }
+     goto empty;
+
+   *txtlenp = codepoint_to_utf8(cell.codepoint, txt);
+
+   return 0;
 
+empty:
+   txt[0] = '\0';
+   *txtlenp = 0;
    return 0;
 
 bad:

-- 


Reply via email to