summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2013-08-26 20:44:46 +0200
committerBoris Faure <billiob@gmail.com>2013-08-26 20:44:46 +0200
commit9d000c7c1dfa63fa65bc1b25468bd81f45f47708 (patch)
treeead712caa6d5dda08abcf4fac797a0908a386a20
parent58ec67bfa21b1cb2997f411f578987f261d52781 (diff)
fix word selection on multiple lines. Closes T305
-rw-r--r--src/bin/termio.c106
-rw-r--r--src/bin/termpty.c2
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)
2286{ 2286{
2287 Termio *sd = evas_object_smart_data_get(obj); 2287 Termio *sd = evas_object_smart_data_get(obj);
2288 Termcell *cells; 2288 Termcell *cells;
2289 int x, w = 0; 2289 int x, y, w = 0;
2290 Eina_Bool done = EINA_FALSE;
2291
2290 if (!sd) return; 2292 if (!sd) return;
2291 2293
2292 termpty_cellcomp_freeze(sd->pty); 2294 termpty_cellcomp_freeze(sd->pty);
2293 cells = termpty_cellrow_get(sd->pty, cy, &w); 2295
2294 if (!cells)
2295 {
2296 termpty_cellcomp_thaw(sd->pty);
2297 return;
2298 }
2299 sd->cur.sel = 1; 2296 sd->cur.sel = 1;
2300 sd->cur.makesel = 0; 2297 sd->cur.makesel = 0;
2301 sd->cur.sel1.x = cx; 2298 sd->cur.sel1.x = cx;
2302 sd->cur.sel1.y = cy; 2299 sd->cur.sel1.y = cy;
2303 for (x = sd->cur.sel1.x; x >= 0; x--) 2300 sd->cur.sel2.x = cx;
2301 sd->cur.sel2.y = cy;
2302 x = sd->cur.sel1.x;
2303 y = cy;
2304 cells = termpty_cellrow_get(sd->pty, y, &w);
2305 if (!cells) goto end;
2306 if (x >= w) x = w - 1;
2307
2308 do
2304 { 2309 {
2310 for (; x >= 0; x--)
2311 {
2305#if defined(SUPPORT_DBLWIDTH) 2312#if defined(SUPPORT_DBLWIDTH)
2306 if ((cells[x].codepoint == 0) && (cells[x].att.dblwidth) && 2313 if ((cells[x].codepoint == 0) && (cells[x].att.dblwidth) &&
2307 (x > 0)) 2314 (x > 0))
2308 x--; 2315 x--;
2309#endif 2316#endif
2310 if (x >= w) break; 2317 if (_codepoint_is_wordsep(sd->config, cells[x].codepoint))
2311 if (_codepoint_is_wordsep(sd->config, cells[x].codepoint)) break; 2318 {
2312 sd->cur.sel1.x = x; 2319 done = EINA_TRUE;
2320 break;
2321 }
2322 sd->cur.sel1.x = x;
2323 sd->cur.sel1.y = y;
2324 }
2325 if (!done)
2326 {
2327 Termcell *old_cells = cells;
2328
2329 cells = termpty_cellrow_get(sd->pty, y - 1, &w);
2330 if (!cells || !cells[w-1].att.autowrapped)
2331 {
2332 x = 0;
2333 cells = old_cells;
2334 done = EINA_TRUE;
2335 }
2336 else
2337 {
2338 y--;
2339 x = w - 1;
2340 }
2341 }
2313 } 2342 }
2314 sd->cur.sel2.x = cx; 2343 while (!done);
2315 sd->cur.sel2.y = cy; 2344
2316 for (x = sd->cur.sel2.x; x < sd->grid.w; x++) 2345 done = EINA_FALSE;
2346 if (cy != y)
2317 { 2347 {
2318#if defined(SUPPORT_DBLWIDTH) 2348 y = cy;
2319 if ((cells[x].codepoint == 0) && (cells[x].att.dblwidth) && 2349 cells = termpty_cellrow_get(sd->pty, y, &w);
2320 (x < (sd->grid.w - 1))) 2350 if (!cells) goto end;
2351 }
2352 x = sd->cur.sel2.x;
2353
2354 do
2355 {
2356 for (; x < w; x++)
2321 { 2357 {
2358#if defined(SUPPORT_DBLWIDTH)
2359 if ((cells[x].codepoint == 0) && (cells[x].att.dblwidth) &&
2360 (x < (w - 1)))
2361 {
2362 sd->cur.sel2.x = x;
2363 x++;
2364 }
2365#endif
2366 if (_codepoint_is_wordsep(sd->config, cells[x].codepoint))
2367 {
2368 done = EINA_TRUE;
2369 break;
2370 }
2322 sd->cur.sel2.x = x; 2371 sd->cur.sel2.x = x;
2323 x++; 2372 sd->cur.sel2.y = y;
2373 }
2374 if (!done)
2375 {
2376 if (!cells[w - 1].att.autowrapped) goto end;
2377 y++;
2378 x = 0;
2379 cells = termpty_cellrow_get(sd->pty, y, &w);
2380 if (!cells) goto end;
2324 } 2381 }
2325#endif
2326 if (x >= w) break;
2327 if (_codepoint_is_wordsep(sd->config, cells[x].codepoint)) break;
2328 sd->cur.sel2.x = x;
2329 } 2382 }
2383 while (!done);
2384
2385 end:
2330 termpty_cellcomp_thaw(sd->pty); 2386 termpty_cellcomp_thaw(sd->pty);
2331} 2387}
2332 2388
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)
504 /* fprintf(stderr, "getting: %i (%i, %i)\n", y, ty->circular_offset, ty->h); */ 504 /* fprintf(stderr, "getting: %i (%i, %i)\n", y, ty->circular_offset, ty->h); */
505 return &(TERMPTY_SCREEN(ty, 0, y)); 505 return &(TERMPTY_SCREEN(ty, 0, y));
506 } 506 }
507 if (y < -ty->backmax) return NULL; 507 if ((y < -ty->backmax) || !ty->back) return NULL;
508 tssrc = &(ty->back[(ty->backmax + ty->backpos + y) % ty->backmax]); 508 tssrc = &(ty->back[(ty->backmax + ty->backpos + y) % ty->backmax]);
509 ts = termpty_save_extract(*tssrc); 509 ts = termpty_save_extract(*tssrc);
510 if (!ts) return NULL; 510 if (!ts) return NULL;