diff options
| author | noname <noname@inventati.org> | 2014-04-27 15:40:23 +0400 |
|---|---|---|
| committer | Roberto E. Vargas Caballero <k0ga@shike2.com> | 2014-04-28 18:38:07 +0200 |
| commit | 74962bf56636e608f0ee35f2076bc6b48923119d (patch) | |
| tree | 6c8ce174b1dd99758779dd432e9beaa84ff31852 | |
| parent | 6681af165b06c32cf65bf970a295600d46cb7025 (diff) | |
| download | st-74962bf56636e608f0ee35f2076bc6b48923119d.tar.gz st-74962bf56636e608f0ee35f2076bc6b48923119d.zip | |
Remove one indentation level in getsel().
| -rw-r--r-- | st.c | 91 |
1 files changed, 45 insertions, 46 deletions
| @@ -922,60 +922,59 @@ getsel(void) { | |||
| 922 | int x, y, bufsize, size, i, ex; | 922 | int x, y, bufsize, size, i, ex; |
| 923 | Glyph *gp, *last; | 923 | Glyph *gp, *last; |
| 924 | 924 | ||
| 925 | if(sel.ob.x == -1) { | 925 | if(sel.ob.x == -1) |
| 926 | str = NULL; | 926 | return NULL; |
| 927 | } else { | ||
| 928 | bufsize = (term.col+1) * (sel.ne.y-sel.nb.y+1) * UTF_SIZ; | ||
| 929 | ptr = str = xmalloc(bufsize); | ||
| 930 | 927 | ||
| 931 | /* append every set & selected glyph to the selection */ | 928 | bufsize = (term.col+1) * (sel.ne.y-sel.nb.y+1) * UTF_SIZ; |
| 932 | for(y = sel.nb.y; y < sel.ne.y + 1; y++) { | 929 | ptr = str = xmalloc(bufsize); |
| 933 | gp = &term.line[y][0]; | ||
| 934 | last = &gp[term.col-1]; | ||
| 935 | 930 | ||
| 936 | while(last >= gp && !(selected(last - gp, y) && | 931 | /* append every set & selected glyph to the selection */ |
| 937 | strcmp(last->c, " ") != 0)) { | 932 | for(y = sel.nb.y; y < sel.ne.y + 1; y++) { |
| 938 | --last; | 933 | gp = &term.line[y][0]; |
| 939 | } | 934 | last = &gp[term.col-1]; |
| 940 | 935 | ||
| 941 | for(x = 0; gp <= last; x++, ++gp) { | 936 | while(last >= gp && !(selected(last - gp, y) && |
| 942 | if(!selected(x, y) || (gp->mode & ATTR_WDUMMY)) | 937 | strcmp(last->c, " ") != 0)) { |
| 943 | continue; | 938 | --last; |
| 939 | } | ||
| 944 | 940 | ||
| 945 | size = utf8len(gp->c); | 941 | for(x = 0; gp <= last; x++, ++gp) { |
| 946 | memcpy(ptr, gp->c, size); | 942 | if(!selected(x, y) || (gp->mode & ATTR_WDUMMY)) |
| 947 | ptr += size; | 943 | continue; |
| 948 | } | ||
| 949 | 944 | ||
| 950 | /* | 945 | size = utf8len(gp->c); |
| 951 | * Copy and pasting of line endings is inconsistent | 946 | memcpy(ptr, gp->c, size); |
| 952 | * in the inconsistent terminal and GUI world. | 947 | ptr += size; |
| 953 | * The best solution seems like to produce '\n' when | 948 | } |
| 954 | * something is copied from st and convert '\n' to | ||
| 955 | * '\r', when something to be pasted is received by | ||
| 956 | * st. | ||
| 957 | * FIXME: Fix the computer world. | ||
| 958 | */ | ||
| 959 | if(y < sel.ne.y && x > 0 && !((gp-1)->mode & ATTR_WRAP)) | ||
| 960 | *ptr++ = '\n'; | ||
| 961 | 949 | ||
| 962 | /* | 950 | /* |
| 963 | * If the last selected line expands in the selection | 951 | * Copy and pasting of line endings is inconsistent |
| 964 | * after the visible text '\n' is appended. | 952 | * in the inconsistent terminal and GUI world. |
| 965 | */ | 953 | * The best solution seems like to produce '\n' when |
| 966 | if(y == sel.ne.y) { | 954 | * something is copied from st and convert '\n' to |
| 967 | i = term.col; | 955 | * '\r', when something to be pasted is received by |
| 968 | while(--i > 0 && term.line[y][i].c[0] == ' ') | 956 | * st. |
| 969 | /* nothing */; | 957 | * FIXME: Fix the computer world. |
| 970 | ex = sel.ne.x; | 958 | */ |
| 971 | if(sel.nb.y == sel.ne.y && sel.ne.x < sel.nb.x) | 959 | if(y < sel.ne.y && x > 0 && !((gp-1)->mode & ATTR_WRAP)) |
| 972 | ex = sel.nb.x; | 960 | *ptr++ = '\n'; |
| 973 | if(i < ex) | 961 | |
| 974 | *ptr++ = '\n'; | 962 | /* |
| 975 | } | 963 | * If the last selected line expands in the selection |
| 964 | * after the visible text '\n' is appended. | ||
| 965 | */ | ||
| 966 | if(y == sel.ne.y) { | ||
| 967 | i = term.col; | ||
| 968 | while(--i > 0 && term.line[y][i].c[0] == ' ') | ||
| 969 | /* nothing */; | ||
| 970 | ex = sel.ne.x; | ||
| 971 | if(sel.nb.y == sel.ne.y && sel.ne.x < sel.nb.x) | ||
| 972 | ex = sel.nb.x; | ||
| 973 | if(i < ex) | ||
| 974 | *ptr++ = '\n'; | ||
| 976 | } | 975 | } |
| 977 | *ptr = 0; | ||
| 978 | } | 976 | } |
| 977 | *ptr = 0; | ||
| 979 | return str; | 978 | return str; |
| 980 | } | 979 | } |
| 981 | 980 | ||
