ide: show lighter line numbers. make minimal line numbers width 3 instead of 4. show...
authorRejean Loyer <redj@ecere.com>
Wed, 19 Mar 2014 12:00:23 +0000 (08:00 -0400)
committerRejean Loyer <redj@ecere.com>
Mon, 16 Mar 2015 05:31:52 +0000 (01:31 -0400)
ecere/src/gui/controls/EditBox.ec
ide/src/designer/CodeEditor.ec

index b9cebd1..a8d25fb 100644 (file)
@@ -3415,6 +3415,8 @@ private:
          }
       }
       mouseMove = false;
+      UpdateCaretPosition(false); // when NotifyCaretMove is called through UpdateCaretPosition from OnLeftButtonDown the deselection
+                                  // is not yet apparent or something? this fixes it but there might be a better fix
       // Return false because DataBoxes automatically set EditBox editor's clickThrough to true for MouseMove events
       // ( for tool tips -- see 95ee4962c4c7bc3fe0a04aa6a4f98cacada40884)
       return false;
index de4ec14..cbc9c22 100644 (file)
@@ -908,18 +908,29 @@ class CodeEditor : Window
       void NotifyCaretMove(EditBox editBox, int line, int charPos)
       {
          // Update Line Numbers
+         static int oy1 = 0, oy2 = 0;
+         int y1, y2;
          int spaceH;
-         int oldLine = lastLine;
          display.FontExtent(font.font, " ", 1, null, &spaceH);
+         editBox.GetSelPos(null, &y1, null, null, &y2, null, false);
+         if(y1 > y2)
          {
-            Box box { 0, (oldLine-1) * spaceH - editBox.scroll.y, editBox.anchor.left.distance, oldLine*spaceH-1 - editBox.scroll.y };
+            int swap = y2;
+            y2 = y1;
+            y1 = swap;
+         }
+         y2++;
+         {
+            Box box { 0, (oy1-1) * spaceH - editBox.scroll.y, editBox.anchor.left.distance, oy2*spaceH-1 - editBox.scroll.y };
             Update(box);
          }
          {
-            Box box { 0, (line-1) * spaceH - editBox.scroll.y, editBox.anchor.left.distance, line*spaceH-1 - editBox.scroll.y };
+            Box box { 0, (y1-1) * spaceH - editBox.scroll.y, editBox.anchor.left.distance, y2*spaceH-1 - editBox.scroll.y };
             Update(box);
          }
          lastLine = line;
+         oy1 = y1;
+         oy2 = y2;
 
          if(ide.activeClient == this)
             ProcessCaretMove(editBox, line, charPos);
@@ -2389,28 +2400,59 @@ class CodeEditor : Window
          char lineFormat[16];
          char lineText[256];
          int spaceH;
+         int y1, y2;
+         int lineNum = editBox.lineNumber + 1;
+
+         int n = 0;
+         Array<int> highlightLines = GetHighlightLines();
 
          surface.textOpacity = false;
          surface.font = font.font;
          surface.TextExtent(" ", 1, null, &spaceH);
          currentLineNumber = editBox.scroll.y / spaceH + 1;
          sprintf(lineFormat, " %%%du", maxLineNumberLength);
+         editBox.GetSelPos(null, &y1, null, null, &y2, null, false);
 
          surface.SetForeground(lineNumbersColor);
          for(i = 0; i < editBox.clientSize.h - 4; i += spaceH)
          {
-            // Highlight current line
-            if(editBox.lineNumber == currentLineNumber - 1)
+            for(; n < highlightLines.count && highlightLines[n] < currentLineNumber; n++);
+            if(currentLineNumber == lineNum)
             {
                surface.SetBackground(selectedMarginColor);
                surface.Area(0, i, editBox.anchor.left.distance, i+spaceH-1);
                surface.SetBackground(marginColor);
             }
-            sprintf(lineText, lineFormat, currentLineNumber);
+            else if((currentLineNumber - 1 >= y1 && currentLineNumber - 1 <= y2) || (currentLineNumber - 1 <= y1 && currentLineNumber - 1 >= y2))
+            {
+               surface.SetBackground(Color { (marginColor.r + selectedMarginColor.r) / 2, (marginColor.g + selectedMarginColor.g) / 2, (marginColor.b + selectedMarginColor.b) / 2 });
+               surface.Area(0, i, editBox.anchor.left.distance, i+spaceH-1);
+               surface.SetBackground(marginColor);
+            }
+            else
+            {
+               surface.SetBackground(marginColor);
+               surface.Area(0, i, editBox.anchor.left.distance, i+spaceH-1);
+            }
             if(currentLineNumber <= editBox.numLines)
-               surface.WriteText(editBox.syntaxHighlighting * 20, i+1,lineText,maxLineNumberLength+1);
+            {
+               sprintf(lineText, lineFormat, currentLineNumber);
+               if(currentLineNumber % 10 == 0 || (n < highlightLines.count && currentLineNumber == highlightLines[n]))
+               {
+                  surface.WriteText(editBox.syntaxHighlighting * 20, i+1,lineText,maxLineNumberLength+1);
+               }
+               else
+               {
+                  surface.SetForeground(Color { 80, 80, 80 });
+                  surface.WriteText(editBox.syntaxHighlighting * 20, i+1,lineText,maxLineNumberLength+1);
+                  sprintf(lineText, lineFormat, currentLineNumber % 10);
+                  surface.SetForeground(lineNumbersColor);
+                  surface.WriteText(editBox.syntaxHighlighting * 20, i+1,lineText,maxLineNumberLength+1);
+               }
+            }
             currentLineNumber++;
          }
+         delete highlightLines;
       }
 
       if(editBox.syntaxHighlighting && fileName && ide.projectView)
@@ -2507,7 +2549,7 @@ class CodeEditor : Window
    {
       if(ideSettings.showLineNumbers)
       {
-         int numLen = Max(4, nofdigits(editBox.numLines));
+         int numLen = Max(3, nofdigits(editBox.numLines));
          int digitWidth;
          maxLineNumberLength = numLen;
          display.FontExtent(font.font, "0", 1, &digitWidth, null);
@@ -6985,6 +7027,37 @@ class CodeEditor : Window
       }
       return true;
    }
+
+   Array<int> GetHighlightLines()
+   {
+      Array<int> lines { };
+      Map<int, bool> map { };
+      MapNode<int, bool> mn;
+      Debugger debugger = ide.debugger;
+      map[editBox.lineNumber + 1] = true;
+      if(editBox.syntaxHighlighting && fileName && ide.projectView)
+      {
+         bool error, breakpointEnabled[128];
+         int count, lineCursor, lineTopFrame, breakpointLines[128];
+         count = debugger.GetMarginIconsLineNumbers(fileName, breakpointLines, breakpointEnabled, 128, &error, &lineCursor, &lineTopFrame);
+         if(error)
+            map[error] = true;
+         if(lineCursor)
+            map[lineCursor] = true;
+         if(lineTopFrame)
+            map[lineTopFrame] = true;
+         if(count)
+         {
+            int i;
+            for(i = 0; i < count; i++)
+               map[breakpointLines[i]] = true;
+         }
+      }
+      for(mn = map.root.minimum; mn; mn = mn.next)
+         lines.Add(mn.key);
+      delete map;
+      return lines;
+   }
 };
 
 CodeEditor NewCodeEditor(Window parent, WindowState state, bool modified)