billiob pushed a commit to branch master.

commit 9d000c7c1dfa63fa65bc1b25468bd81f45f47708
Author: Boris Faure <[email protected]>
Date:   Mon Aug 26 20:44:46 2013 +0200

    fix word selection on multiple lines. Closes T305
---
 src/bin/termio.c  | 106 +++++++++++++++++++++++++++++++++++++++++-------------
 src/bin/termpty.c |   2 +-
 2 files changed, 82 insertions(+), 26 deletions(-)

diff --git a/src/bin/termio.c b/src/bin/termio.c
index a921847..b9cfb6e 100644
--- a/src/bin/termio.c
+++ b/src/bin/termio.c
@@ -2286,47 +2286,103 @@ _sel_word(Evas_Object *obj, int cx, int cy)
 {
    Termio *sd = evas_object_smart_data_get(obj);
    Termcell *cells;
-   int x, w = 0;
+   int x, y, w = 0;
+   Eina_Bool done = EINA_FALSE;
+
    if (!sd) return;
 
    termpty_cellcomp_freeze(sd->pty);
-   cells = termpty_cellrow_get(sd->pty, cy, &w);
-   if (!cells)
-     {
-        termpty_cellcomp_thaw(sd->pty);
-        return;
-     }
+
    sd->cur.sel = 1;
    sd->cur.makesel = 0;
    sd->cur.sel1.x = cx;
    sd->cur.sel1.y = cy;
-   for (x = sd->cur.sel1.x; x >= 0; x--)
+   sd->cur.sel2.x = cx;
+   sd->cur.sel2.y = cy;
+   x = sd->cur.sel1.x;
+   y = cy;
+   cells = termpty_cellrow_get(sd->pty, y, &w);
+   if (!cells) goto end;
+   if (x >= w) x = w - 1;
+
+   do
      {
+        for (; x >= 0; x--)
+          {
 #if defined(SUPPORT_DBLWIDTH)
-        if ((cells[x].codepoint == 0) && (cells[x].att.dblwidth) &&
-            (x > 0))
-          x--;
+             if ((cells[x].codepoint == 0) && (cells[x].att.dblwidth) &&
+                 (x > 0))
+               x--;
 #endif
-        if (x >= w) break;
-        if (_codepoint_is_wordsep(sd->config, cells[x].codepoint)) break;
-        sd->cur.sel1.x = x;
+             if (_codepoint_is_wordsep(sd->config, cells[x].codepoint))
+               {
+                  done = EINA_TRUE;
+                  break;
+               }
+             sd->cur.sel1.x = x;
+             sd->cur.sel1.y = y;
+          }
+        if (!done)
+          {
+             Termcell *old_cells = cells;
+
+             cells = termpty_cellrow_get(sd->pty, y - 1, &w);
+             if (!cells || !cells[w-1].att.autowrapped)
+               {
+                  x = 0;
+                  cells = old_cells;
+                  done = EINA_TRUE;
+               }
+             else
+               {
+                  y--;
+                  x = w - 1;
+               }
+          }
      }
-   sd->cur.sel2.x = cx;
-   sd->cur.sel2.y = cy;
-   for (x = sd->cur.sel2.x; x < sd->grid.w; x++)
+   while (!done);
+
+   done = EINA_FALSE;
+   if (cy != y)
      {
-#if defined(SUPPORT_DBLWIDTH)
-        if ((cells[x].codepoint == 0) && (cells[x].att.dblwidth) &&
-            (x < (sd->grid.w - 1)))
+        y = cy;
+        cells = termpty_cellrow_get(sd->pty, y, &w);
+        if (!cells) goto end;
+     }
+   x = sd->cur.sel2.x;
+
+   do
+     {
+        for (; x < w; x++)
           {
+#if defined(SUPPORT_DBLWIDTH)
+             if ((cells[x].codepoint == 0) && (cells[x].att.dblwidth) &&
+                 (x < (w - 1)))
+               {
+                  sd->cur.sel2.x = x;
+                  x++;
+               }
+#endif
+             if (_codepoint_is_wordsep(sd->config, cells[x].codepoint))
+               {
+                  done = EINA_TRUE;
+                  break;
+               }
              sd->cur.sel2.x = x;
-             x++;
+             sd->cur.sel2.y = y;
+          }
+        if (!done)
+          {
+             if (!cells[w - 1].att.autowrapped) goto end;
+             y++;
+             x = 0;
+             cells = termpty_cellrow_get(sd->pty, y, &w);
+             if (!cells) goto end;
           }
-#endif
-        if (x >= w) break;
-        if (_codepoint_is_wordsep(sd->config, cells[x].codepoint)) break;
-        sd->cur.sel2.x = x;
      }
+   while (!done);
+
+  end:
    termpty_cellcomp_thaw(sd->pty);
 }
 
diff --git a/src/bin/termpty.c b/src/bin/termpty.c
index 18c9ef8..efed38b 100644
--- a/src/bin/termpty.c
+++ b/src/bin/termpty.c
@@ -504,7 +504,7 @@ termpty_cellrow_get(Termpty *ty, int y, int *wret)
        /* fprintf(stderr, "getting: %i (%i, %i)\n", y, ty->circular_offset, 
ty->h); */
         return &(TERMPTY_SCREEN(ty, 0, y));
      }
-   if (y < -ty->backmax) return NULL;
+   if ((y < -ty->backmax) || !ty->back) return NULL;
    tssrc = &(ty->back[(ty->backmax + ty->backpos + y) % ty->backmax]);
    ts = termpty_save_extract(*tssrc);
    if (!ts) return NULL;

-- 

------------------------------------------------------------------------------
Introducing Performance Central, a new site from SourceForge and 
AppDynamics. Performance Central is your source for news, insights, 
analysis and resources for efficient Application Performance Management. 
Visit us today!
http://pubads.g.doubleclick.net/gampad/clk?id=48897511&iu=/4140/ostg.clktrk

Reply via email to