A new user interface for you! Read more...

File kde4-kdebase-bug-188528.patch of Package konsole

--- src/EditProfileDialog.cpp.orig	2011-11-17 21:57:16.000000000 +0100
+++ src/EditProfileDialog.cpp	2012-08-31 08:19:03.480631038 +0200
@@ -1133,6 +1133,8 @@ void EditProfileDialog::setupAdvancedPag
                                  SLOT(toggleBlinkingCursor(bool)) },
                                { _ui->underlineLinksButton , Profile::UnderlineLinksEnabled,
                                  SLOT(toggleUnderlineLinks(bool)) },
+                               { _ui->trimTrailingSpacesButton , Profile::TrimTrailingSpacesInSelectedText,
+                                 SLOT(toggleTrimTrailingSpacesInSelectedText(bool)) },
                                { _ui->enableBidiRenderingButton , Profile::BidiRenderingEnabled ,
                                  SLOT(togglebidiRendering(bool)) },
                                { 0 , Profile::Property(0) , 0 }
@@ -1235,6 +1237,10 @@ void EditProfileDialog::toggleResizeWind
 {
     updateTempProfileProperty(Profile::AllowProgramsToResizeWindow,enable);
 }
+void EditProfileDialog::toggleTrimTrailingSpacesInSelectedText(bool enable)
+{
+    updateTempProfileProperty(Profile::TrimTrailingSpacesInSelectedText, enable);
+}
 void EditProfileDialog::fontSelected(const QFont& font)
 {
     QFont previewFont = font;
--- src/EditProfileDialog.h.orig	2011-11-17 21:57:16.000000000 +0100
+++ src/EditProfileDialog.h	2012-08-31 08:19:53.140010214 +0200
@@ -168,6 +168,7 @@ private slots:
     void toggleBlinkingCursor(bool);
     void TripleClickModeChanged(int);
     void toggleUnderlineLinks(bool);
+    void toggleTrimTrailingSpacesInSelectedText(bool);
 
     void setCursorShape(int);
     void autoCursorColor();
--- src/EditProfileDialog.ui.orig	2011-10-11 16:45:42.000000000 +0200
+++ src/EditProfileDialog.ui	2012-08-31 08:23:36.188221727 +0200
@@ -1083,6 +1083,16 @@
             </property>
            </widget>
           </item>
+          <item>
+           <widget class="QCheckBox" name="trimTrailingSpacesButton">
+            <property name="toolTip">
+             <string>Trim trailing spaces in selected text, useful in some editors</string>
+            </property>
+            <property name="text">
+             <string>Trim trailing spaces</string>
+            </property>
+           </widget>
+          </item>
          </layout>
         </widget>
        </item>
--- src/Profile.cpp.orig	2012-01-18 19:49:29.000000000 +0100
+++ src/Profile.cpp	2012-08-31 08:25:11.366031842 +0200
@@ -116,6 +116,7 @@ const Profile::PropertyInfo Profile::Def
     , { WordCharacters , "WordCharacters" , INTERACTION_GROUP , QVariant::String }
     , { TripleClickMode , "TripleClickMode" , INTERACTION_GROUP , QVariant::Int }
     , { UnderlineLinksEnabled , "UnderlineLinksEnabled" , INTERACTION_GROUP , QVariant::Bool }
+    , { TrimTrailingSpacesInSelectedText , "TrimTrailingSpacesInSelectedText" , INTERACTION_GROUP , QVariant::Bool }
 
     // Encoding
     , { DefaultEncoding , "DefaultEncoding" , ENCODING_GROUP , QVariant::String }
@@ -181,6 +182,7 @@ FallbackProfile::FallbackProfile()
     setProperty(BlinkingTextEnabled,true);
     setProperty(UnderlineLinksEnabled,true);
     setProperty(TripleClickMode,SelectWholeLine);
+    setProperty(TrimTrailingSpacesInSelectedText, false);
 
     setProperty(BlinkingCursorEnabled,false);
     setProperty(BidiRenderingEnabled,true);
--- src/Profile.h.orig	2011-11-17 21:57:16.000000000 +0100
+++ src/Profile.h	2012-08-31 08:27:20.434418263 +0200
@@ -183,6 +183,8 @@ public:
          * hovered by the mouse pointer.
          */
         UnderlineLinksEnabled,
+        /** (bool) If true, trailing spaces are trimmed in selected text */
+        TrimTrailingSpacesInSelectedText,
         /** (String) Default text codec */
         DefaultEncoding,
         /** (bool) Whether fonts should be aliased or not */
--- src/ScreenWindow.cpp.orig	2011-11-17 21:57:16.000000000 +0100
+++ src/ScreenWindow.cpp	2012-08-31 08:41:24.850081175 +0200
@@ -115,9 +115,9 @@ QVector<LineProperty> ScreenWindow::getL
     return result;
 }
 
