diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Editor.cxx | 58 | ||||
-rw-r--r-- | src/ViewStyle.cxx | 2 | ||||
-rw-r--r-- | src/ViewStyle.h | 4 |
3 files changed, 55 insertions, 9 deletions
diff --git a/src/Editor.cxx b/src/Editor.cxx index 916f32316..3373424da 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -2286,7 +2286,7 @@ void Editor::DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int lineVis // Normal text display surface->FillRectangle(rcSegment, textBack); if (vsDraw.viewWhitespace != wsInvisible || - (inIndentation && vsDraw.viewIndentationGuides)) { + (inIndentation && vsDraw.viewIndentationGuides == ivReal)) { for (int cpos = 0; cpos <= i - startseg; cpos++) { if (ll->chars[cpos + startseg] == ' ') { if (drawWhitespaceBackground && @@ -2361,12 +2361,13 @@ void Editor::DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int lineVis textBack = vsDraw.whitespaceBackground.allocated; surface->FillRectangle(rcSegment, textBack); } - if ((vsDraw.viewWhitespace != wsInvisible) || ((inIndentation && vsDraw.viewIndentationGuides))) { + if ((vsDraw.viewWhitespace != wsInvisible) || + (inIndentation && vsDraw.viewIndentationGuides != ivNone)) { if (vsDraw.whitespaceForegroundSet) textFore = vsDraw.whitespaceForeground.allocated; surface->PenColour(textFore); } - if (inIndentation && vsDraw.viewIndentationGuides) { + if (inIndentation && vsDraw.viewIndentationGuides == ivReal) { for (int xIG = ll->positions[i] / indentWidth * indentWidth; xIG < ll->positions[i + 1]; xIG += indentWidth) { if (xIG >= ll->positions[i] && xIG > 0) { DrawIndentGuide(surface, lineVisible, vsDraw.lineHeight, xIG + xStart, rcSegment, @@ -2426,7 +2427,7 @@ void Editor::DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int lineVis } } if (vsDraw.viewWhitespace != wsInvisible || - (inIndentation && vsDraw.viewIndentationGuides)) { + (inIndentation && vsDraw.viewIndentationGuides != ivNone)) { for (int cpos = 0; cpos <= i - startseg; cpos++) { if (ll->chars[cpos + startseg] == ' ') { if (vsDraw.viewWhitespace != wsInvisible) { @@ -2446,7 +2447,7 @@ void Editor::DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int lineVis surface->FillRectangle(rcDot, textFore); } } - if (inIndentation && vsDraw.viewIndentationGuides) { + if (inIndentation && vsDraw.viewIndentationGuides == ivReal) { int startSpace = ll->positions[cpos + startseg]; if (startSpace > 0 && (startSpace % indentWidth == 0)) { DrawIndentGuide(surface, lineVisible, vsDraw.lineHeight, startSpace + xStart, rcSegment, @@ -2477,6 +2478,49 @@ void Editor::DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int lineVis break; } } + if ((vsDraw.viewIndentationGuides == ivLookForward || vsDraw.viewIndentationGuides == ivLookBoth) + && (subLine == 0)) { + int indentSpace = pdoc->GetLineIndentation(line); + // Find the most recent line with some text + + int lineLastWithText = line; + while (lineLastWithText > 0 && pdoc->IsWhiteLine(lineLastWithText)) { + lineLastWithText--; + } + if (lineLastWithText < line) { + // This line is empty, so use indentation of last line with text + int indentLastWithText = pdoc->GetLineIndentation(lineLastWithText); + int isFoldHeader = pdoc->GetLevel(lineLastWithText) & SC_FOLDLEVELHEADERFLAG; + if (isFoldHeader) { + // Level is one more level than parent + indentLastWithText += pdoc->IndentSize(); + } + if (vsDraw.viewIndentationGuides == ivLookForward) { + // In viLookForward mode, previous line only used if it is a fold header + if (isFoldHeader) { + indentSpace = Platform::Maximum(indentSpace, indentLastWithText); + } + } else { // viLookBoth + indentSpace = Platform::Maximum(indentSpace, indentLastWithText); + } + } + + int lineNextWithText = line; + while (lineNextWithText < pdoc->LinesTotal() && pdoc->IsWhiteLine(lineNextWithText)) { + lineNextWithText++; + } + if (lineNextWithText > line) { + // This line is empty, so use indentation of last line with text + indentSpace = Platform::Maximum(indentSpace, + pdoc->GetLineIndentation(lineNextWithText)); + } + + for (int indentPos=pdoc->IndentSize(); indentPos < indentSpace; indentPos += pdoc->IndentSize()) { + int xIndent = indentPos * vsDraw.spaceWidth; + DrawIndentGuide(surface, lineVisible, vsDraw.lineHeight, xIndent + xStart, rcSegment, + (ll->xHighlightGuide == xIndent)); + } + } DrawIndicators(surface, vsDraw, line, xStart, rcLine, ll, subLine, lineEnd, false); @@ -3030,7 +3074,7 @@ long Editor::FormatRange(bool draw, RangeToFormat *pfr) { vsPrint.showMarkedLines = false; vsPrint.fixedColumnWidth = 0; vsPrint.zoomLevel = printMagnification; - vsPrint.viewIndentationGuides = false; + vsPrint.viewIndentationGuides = ivNone; // Don't show the selection when printing vsPrint.selbackset = false; vsPrint.selforeset = false; @@ -6557,7 +6601,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { return verticalScrollBarVisible; case SCI_SETINDENTATIONGUIDES: - vs.viewIndentationGuides = wParam != 0; + vs.viewIndentationGuides = IndentView(wParam); Redraw(); break; diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx index f73c15ed1..15efea8cc 100644 --- a/src/ViewStyle.cxx +++ b/src/ViewStyle.cxx @@ -229,7 +229,7 @@ void ViewStyle::Init(size_t stylesSize_) { } zoomLevel = 0; viewWhitespace = wsInvisible; - viewIndentationGuides = false; + viewIndentationGuides = ivNone; viewEOL = false; showMarkedLines = true; extraFontFlag = false; diff --git a/src/ViewStyle.h b/src/ViewStyle.h index a41e5f452..2f2d52461 100644 --- a/src/ViewStyle.h +++ b/src/ViewStyle.h @@ -38,6 +38,8 @@ public: const char *Save(const char *name); }; +enum IndentView {ivNone, ivReal, ivLookForward, ivLookBoth}; + enum WhiteSpaceVisibility {wsInvisible=0, wsVisibleAlways=1, wsVisibleAfterIndent=2}; /** @@ -87,7 +89,7 @@ public: int fixedColumnWidth; int zoomLevel; WhiteSpaceVisibility viewWhitespace; - bool viewIndentationGuides; + IndentView viewIndentationGuides; bool viewEOL; bool showMarkedLines; ColourPair caretcolour; |