Patch #1801 2007-01-05 11:26

mcdave

Patch for Bug #9380
Download
1801-Patch_for_Bug.patch (4.8 KB)
Category
Application::Bugfix
Status
Rejected
Close date
2007-03-19 09:57
Assigned to
biplab
Index: src/sdk/cbeditor.cpp
===================================================================
--- src/sdk/cbeditor.cpp    (revision 3459)
+++ src/sdk/cbeditor.cpp    (working copy)
@@ -74,6 +74,7 @@
     EVT_CONTEXT_MENU(cbStyledTextCtrl::OnContextMenu)
     EVT_KILL_FOCUS(cbStyledTextCtrl::OnKillFocus)
     EVT_MIDDLE_DOWN(cbStyledTextCtrl::OnGPM)
+    EVT_KEY_DOWN(cbStyledTextCtrl::OnKeyDown)
 END_EVENT_TABLE()
 
 cbStyledTextCtrl::cbStyledTextCtrl(wxWindow* pParent, int id, const wxPoint& pos, const wxSize& size, long style)
@@ -136,8 +137,111 @@
 #endif
 }
 
+void cbStyledTextCtrl::OnKeyDown (wxKeyEvent& evt) //Used to check if code is unfolded before a delete
+{
+   int keyPressed = evt.GetKeyCode();
+   if(keyPressed == WXK_DELETE || keyPressed == WXK_BACK)
+   {
+      ConfigManager* mgr = Manager::Get()->GetConfigManager(_T("editor"));
+      if(mgr->ReadBool(_T("/folding/show_folds"), true)) //Only try to fix folds if the folds are used
+      {
+         int currentLine = GetCurrentLine();
+         int currentSelectionStart = GetSelectionStart();
+         int currentSelectionEnd = GetSelectionEnd();
+         int selectionSize = currentSelectionEnd - currentSelectionStart;
+         if(selectionSize != 0) //Determine if there is a selection involved
+         {
+            int selectionStartLine = LineFromPosition(currentSelectionStart);
+            int selectionEndLine = LineFromPosition(currentSelectionEnd);
 
+            int foldLevelStartLine = GetFoldLevel(selectionStartLine);
+            int foldLevelEndLine = GetFoldLevel(selectionEndLine);
 
+            int foldStartParent = GetFoldParent(selectionStartLine);
+            int foldEndParent = GetFoldParent(selectionEndLine);
+
+            if ((foldLevelStartLine & wxSCI_FOLDLEVELHEADERFLAG) &&
+            (wxSCI_FOLDLEVELBASE <= (foldLevelStartLine & wxSCI_FOLDLEVELNUMBERMASK)))
+            {
+               foldStartParent = selectionStartLine;
+            }
+
+            if ((foldLevelEndLine & wxSCI_FOLDLEVELHEADERFLAG) &&
+            (wxSCI_FOLDLEVELBASE <= (foldLevelEndLine & wxSCI_FOLDLEVELNUMBERMASK)))
+            {
+               foldEndParent = selectionEndLine;
+            }
+
+            if(foldStartParent != -1)
+            {
+               if(GetFoldExpanded(foldStartParent) == false)
+               {
+                  ToggleFold(foldStartParent);
+               }
+            }
+
+            if(foldEndParent != -1)
+            {
+               if(GetFoldExpanded(foldEndParent) == false)
+               {
+                  ToggleFold(foldEndParent);
+               }
+            }
+         }
+         else //If no selection involved
+         {
+            int foldParent = GetFoldParent(currentLine);
+            int foldLevel = GetFoldLevel(currentLine);
+
+            if ((foldLevel & wxSCI_FOLDLEVELHEADERFLAG) &&
+            (wxSCI_FOLDLEVELBASE <= (foldLevel & wxSCI_FOLDLEVELNUMBERMASK)))
+            {
+               foldParent = currentLine;
+            }
+
+            if(foldParent != -1)
+            {
+               if(GetFoldExpanded(foldParent) == false)
+               {
+                  ToggleFold(foldParent);
+               }
+               else
+               {
+                  int prevLine = currentLine - 1;
+                  if(prevLine > 0)
+                  {
+                     int prevFoldParent = GetFoldParent(prevLine);
+                     if( prevFoldParent != -1)
+                     {
+                        if(GetFoldExpanded(prevFoldParent) == false)
+                        {
+                           ToggleFold(prevFoldParent);
+                        }
+                     }
+                  }
+               }
+            }
+            else
+            {
+               int prevLine = currentLine - 1;
+               if(prevLine > 0)
+               {
+                  int prevFoldParent = GetFoldParent(prevLine);
+                  if( prevFoldParent != -1)
+                  {
+                     if(GetFoldExpanded(prevFoldParent) == false)
+                     {
+                        ToggleFold(prevFoldParent);
+                     }
+                  }
+               }
+            }
+         }
+      }
+   }
+   evt.Skip();
+}
+
 /* This struct holds private data for the cbEditor class.
  * It's a paradigm to avoid rebuilding the entire project (as cbEditor is a basic dependency)
  * for just adding a private var or method.
Index: src/sdk/cbeditor.h
===================================================================
--- src/sdk/cbeditor.h    (revision 3459)
+++ src/sdk/cbeditor.h    (working copy)
@@ -28,6 +28,7 @@
         void OnContextMenu(wxContextMenuEvent& event);
         void OnKillFocus(wxFocusEvent& event);
         void OnGPM(wxMouseEvent& event);
+        void OnKeyDown (wxKeyEvent& evt);
     private:
         wxWindow* m_pParent;
         DECLARE_EVENT_TABLE()
mcdave 2007-01-05 11:27

This patch will only expand the folded code part in question, and not delete any part that was not selected.

pauliusz 2007-03-13 20:42

Since bug is closed I think this patch can be closed also.

biplab 2007-03-19 09:57

I've discussed the solution in Bug #9380. As the present behaviour is consistent with other Scintilla based editors, we're not applying this patch to repository.

We're unable to support any bug or it's fix which belongs to a different project (in the present case it's wxScintilla) unless it's critical to C::B.