Patch #3278 2012-04-15 11:34

alpha0010

EditorTweaks: implement strip trailing blanks
Download
3278-EditorTweaks_i.patch (1.2 KB)
Category
Plugin::Refinement
Status
Accepted
Close date
2012-06-17 07:50
Assigned to
mortenmacfly
Index: src/plugins/contrib/EditorTweaks/EditorTweaks.cpp
===================================================================
--- src/plugins/contrib/EditorTweaks/EditorTweaks.cpp    (revision 7934)
+++ src/plugins/contrib/EditorTweaks/EditorTweaks.cpp    (working copy)
@@ -640,7 +640,28 @@
     if (!ed || !ed->GetControl())
         return;
 
-    wxMessageBox(_("Not Implemented"));
+    cbStyledTextCtrl* control = ed->GetControl();
+    int maxLines = control->GetLineCount();
+    control->BeginUndoAction();
+    for (int line = 0; line < maxLines; line++)
+    {
+        int lineStart = control->PositionFromLine(line);
+        int lineEnd = control->GetLineEndPosition(line);
+        int i = lineEnd-1;
+        wxChar ch = (wxChar)(control->GetCharAt(i));
+        while ((i >= lineStart) && ((ch == _T(' ')) || (ch == _T('\t'))))
+        {
+            i--;
+            ch = (wxChar)(control->GetCharAt(i));
+        }
+        if (i < (lineEnd-1))
+        {
+            control->SetTargetStart(i+1);
+            control->SetTargetEnd(lineEnd);
+            control->ReplaceTarget(_T(""));
+        }
+    }
+    control->EndUndoAction();
 }
 
 void EditorTweaks::OnEnsureConsistentEOL(wxCommandEvent &/*event*/)
alpha0010 2012-04-15 11:34

Code copied from cbEditorInternalData.