diff options
Diffstat (limited to 'st.c')
| -rw-r--r-- | st.c | 35 |
1 files changed, 31 insertions, 4 deletions
| @@ -788,9 +788,18 @@ selcopy(void) { | |||
| 788 | memcpy(ptr, p, size); | 788 | memcpy(ptr, p, size); |
| 789 | ptr += size; | 789 | ptr += size; |
| 790 | } | 790 | } |
| 791 | /* \n at the end of every selected line except for the last one */ | 791 | |
| 792 | /* | ||
| 793 | * Copy and pasting of line endings is inconsistent | ||
| 794 | * in the inconsistent terminal and GUI world. | ||
| 795 | * The best solution seems like to produce '\n' when | ||
| 796 | * something is copied from st and convert '\n' to | ||
| 797 | * '\r', when something to be pasted is received by | ||
| 798 | * st. | ||
| 799 | * FIXME: Fix the computer world. | ||
| 800 | */ | ||
| 792 | if(is_selected && y < sel.e.y) | 801 | if(is_selected && y < sel.e.y) |
| 793 | *ptr++ = '\r'; | 802 | *ptr++ = '\n'; |
| 794 | } | 803 | } |
| 795 | *ptr = 0; | 804 | *ptr = 0; |
| 796 | } | 805 | } |
| @@ -801,7 +810,7 @@ void | |||
| 801 | selnotify(XEvent *e) { | 810 | selnotify(XEvent *e) { |
| 802 | ulong nitems, ofs, rem; | 811 | ulong nitems, ofs, rem; |
| 803 | int format; | 812 | int format; |
| 804 | uchar *data; | 813 | uchar *data, *last, *repl; |
| 805 | Atom type; | 814 | Atom type; |
| 806 | 815 | ||
| 807 | ofs = 0; | 816 | ofs = 0; |
| @@ -812,7 +821,25 @@ selnotify(XEvent *e) { | |||
| 812 | fprintf(stderr, "Clipboard allocation failed\n"); | 821 | fprintf(stderr, "Clipboard allocation failed\n"); |
| 813 | return; | 822 | return; |
| 814 | } | 823 | } |
| 815 | ttywrite((const char *) data, nitems * format / 8); | 824 | |
| 825 | /* | ||
| 826 | * As seen in selcopy: | ||
| 827 | * Line endings are inconsistent in the terminal and GUI world | ||
| 828 | * copy and pasting. When receiving some selection data, | ||
| 829 | * replace all '\n' with '\r'. | ||
| 830 | * FIXME: Fix the computer world. | ||
| 831 | */ | ||
| 832 | repl = data; | ||
| 833 | last = data + nitems * format / 8; | ||
| 834 | while((repl = memchr(repl, '\n', last - repl))) { | ||
| 835 | *repl++ = '\r'; | ||
| 836 | } | ||
| 837 | |||
| 838 | last = data + nitems * format / 8; | ||
| 839 | repl = data; | ||
| 840 | |||
| 841 | |||
| 842 | ttywrite((const char *)data, nitems * format / 8); | ||
| 816 | XFree(data); | 843 | XFree(data); |
| 817 | /* number of 32-bit chunks returned */ | 844 | /* number of 32-bit chunks returned */ |
| 818 | ofs += nitems * format / 32; | 845 | ofs += nitems * format / 32; |
