summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2015-08-16 21:40:58 +0200
committerBoris Faure <billiob@gmail.com>2015-08-16 21:40:58 +0200
commit716cb03b5b6a2bdba2a913ba3a2f6df9fc8793d1 (patch)
treeb5c8d29557adaeafc53bbe3e04c0070fa620ba8e /src
parent8e8207dae1e2fc9195de5c97041d5d44629b702a (diff)
fix small issue on word selection and simplify code
Diffstat (limited to 'src')
-rw-r--r--src/bin/termio.c113
1 files changed, 54 insertions, 59 deletions
diff --git a/src/bin/termio.c b/src/bin/termio.c
index c92fd6e..69eaf1b 100644
--- a/src/bin/termio.c
+++ b/src/bin/termio.c
@@ -2769,7 +2769,7 @@ _codepoint_is_wordsep(const Eina_Unicode g)
2769 return EINA_FALSE; 2769 return EINA_FALSE;
2770} 2770}
2771 2771
2772Eina_Bool 2772static Eina_Bool
2773_to_trim(Eina_Unicode codepoint) 2773_to_trim(Eina_Unicode codepoint)
2774{ 2774{
2775 static const Eina_Unicode trim_chars[] = 2775 static const Eina_Unicode trim_chars[] =
@@ -2779,83 +2779,78 @@ _to_trim(Eina_Unicode codepoint)
2779 '>', 2779 '>',
2780 '.' 2780 '.'
2781 }; 2781 };
2782 int i = 0; 2782 size_t i = 0, len;
2783 size_t len;
2784 len = sizeof(trim_chars)/sizeof((trim_chars)[0]); 2783 len = sizeof(trim_chars)/sizeof((trim_chars)[0]);
2785 2784
2786 for (i == 0; i < len; i++) 2785 for (i = 0; i < len; i++)
2787 if (codepoint == trim_chars[i]) 2786 if (codepoint == trim_chars[i])
2788 return EINA_TRUE; 2787 return EINA_TRUE;
2789 return EINA_FALSE; 2788 return EINA_FALSE;
2790} 2789}
2791 2790
2792static void 2791static void
2793_trim_sel_word(Termio *sd, int w) 2792_trim_sel_word(Termio *sd)
2794{ 2793{
2794 Termpty *pty = sd->pty;
2795 Termcell *cells; 2795 Termcell *cells;
2796 int start = 0, end = 0, line = 0, k = 0; 2796 int start = 0, end = 0, y = 0;
2797 if (sd->pty->selection.start.y != sd->pty->selection.end.y) 2797 ssize_t w;
2798 {
2799 start = sd->pty->selection.start.x;
2800 end = sd->pty->selection.end.x;
2801 k = sd->pty->selection.end.y - sd->pty->selection.start.y;
2802 for (; k >= 0; k--)
2803 {
2804 line = sd->pty->selection.start.y;
2805 cells = termpty_cellrow_get(sd->pty, line, &w);
2806
2807 while (_to_trim(cells[start].codepoint)) start++;
2808 2798
2809 if (start >= w) 2799 /* 1st step: trim from the start */
2810 { 2800 start = pty->selection.start.x;
2811 start = 0; 2801 for (y = pty->selection.start.y;
2812 sd->pty->selection.start.y += 1; 2802 y <= pty->selection.end.y;
2813 } 2803 y++)
2814 2804 {
2815 if (sd->pty->selection.start.y == sd->pty->selection.end.y) 2805 cells = termpty_cellrow_get(pty, y, &w);
2816 {
2817 start = 0;
2818 line = sd->pty->selection.start.y;
2819 cells = termpty_cellrow_get(sd->pty, line, &w);
2820 while (_to_trim(cells[start].codepoint)) start++;
2821 while (_to_trim(cells[end].codepoint)) end--;
2822 break;
2823 }
2824 }
2825 sd->pty->selection.start.x = start;
2826 2806
2827 start = sd->pty->selection.start.x; 2807 while (start < w && _to_trim(cells[start].codepoint))
2828 end = sd->pty->selection.end.x; 2808 start++;
2829 k = sd->pty->selection.end.y;
2830 for (; k >= sd->pty->selection.start.y; k--)
2831 {
2832 line = sd->pty->selection.end.y;
2833 cells = termpty_cellrow_get(sd->pty, line, &w);
2834 2809
2835 while (_to_trim(cells[end].codepoint)) end--; 2810 if (start < w)
2811 break;
2836 2812
2837 if (end <= 0) 2813 start = 0;
2838 {
2839 end = w;
2840 sd->pty->selection.end.y -= 1;
2841 }
2842 }
2843 sd->pty->selection.end.x = end;
2844 } 2814 }
2845 else 2815 /* check validy of the selection */
2816 if ((y > pty->selection.end.y) ||
2817 ((y == pty->selection.end.y) &&
2818 (start >= pty->selection.end.x)))
2846 { 2819 {
2847 line = sd->pty->selection.start.y; 2820 pty->selection.start.y = pty->selection.start.y;
2848 start = sd->pty->selection.start.x; 2821 pty->selection.start.x = pty->selection.end.x;
2849 end = sd->pty->selection.end.x; 2822 return;
2823 }
2824 pty->selection.start.y = y;
2825 pty->selection.start.x = start;
2850 2826
2851 cells = termpty_cellrow_get(sd->pty, line, &w); 2827 /* 2nd step: trim from the end */
2828 end = pty->selection.end.x;
2829 for (y = pty->selection.end.y;
2830 y >= pty->selection.start.y;
2831 y--)
2832 {
2833 cells = termpty_cellrow_get(pty, y, &w);
2852 2834
2853 while (_to_trim(cells[start].codepoint)) start++; 2835 while (end >= 0 && _to_trim(cells[end].codepoint))
2854 while (_to_trim(cells[end].codepoint)) end--; 2836 end--;
2855 2837
2856 sd->pty->selection.start.x = start; 2838 if (end >= 0)
2857 sd->pty->selection.end.x = end; 2839 break;
2840 }
2841 if (end < 0)
2842 return;
2843 /* check validy of the selection */
2844 if ((y < pty->selection.start.y) ||
2845 ((y == pty->selection.start.y) &&
2846 (end < pty->selection.start.x)))
2847 {
2848 pty->selection.end.x = pty->selection.end.x;
2849 pty->selection.end.y = pty->selection.start.y;
2850 return;
2858 } 2851 }
2852 pty->selection.end.x = end;
2853 pty->selection.end.y = y;
2859} 2854}
2860 2855
2861static void 2856static void
@@ -2972,9 +2967,9 @@ _sel_word(Termio *sd, int cx, int cy)
2972 2967
2973 end: 2968 end:
2974 2969
2975 _trim_sel_word(sd, w);
2976 sd->pty->selection.by_word = EINA_TRUE; 2970 sd->pty->selection.by_word = EINA_TRUE;
2977 sd->pty->selection.is_top_to_bottom = EINA_TRUE; 2971 sd->pty->selection.is_top_to_bottom = EINA_TRUE;
2972 _trim_sel_word(sd);
2978 2973
2979 termpty_backlog_unlock(); 2974 termpty_backlog_unlock();
2980} 2975}