GNOME Bugzilla – Bug 760497
Pasting text should remove newlines at front/end of text
Last modified: 2016-02-09 19:57:14 UTC
To reproduce: 1. Bug Andre 2. Go to https://www.brussels-city-shuttle.com/en/tickets 3. Copy "Online from 5 € to max. 14 € per person (no handling fee)" 4. Try to past this Actual results: A. Polari suggests to use public paste server B. Say paste C. Open link (https://paste.gnome.org/ppvr11b5e) D. Copy text again, minus the newlines E. Paste again F. Works Wanted results: A. Pastes 3 lines of text, no newlines
Created attachment 320245 [details] [review] pasteManager: trimmed the text that is to be pasted Trimming of the text is necessary to prevent unwanted newlines being sent. The problem is that when the user selects a multiline text and wants to paste it in the chatEntry, the pasteManeger takes care of sending the actual message to gnome pastebin. The fix is to trim the text just before calling the Utils.gpaste method from utils.js. A problem that may arise is that the user still gets prompted with a message length that may be greater than the one actually being sent. Another possible fix, that also fixes the length with the issue, would be to trim the text and adjust the length before emitting the 'test-pasted' signal, in the vfunc_paste_clipboard function located in entryArea.js.
Makes more sense to trim it before calling the pasteManager function.
(In reply to Kunaal Jain from comment #2) > Makes more sense to trim it before calling the pasteManager function. I agree. It's not just that the number of lines we report to the user may be wrong - having that in the signal is just a minor optimization to not compute the value twice, which we could remove again. We may also trigger the paste service unnecessarily - think of the extreme case of pasting five empty lines.
Created attachment 320269 [details] [review] entryArea: message is trimmed just before it is pasted In commit 270cae6, the same bug was fixed, but the trimming was not done in the right place. The problem was that the above mentioned commit trimmed the text later than it should have. The fix is that the trimming process is done as soon as possible, thus making it possible for the correct number of pasted lines to be shown. Note that a message composed of multiple newlines does not get sent to gnome pastebin, but it is pasted as it is and it gets sent right away, just like a normal written message.
Rares the patch you mentioned in commit doesn't exist. Secondly, please rebase your patch on master branch, not on your previous commit :)
Sorry. I will push another patch soon :D
Created attachment 320286 [details] [review] entryArea: message is trimmed just before it is pasted Trimming of the text is necessary to prevent unwanted newlines being sent. The problem is that when the user selects a multiline (greater than a maximum limit, currently set to 5 by default) text and wants to paste it in the chatEntry, the pasteManager takes care of sending the actual message to gnome pastebin. The fix is to trim the text right after it is retrieved from the clipboard, thus making sure that no useless newlines will be sent to gnome pastebin.
Looks good to me :) Though I think there is no need of extra line after text.trim(). Florian, Bastian will do the review :) Commit message should be something like : "entryArea: Trim extra lines spaces in pasted text Remove extra lines and space before/after the pasted text to prevent unwanted spaces/lines being sent/pasted."
Review of attachment 320286 [details] [review]: (In reply to Kunaal Jain from comment #8) > Looks good to me :) Dto. > Commit message should be something like : > > "entryArea: Trim extra lines spaces in pasted text > > Remove extra lines and space before/after the pasted text to prevent > unwanted spaces/lines being sent/pasted." Yeah. I'm quite fond of detailed commit messages, but I don't think we need it to be that lengthy. The interesting bit is to mention why we trim the text (for anyone who stumbles upon the code and wonders why it's there), not necessarily why it's exactly in that place.
Should i modify "Trimming of the text is necessary to prevent unwanted newlines being sent." into something else? Or any other part?
Created attachment 320736 [details] [review] entryArea: Trim newline(s)/space(s) in pasted text Remove extra newlines or spaces surrounding the pasted text to prevent unwanted newlines/spaces from being pasted and sent to pastebin. Unnecessary whitespaces around the selected text are not useful and they usually appear as an odd behaviour when selecting multiline text from webpages.
Created attachment 320737 [details] [review] entryArea: Trim newline(s)/space(s) in pasted text Remove extra newlines or spaces surrounding the pasted text to prevent unwanted newlines/spaces from being pasted and sent to pastebin. Unnecessary whitespace around the selected text are not useful and they usually appear as an odd behaviour when selecting multiline text from webpages.
Created attachment 320739 [details] [review] entryArea: Trim newline(s)/space(s) in pasted text Remove extra newlines or spaces surrounding the pasted text to prevent unwanted newlines/spaces from being pasted and sent to pastebin. Unnecessary whitespace around the selected text is not useful and it usually appears as an odd behaviour when selecting multiline text from webpages.
Attachment 320739 [details] pushed as 165c6fb - entryArea: Trim newline(s)/space(s) in pasted text