Bug 121149 - message is sent when pasteing text containing a newline
Summary: message is sent when pasteing text containing a newline
Status: RESOLVED FIXED
Alias: None
Product: konversation
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: ---
Assignee: Konversation Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-02-01 14:22 UTC by Jan Braunisch
Modified: 2006-10-08 21:16 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Braunisch 2006-02-01 14:22:03 UTC
Version:            (using KDE Devel)
Installed from:    Compiled sources

When I paste text containing one ore more newlines into the input line, the message is sent without me pressing enter.

Solution:

Only send message when user presses enter.
This would also be nice:
Replace newline with some character that shown where the newlines are when pasteing into the input line, and convert back when sending message.

I am using konversation 0.19.
Comment 1 Dario Abatianni 2006-02-01 22:26:56 UTC
Please make sure that you have not switched off the question for multiline pastes in the warnings dialog panel, because konversation is supposed to warn you if you want to paste messages with newlines in them.

Please reopen this bug if your settings are correct and the problem still persists.
Comment 2 Jan Braunisch 2006-02-01 22:45:10 UTC
IMO, a message should NEVER be sent without me pressing enter.

My suggested solution is the same as xchat has, not with an annoying dialog letting me edit the text. I discussed this with JohnFlux and he said he would try to implement it using a pilcrow (ΒΆ) character.
Comment 3 Eike Hein 2006-02-01 22:49:10 UTC
Personally, I prefer the multi-line paste editor. 

As for the codepath that does not use it, we were recently discussing an optional grow-as-necessary multi-line input box, and I would prefer that to a codepath that replaces newline characters with a pilcrow.
Comment 4 argonel 2006-08-27 09:13:54 UTC
SVN commit 577598 by argonel:

-prevent pasted text with leading newlines from being sent directly to the server
-retain original text when cancelling from the paste editor
-prevent text pasted via keyboard from being sent to the server when cancelling from the paste editor

CCBUG:121149


 M  +1 -1      commit.h  
 M  +21 -22    ircinput.cpp  


--- trunk/extragear/network/konversation/src/commit.h #577597:577598
@@ -1,4 +1,4 @@
 // This COMMIT number is added to version string to be used as "patch level"
 #ifndef COMMIT
-#define COMMIT 3145
+#define COMMIT 3146
 #endif
--- trunk/extragear/network/konversation/src/ircinput.cpp #577597:577598
@@ -371,8 +371,6 @@
 
 void IRCInput::paste()
 {
-
-    kdDebug() << "paste()" << endl;
     QClipboard *cb = KApplication::kApplication()->clipboard();
     setFocus();
 
@@ -395,12 +393,21 @@
         emit endCompletion();
 
         bool signal=false;
+
         // replace \r with \n to make xterm pastes happy
         pasteText.replace("\r","\n");
+        // remove blank lines
+        while(pasteText.contains("\n\n"))
+            pasteText.replace("\n\n","\n");
 
-        //  remove all trailing newlines
-        pasteText.replace(QRegExp("\n+$"),"");
+        QRegExp reTopSpace("^ *\n");
+        while(pasteText.contains(reTopSpace))
+            pasteText.remove(reTopSpace);
 
+        QRegExp reBottomSpace("\n *$");
+        while(pasteText.contains(reBottomSpace))
+            pasteText.remove(reBottomSpace);
+
         // does the text contain at least one newline character?
         if(pasteText.find('\n')!=-1)
         {
@@ -409,15 +416,15 @@
             unsigned int rpos=pasteText.findRev('\n');
 
             // emit the signal if there's a line break in the middle of the text
-            if(pos>0 && pos!=(pasteText.length()-1)) signal=true;
+            if(pos>0 && pos!=(pasteText.length()-1))
+                signal=true;
             // emit the signal if there's more than one line break in the text
-            if(pos!=rpos) signal=true;
+            if(pos!=rpos)
+                signal=true;
 
             // Remove the \n from end of the line if there's only one \n
             if(!signal)
-            {
                 pasteText.remove('\n');
-            }
         }
         else
         {
@@ -454,18 +461,7 @@
 {
     int doPaste=KMessageBox::Yes;
 
-    // Don't use QString::stripWhiteSpace() because it deletes spaces in the first line too.
-    // remove waste spaces (including LF)
-    QRegExp reTopSpace("^ *\n");
-    while(text.contains(reTopSpace))
-        text.remove(reTopSpace);
-    QRegExp reBottomSpace("\n *$");
-    while(text.contains(reBottomSpace))
-        text.remove(reBottomSpace);
-    // remove blank lines
-    while(text.contains("\n\n"))
-        text.replace("\n\n","\n");
-
+    //text is now preconditioned when you get here
     int lines=text.contains('\n');
 
     if(text.length()>256 || lines)
@@ -483,8 +479,11 @@
 
     if (doPaste==KMessageBox::No)
     {
-        text=MultilineEdit::edit(this,text);
-        return true;
+        QString ret(MultilineEdit::edit(this,text));
+        if (ret.isEmpty())
+            return false;
+        text=ret;
+        return false;
     }
 
     return (doPaste==KMessageBox::Yes);
Comment 5 Eike Hein 2006-10-08 21:16:21 UTC
*** Bug has been marked as fixed ***.