summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2015-01-18 19:29:39 +0100
committerBoris Faure <billiob@gmail.com>2015-01-30 00:24:55 +0100
commite94051dd86fde0eb13993c32a99cb463b8a5b724 (patch)
tree4bf4cc88028a4fd6c9036045d3d48331bce4f625 /src
parent87d653ea4d2718038e1094542072143cc9704a71 (diff)
make selection consistent when selecting space with no text. Closes T2013
Diffstat (limited to 'src')
-rw-r--r--src/bin/termio.c53
-rw-r--r--src/bin/termpty.c68
-rw-r--r--src/bin/termpty.h1
3 files changed, 78 insertions, 44 deletions
diff --git a/src/bin/termio.c b/src/bin/termio.c
index 933c79c..35cc726 100644
--- a/src/bin/termio.c
+++ b/src/bin/termio.c
@@ -2794,34 +2794,39 @@ static void
2794_selection_newline_extend_fix(Evas_Object *obj) 2794_selection_newline_extend_fix(Evas_Object *obj)
2795{ 2795{
2796 Termio *sd; 2796 Termio *sd;
2797 ssize_t w;
2797 2798
2798 sd = evas_object_smart_data_get(obj); 2799 sd = evas_object_smart_data_get(obj);
2799 if ((!sd->top_left) && (sd->pty->selection.end.y >= sd->pty->selection.start.y)) 2800
2801 if ((sd->top_left) || (sd->bottom_right))
2802 return;
2803
2804 termpty_cellcomp_freeze(sd->pty);
2805
2806 if ((sd->pty->selection.end.y > sd->pty->selection.start.y) ||
2807 ((sd->pty->selection.end.y == sd->pty->selection.start.y) &&
2808 (sd->pty->selection.end.x > sd->pty->selection.start.x)))
2800 { 2809 {
2801 if (((sd->pty->selection.start.y == sd->pty->selection.end.y) && 2810 /* going down/right */
2802 (sd->pty->selection.start.x <= sd->pty->selection.end.x)) || 2811 w = termpty_row_length(sd->pty, sd->pty->selection.start.y);
2803 (sd->pty->selection.start.y < sd->pty->selection.end.y)) 2812 if (w < sd->pty->selection.start.x)
2804 { 2813 sd->pty->selection.start.x = w;
2805 char *lastline; 2814 w = termpty_row_length(sd->pty, sd->pty->selection.end.y);
2806 int x1, y1, x2, y2; 2815 if (w <= sd->pty->selection.end.x)
2807 size_t len; 2816 sd->pty->selection.end.x = sd->pty->w;
2808 2817 }
2809 if (sd->pty->selection.start.y == sd->pty->selection.end.y) x1 = sd->pty->selection.start.x; 2818 else
2810 else x1 = 0; 2819 {
2811 x2 = sd->pty->selection.end.x; 2820 /* going up/left */
2812 y1 = y2 = sd->pty->selection.end.y; 2821 w = termpty_row_length(sd->pty, sd->pty->selection.end.y);
2813 lastline = termio_selection_get(obj, x1, y1, x2, y2, &len); 2822 if (w < sd->pty->selection.end.x)
2814 if (lastline) 2823 sd->pty->selection.end.x = w;
2815 { 2824 w = termpty_row_length(sd->pty, sd->pty->selection.start.y);
2816 if ((len > 0) && (lastline[len - 1] == '\n')) 2825 if (w <= sd->pty->selection.start.x)
2817 { 2826 sd->pty->selection.start.x = sd->pty->w;
2818 sd->pty->selection.end.x = sd->grid.w - 1;
2819 _selection_dbl_fix(obj);
2820 }
2821 free(lastline);
2822 }
2823 }
2824 } 2827 }
2828
2829 termpty_cellcomp_thaw(sd->pty);
2825} 2830}
2826 2831
2827/* }}} */ 2832/* }}} */
diff --git a/src/bin/termpty.c b/src/bin/termpty.c
index 7a3d710..63d2c7b 100644
--- a/src/bin/termpty.c
+++ b/src/bin/termpty.c
@@ -580,6 +580,50 @@ termpty_cellcomp_thaw(Termpty *ty EINA_UNUSED)
580 termpty_save_thaw(); 580 termpty_save_thaw();
581} 581}
582 582
583ssize_t
584termpty_line_length(const Termcell *cells, ssize_t nb_cells)
585{
586 ssize_t len = nb_cells;
587
588 for (len = nb_cells - 1; len >= 0; len--)
589 {
590 const Termcell *cell = cells + len;
591
592 if ((cell->codepoint != 0) &&
593 (cell->att.bg != COL_INVIS))
594 return len + 1;
595 }
596
597 return 0;
598}
599
600ssize_t
601termpty_row_length(Termpty *ty, int y)
602{
603 Termsave *ts;
604
605 if (y >= 0)
606 {
607 Termcell *cells;
608 if (y >= ty->h)
609 {
610 ERR("invalid row given");
611 return 0;
612 }
613 cells = &(TERMPTY_SCREEN(ty, 0, y));
614 return termpty_line_length(cells, ty->w);
615 }
616 if ((y < -ty->backmax) || !ty->back)
617 {
618 ERR("invalid row given");
619 return 0;
620 }
621 ts = ty->back[(ty->backmax + ty->backpos + y) % ty->backmax];
622 if (!ts) return 0;
623
624 return ts->comp ? ((Termsavecomp*)ts)->wout : ts->w;
625}
626
583Termcell * 627Termcell *
584termpty_cellrow_get(Termpty *ty, int y, int *wret) 628termpty_cellrow_get(Termpty *ty, int y, int *wret)
585{ 629{
@@ -587,10 +631,11 @@ termpty_cellrow_get(Termpty *ty, int y, int *wret)
587 631
588 if (y >= 0) 632 if (y >= 0)
589 { 633 {
634 Termcell *cells;
590 if (y >= ty->h) return NULL; 635 if (y >= ty->h) return NULL;
591 *wret = ty->w; 636 cells = &(TERMPTY_SCREEN(ty, 0, y));
592 /* fprintf(stderr, "getting: %i (%i, %i)\n", y, ty->circular_offset, ty->h); */ 637 *wret = termpty_line_length(cells, ty->w);
593 return &(TERMPTY_SCREEN(ty, 0, y)); 638 return cells;
594 } 639 }
595 if ((y < -ty->backmax) || !ty->back) return NULL; 640 if ((y < -ty->backmax) || !ty->back) return NULL;
596 tssrc = &(ty->back[(ty->backmax + ty->backpos + y) % ty->backmax]); 641 tssrc = &(ty->back[(ty->backmax + ty->backpos + y) % ty->backmax]);
@@ -610,23 +655,6 @@ termpty_write(Termpty *ty, const char *input, int len)
610 ty->fd, strerror(errno)); 655 ty->fd, strerror(errno));
611} 656}
612 657
613ssize_t
614termpty_line_length(const Termcell *cells, ssize_t nb_cells)
615{
616 ssize_t len = nb_cells;
617
618 for (len = nb_cells - 1; len >= 0; len--)
619 {
620 const Termcell *cell = cells + len;
621
622 if ((cell->codepoint != 0) &&
623 (cell->att.bg != COL_INVIS))
624 return len + 1;
625 }
626
627 return 0;
628}
629
630static int 658static int
631termpty_line_find_top(Termpty *ty, int y_end, int *top) 659termpty_line_find_top(Termpty *ty, int y_end, int *top)
632{ 660{
diff --git a/src/bin/termpty.h b/src/bin/termpty.h
index f245bc6..f8361d5 100644
--- a/src/bin/termpty.h
+++ b/src/bin/termpty.h
@@ -226,6 +226,7 @@ void termpty_free(Termpty *ty);
226void termpty_cellcomp_freeze(Termpty *ty); 226void termpty_cellcomp_freeze(Termpty *ty);
227void termpty_cellcomp_thaw(Termpty *ty); 227void termpty_cellcomp_thaw(Termpty *ty);
228Termcell *termpty_cellrow_get(Termpty *ty, int y, int *wret); 228Termcell *termpty_cellrow_get(Termpty *ty, int y, int *wret);
229ssize_t termpty_row_length(Termpty *ty, int y);
229void termpty_write(Termpty *ty, const char *input, int len); 230void termpty_write(Termpty *ty, const char *input, int len);
230void termpty_resize(Termpty *ty, int w, int h); 231void termpty_resize(Termpty *ty, int w, int h);
231void termpty_backscroll_set(Termpty *ty, int size); 232void termpty_backscroll_set(Termpty *ty, int size);