Fossil SCM
/chat: when submitting a message, trim trailing whitespace from all input lines in order to keep pasted-in text from consoles, especially wide ones, from forcing horizontal scrollbars on all clients to due long runs of blanks at the end of each line. Sidebar: this is incompatible with markdown-formatted text which makes use of lines ending with whitespace for continuation of multi-paragraph list entries.
Commit
afaffb66dff556527666b4f9c8517ed62a86f33bd268bd1957e6e2f3b4d049d1
Parent
966305b26489072…
1 file changed
+21
-3
+21
-3
| --- src/chat.js | ||
| +++ src/chat.js | ||
| @@ -870,17 +870,35 @@ | ||
| 870 | 870 | return [ |
| 871 | 871 | d.getYear()+1900, '-', pad2(d.getMonth()+1), '-', pad2(d.getDate()), |
| 872 | 872 | 'T', pad2(d.getHours()),':', pad2(d.getMinutes()),':',pad2(d.getSeconds()) |
| 873 | 873 | ].join(''); |
| 874 | 874 | }; |
| 875 | - | |
| 876 | - Chat.submitMessage = function(){ | |
| 875 | + | |
| 876 | + /** | |
| 877 | + Submits the contents of the message input field (if not empty) | |
| 878 | + and/or the file attachment field to the server. If both are | |
| 879 | + empty, this is a no-op. | |
| 880 | + */ | |
| 881 | + Chat.submitMessage = function f(){ | |
| 882 | + if(!f.spaces){ | |
| 883 | + f.spaces = /\s+$/; | |
| 884 | + } | |
| 877 | 885 | const fd = new FormData(this.e.inputForm) |
| 878 | 886 | /* ^^^^ we don't really want/need the FORM element, but when |
| 879 | 887 | FormData() is default-constructed here then the server |
| 880 | 888 | segfaults, and i have no clue why! */; |
| 881 | - const msg = this.inputValue().trim(); | |
| 889 | + var msg = this.inputValue().trim(); | |
| 890 | + if(msg && (msg.indexOf('\n')>0 || f.spaces.test(msg))){ | |
| 891 | + /* Cosmetic: trim whitespace from the ends of lines to try to | |
| 892 | + keep copy/paste from terminals, especially wide ones, from | |
| 893 | + forcing a horizontal scrollbar on all clients. */ | |
| 894 | + const xmsg = msg.split('\n'); | |
| 895 | + xmsg.forEach(function(line,ndx){ | |
| 896 | + xmsg[ndx] = line.trimRight(); | |
| 897 | + }); | |
| 898 | + msg = xmsg.join('\n'); | |
| 899 | + } | |
| 882 | 900 | if(msg) fd.set('msg',msg); |
| 883 | 901 | const file = BlobXferState.blob || this.e.inputFile.files[0]; |
| 884 | 902 | if(file) fd.set("file", file); |
| 885 | 903 | if( !msg && !file ) return; |
| 886 | 904 | const self = this; |
| 887 | 905 |
| --- src/chat.js | |
| +++ src/chat.js | |
| @@ -870,17 +870,35 @@ | |
| 870 | return [ |
| 871 | d.getYear()+1900, '-', pad2(d.getMonth()+1), '-', pad2(d.getDate()), |
| 872 | 'T', pad2(d.getHours()),':', pad2(d.getMinutes()),':',pad2(d.getSeconds()) |
| 873 | ].join(''); |
| 874 | }; |
| 875 | |
| 876 | Chat.submitMessage = function(){ |
| 877 | const fd = new FormData(this.e.inputForm) |
| 878 | /* ^^^^ we don't really want/need the FORM element, but when |
| 879 | FormData() is default-constructed here then the server |
| 880 | segfaults, and i have no clue why! */; |
| 881 | const msg = this.inputValue().trim(); |
| 882 | if(msg) fd.set('msg',msg); |
| 883 | const file = BlobXferState.blob || this.e.inputFile.files[0]; |
| 884 | if(file) fd.set("file", file); |
| 885 | if( !msg && !file ) return; |
| 886 | const self = this; |
| 887 |
| --- src/chat.js | |
| +++ src/chat.js | |
| @@ -870,17 +870,35 @@ | |
| 870 | return [ |
| 871 | d.getYear()+1900, '-', pad2(d.getMonth()+1), '-', pad2(d.getDate()), |
| 872 | 'T', pad2(d.getHours()),':', pad2(d.getMinutes()),':',pad2(d.getSeconds()) |
| 873 | ].join(''); |
| 874 | }; |
| 875 | |
| 876 | /** |
| 877 | Submits the contents of the message input field (if not empty) |
| 878 | and/or the file attachment field to the server. If both are |
| 879 | empty, this is a no-op. |
| 880 | */ |
| 881 | Chat.submitMessage = function f(){ |
| 882 | if(!f.spaces){ |
| 883 | f.spaces = /\s+$/; |
| 884 | } |
| 885 | const fd = new FormData(this.e.inputForm) |
| 886 | /* ^^^^ we don't really want/need the FORM element, but when |
| 887 | FormData() is default-constructed here then the server |
| 888 | segfaults, and i have no clue why! */; |
| 889 | var msg = this.inputValue().trim(); |
| 890 | if(msg && (msg.indexOf('\n')>0 || f.spaces.test(msg))){ |
| 891 | /* Cosmetic: trim whitespace from the ends of lines to try to |
| 892 | keep copy/paste from terminals, especially wide ones, from |
| 893 | forcing a horizontal scrollbar on all clients. */ |
| 894 | const xmsg = msg.split('\n'); |
| 895 | xmsg.forEach(function(line,ndx){ |
| 896 | xmsg[ndx] = line.trimRight(); |
| 897 | }); |
| 898 | msg = xmsg.join('\n'); |
| 899 | } |
| 900 | if(msg) fd.set('msg',msg); |
| 901 | const file = BlobXferState.blob || this.e.inputFile.files[0]; |
| 902 | if(file) fd.set("file", file); |
| 903 | if( !msg && !file ) return; |
| 904 | const self = this; |
| 905 |