-QString ScreenWindow::selectedText( bool preserveLineBreaks ) const
+QString ScreenWindow::selectedText( bool preserveLineBreaks, bool trimTrailingSpaces ) const
 {
-    return _screen->selectedText( preserveLineBreaks );
+    return _screen->selectedText( preserveLineBreaks, trimTrailingSpaces );
 }
 
 void ScreenWindow::getSelectionStart( int& column , int& line )
--- src/ScreenWindow.h.orig	2011-11-17 21:57:16.000000000 +0100
+++ src/ScreenWindow.h	2012-08-31 08:50:31.537613317 +0200
@@ -224,8 +224,9 @@ public:
      * Returns the text which is currently selected.
      *
      * @param preserveLineBreaks See Screen::selectedText()
+     * @param trimTrailingSpaces See Screen::selectedText()
      */
-    QString selectedText( bool preserveLineBreaks ) const;
+    QString selectedText( bool preserveLineBreaks, bool trimTrailingSpaces = false ) const;
 
 public slots:
     /**
--- src/TerminalDisplay.cpp.orig	2012-06-01 14:31:52.000000000 +0200
+++ src/TerminalDisplay.cpp	2012-08-31 09:01:04.091035912 +0200
@@ -318,6 +318,7 @@ TerminalDisplay::TerminalDisplay(QWidget
 ,_cursorShape(BlockCursor)
 ,_antialiasText(true)
 ,_sessionController(0)
+, _trimTrailingSpaces(false)
 {
   // terminal applications are not designed with Right-To-Left in mind,
   // so the layout is forced to Left-To-Right
@@ -2218,7 +2219,7 @@ void TerminalDisplay::mouseReleaseEvent(
     {
       if ( _actSel > 1 )
       {
-          setXSelection(  _screenWindow->selectedText(_preserveLineBreaks)  );
+          setXSelection(  _screenWindow->selectedText(_preserveLineBreaks, _trimTrailingSpaces)  );
       }
 
       _actSel = 0;
@@ -2362,7 +2363,7 @@ void TerminalDisplay::mouseDoubleClickEv
 
      _screenWindow->setSelectionEnd( endSel.x() , endSel.y() );
 
-     setXSelection( _screenWindow->selectedText(_preserveLineBreaks) ); 
+     setXSelection( _screenWindow->selectedText(_preserveLineBreaks, _trimTrailingSpaces) ); 
    }
 
   _possibleTripleClick=true;
--- src/TerminalDisplay.h.orig	2012-04-02 13:28:40.000000000 +0200
+++ src/TerminalDisplay.h	2012-08-31 11:58:25.556279976 +0200
@@ -193,6 +193,16 @@ public:
      */
     bool getUnderlineLinks() const { return _underlineLinks; }
 
+    /**
+     * Sets whether trailing spaces should be trimmed in selected text.
+     */
+    void setTrimTrailingSpaces(bool enabled) { _trimTrailingSpaces = enabled; }
+
+    /**
+     * Returns true if trailing spaces should be trimmed in selected text.
+     */
+    bool trimTrailingSpaces() const { return _trimTrailingSpaces; }
+
     void setLineSpacing(uint);
     uint lineSpacing() const;
 
@@ -828,6 +838,8 @@ private:
 
     SessionController* _sessionController;
 
+    bool _trimTrailingSpaces; // trim trailing spaces in selected text
+
 public:
     static void setTransparencyEnabled(bool enable)
     {
--- src/ViewManager.cpp.orig	2011-11-17 21:57:16.000000000 +0100
+++ src/ViewManager.cpp	2012-08-31 09:02:05.329270331 +0200
@@ -864,6 +864,8 @@ void ViewManager::applyProfileToView(Ter
 
     view->setUnderlineLinks(profile->property<bool>(Profile::UnderlineLinksEnabled));
 
+    view->setTrimTrailingSpaces(profile->property<bool>(Profile::TrimTrailingSpacesInSelectedText));
+
     bool bidiEnabled = profile->property<bool>(Profile::BidiRenderingEnabled);
     view->setBidiEnabled(bidiEnabled);
 
--- src/Screen.cpp.orig	2011-12-02 22:31:44.000000000 +0100
+++ src/Screen.cpp	2012-08-31 08:36:28.027791965 +0200
@@ -1142,14 +1142,14 @@ bool Screen::isSelected( const int x,con
     return pos >= selTopLeft && pos <= selBottomRight && columnInSelection;
 }
 
-QString Screen::selectedText(bool preserveLineBreaks) const
+QString Screen::selectedText(bool preserveLineBreaks, bool trimTrailingSpaces) const
 {
     QString result;
     QTextStream stream(&result, QIODevice::ReadWrite);
 
     PlainTextDecoder decoder;
     decoder.begin(&stream);
-    writeSelectionToStream(&decoder , preserveLineBreaks);
+    writeSelectionToStream(&decoder , preserveLineBreaks, trimTrailingSpaces);
     decoder.end();
 
     return result;
@@ -1161,16 +1161,18 @@ bool Screen::isSelectionValid() const
 }
 
 void Screen::writeSelectionToStream(TerminalCharacterDecoder* decoder , 
-        bool preserveLineBreaks) const
+        bool preserveLineBreaks,
+        bool trimTrailingSpaces) const
 {
     if (!isSelectionValid())
         return;
-    writeToStream(decoder,selTopLeft,selBottomRight,preserveLineBreaks);
+    writeToStream(decoder,selTopLeft,selBottomRight,preserveLineBreaks, trimTrailingSpaces);
 }
 
 void Screen::writeToStream(TerminalCharacterDecoder* decoder, 
         int startIndex, int endIndex,
-        bool preserveLineBreaks) const
+        bool preserveLineBreaks,
+        bool trimTrailingSpaces) const
 {
     int top = startIndex / columns;    
     int left = startIndex % columns;
@@ -1194,7 +1196,8 @@ void Screen::writeToStream(TerminalChara
                 count,
                 decoder, 
                 appendNewLine,
-                preserveLineBreaks );
+                preserveLineBreaks,
+                trimTrailingSpaces );
 
         // if the selection goes beyond the end of the last line then
         // append a new line character.
