X-Git-Url: https://ecere.com/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=ide%2Fsrc%2Fdesigner%2FCodeEditor.ec;h=cbc9c22b90d321c0ed51a16d12b93f7db4e0fbc2;hb=4aadd47bcb91dcf4248dc3984757ddcbc5bb3c3a;hp=de4ec141c516780dd5ad11a27f585b7b9837e2f5;hpb=4abb983e8d05dbbe356db4c7ad68699782a74962;p=sdk diff --git a/ide/src/designer/CodeEditor.ec b/ide/src/designer/CodeEditor.ec index de4ec14..cbc9c22 100644 --- a/ide/src/designer/CodeEditor.ec +++ b/ide/src/designer/CodeEditor.ec @@ -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 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 GetHighlightLines() + { + Array lines { }; + Map map { }; + MapNode 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)