Fixed CodeFileEditor allowing to have no line of code between two section headers
authorLaurent Bessard
Fri, 10 May 2013 13:06:47 +0200
changeset 1117 1aef6a7db08d
parent 1116 300f98a8d4c6
child 1118 2c96a2f36295
Fixed CodeFileEditor allowing to have no line of code between two section headers
editors/CodeFileEditor.py
--- a/editors/CodeFileEditor.py	Fri May 10 12:11:54 2013 +0200
+++ b/editors/CodeFileEditor.py	Fri May 10 13:06:47 2013 +0200
@@ -206,11 +206,14 @@
         for section in SECTIONS_NAMES:
             section_comments = self.SectionsComments[section]
             text += section_comments["comment"]
-            if not parts[section].startswith("\n") or parts[section] == "\n":
+            if parts[section] == "":
                 text += "\n"
-            text += parts[section]
-            if not parts[section].endswith("\n"):
-                text += "\n"
+            else:
+                if not parts[section].startswith("\n"):
+                    text += "\n"
+                text += parts[section]
+                if not parts[section].endswith("\n"):
+                    text += "\n"
         return text
 
     def RefreshView(self, scroll_to_highlight=False):
@@ -273,16 +276,12 @@
         if self.CallTipActive():
             self.CallTipCancel()
         key = event.GetKeyCode()
-        caret = self.GetSelection()[0]
-        print (key in [wx.WXK_DELETE, wx.WXK_NUMPAD_DELETE], 
-               self.GetLineState(self.LineFromPosition(min(len(self.GetText()), caret + 1))))
-        
-        if (self.GetLineState(self.LineFromPosition(caret)) and
-            key not in NAVIGATION_KEYS or
-            key == wx.WXK_BACK and
-            self.GetLineState(self.LineFromPosition(max(0, caret - 1))) or
-            key in [wx.WXK_DELETE, wx.WXK_NUMPAD_DELETE] and
-            self.GetLineState(self.LineFromPosition(min(len(self.GetText()), caret + 1)))):
+        current_pos = self.GetSelection()[0]
+        
+        if (self.GetLineState(self.LineFromPosition(current_pos)) and
+            key not in NAVIGATION_KEYS + [
+                wx.WXK_RETURN,
+                wx.WXK_NUMPAD_ENTER]):
             return
         
         elif key == 32 and event.ControlDown():