@@ -1215,7 +1218,8 @@ int Screen::copyLineToStream(int line ,
         int count,
         TerminalCharacterDecoder* decoder,
         bool appendNewLine,
-        bool preserveLineBreaks) const
+        bool preserveLineBreaks,
+        bool trimTrailingSpaces) const
 {
     //buffer to hold characters for decoding
     //the buffer is static to avoid initialising every 
@@ -1270,6 +1274,19 @@ int Screen::copyLineToStream(int line ,
         Character* data = screenLines[screenLine].data();
         int length = screenLines[screenLine].count();
 
+        // Don't remove end spaces in lines that wrap
+        if (trimTrailingSpaces && !(lineProperties[screenLine] & LINE_WRAPPED))
+        {
+            // ignore trailing white space at the end of the line
+            for (int i = length-1; i >= 0; i--)
+            {
+                if (data[i].character == ' ')
+                    length--;
+                else
+                    break;
+            }
+        }
+
         //retrieve line from screen image
         for (int i=start;i < qMin(start+count,length);i++)
         {
--- src/Screen.h.orig	2011-11-17 21:57:16.000000000 +0100
+++ src/Screen.h	2012-08-31 08:40:23.456848697 +0200
@@ -445,8 +445,10 @@ public:
      * Convenience method.  Returns the currently selected text.
      * @param preserveLineBreaks Specifies whether new line characters should
      * be inserted into the returned text at the end of each terminal line.
+     * @param trimTrailingSpaces Specifies whether trailing spaces should be
+     * trimmed in the returned text.
      */
-    QString selectedText(bool preserveLineBreaks) const;
+    QString selectedText(bool preserveLineBreaks, bool trimTrailingSpaces = false) const;
 
     /**
      * Copies part of the output to a stream.
@@ -466,9 +468,12 @@ public:
      * into plain text with no formatting.
      * @param preserveLineBreaks Specifies whether new line characters should
      * be inserted into the returned text at the end of each terminal line.
+     * @param trimTrailingSpaces Specifies whether trailing spaces should be
+     * trimmed in the returned text.
      */
     void writeSelectionToStream(TerminalCharacterDecoder* decoder , bool
-                                preserveLineBreaks = true) const;
+                                preserveLineBreaks = true,
+                                bool trimTrailingSpaces = false) const;
 
     /**
      * Checks if the text between from and to is inside the current
@@ -594,7 +599,8 @@ private:
                           int count, 
                           TerminalCharacterDecoder* decoder,
                           bool appendNewLine,
-                          bool preserveLineBreaks) const;
+                          bool preserveLineBreaks,
+                          bool trimTrailingSpaces) const;
 
     //fills a section of the screen image with the character 'c'
     //the parameters are specified as offsets from the start of the screen image.
@@ -626,7 +632,7 @@ private:
     // copies text from 'startIndex' to 'endIndex' to a stream
     // startIndex and endIndex are positions generated using the loc(x,y) macro
     void writeToStream(TerminalCharacterDecoder* decoder, int startIndex, 
-                       int endIndex, bool preserveLineBreaks = true) const;
+                       int endIndex, bool preserveLineBreaks = true, bool trimTrailingSpaces = false) const;
     // copies 'count' lines from the screen buffer into 'dest',
     // starting from 'startLine', where 0 is the first line in the screen buffer
     void copyFromScreen(Character* dest, int startLine, int count) const;