aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authornyamatongwe <devnull@localhost>2011-04-29 19:48:39 +1000
committernyamatongwe <devnull@localhost>2011-04-29 19:48:39 +1000
commit6c97f9c411593118bfd807b8a1b8370b17120454 (patch)
treea5d6928b10f3b4979a8a4afdf30087bad9e9eaad /src
parentb3d1c9dd20616fc0e6276571a5bd7faa5141bcdd (diff)
downloadscintilla-mirror-6c97f9c411593118bfd807b8a1b8370b17120454.tar.gz
Use indicators to show matching braces. Feature #3290434.
From Marko Njezic.
Diffstat (limited to 'src')
-rw-r--r--src/Editor.cxx74
-rw-r--r--src/Editor.h2
-rw-r--r--src/PositionCache.cxx12
-rw-r--r--src/PositionCache.h4
-rw-r--r--src/ViewStyle.cxx8
-rw-r--r--src/ViewStyle.h4
6 files changed, 81 insertions, 23 deletions
diff --git a/src/Editor.cxx b/src/Editor.cxx
index 8e61106c7..03c7b1103 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -2530,12 +2530,22 @@ void Editor::DrawEOL(Surface *surface, ViewStyle &vsDraw, PRectangle rcLine, Lin
}
}
+void Editor::DrawIndicator(int indicNum, int startPos, int endPos, Surface *surface, ViewStyle &vsDraw,
+ int xStart, PRectangle rcLine, LineLayout *ll, int subLine) {
+ const int subLineStart = ll->positions[ll->LineStart(subLine)];
+ PRectangle rcIndic(
+ ll->positions[startPos] + xStart - subLineStart,
+ rcLine.top + vsDraw.maxAscent,
+ ll->positions[endPos] + xStart - subLineStart,
+ rcLine.top + vsDraw.maxAscent + 3);
+ vsDraw.indicators[indicNum].Draw(surface, rcIndic, rcLine);
+}
+
void Editor::DrawIndicators(Surface *surface, ViewStyle &vsDraw, int line, int xStart,
PRectangle rcLine, LineLayout *ll, int subLine, int lineEnd, bool under) {
// Draw decorators
const int posLineStart = pdoc->LineStart(line);
const int lineStart = ll->LineStart(subLine);
- const int subLineStart = ll->positions[lineStart];
const int posLineEnd = posLineStart + lineEnd;
if (!under) {
@@ -2560,12 +2570,7 @@ void Editor::DrawIndicators(Surface *surface, ViewStyle &vsDraw, int line, int x
// IN indicator run, looking for END
if (indicPos >= lineEnd || !(ll->indicators[indicPos] & mask)) {
// AT end of indicator run, DRAW it!
- PRectangle rcIndic(
- ll->positions[startPos] + xStart - subLineStart,
- rcLine.top + vsDraw.maxAscent,
- ll->positions[indicPos] + xStart - subLineStart,
- rcLine.top + vsDraw.maxAscent + 3);
- vsDraw.indicators[indicnum].Draw(surface, rcIndic, rcLine);
+ DrawIndicator(indicnum, startPos, indicPos, surface, vsDraw, xStart, rcLine, ll, subLine);
// RESET control var
startPos = -1;
}
@@ -2585,16 +2590,33 @@ void Editor::DrawIndicators(Surface *surface, ViewStyle &vsDraw, int line, int x
int endPos = deco->rs.EndRun(startPos);
if (endPos > posLineEnd)
endPos = posLineEnd;
- PRectangle rcIndic(
- ll->positions[startPos - posLineStart] + xStart - subLineStart,
- rcLine.top + vsDraw.maxAscent,
- ll->positions[endPos - posLineStart] + xStart - subLineStart,
- rcLine.top + vsDraw.maxAscent + 3);
- vsDraw.indicators[deco->indicator].Draw(surface, rcIndic, rcLine);
+ DrawIndicator(deco->indicator, startPos - posLineStart, endPos - posLineStart,
+ surface, vsDraw, xStart, rcLine, ll, subLine);
startPos = deco->rs.EndRun(endPos);
}
}
}
+
+ // Use indicators to highlight matching braces
+ if ((vs.braceHighlightIndicatorSet && (bracesMatchStyle == STYLE_BRACELIGHT)) ||
+ (vs.braceBadLightIndicatorSet && (bracesMatchStyle == STYLE_BRACEBAD))) {
+ int braceIndicator = (bracesMatchStyle == STYLE_BRACELIGHT) ? vs.braceHighlightIndicator : vs.braceBadLightIndicator;
+ if (under == vsDraw.indicators[braceIndicator].under) {
+ Range rangeLine(posLineStart + lineStart, posLineEnd);
+ if (rangeLine.ContainsCharacter(braces[0])) {
+ int braceOffset = braces[0] - posLineStart;
+ if (braceOffset < ll->numCharsInLine) {
+ DrawIndicator(braceIndicator, braceOffset, braceOffset + 1, surface, vsDraw, xStart, rcLine, ll, subLine);
+ }
+ }
+ if (rangeLine.ContainsCharacter(braces[1])) {
+ int braceOffset = braces[1] - posLineStart;
+ if (braceOffset < ll->numCharsInLine) {
+ DrawIndicator(braceIndicator, braceOffset, braceOffset + 1, surface, vsDraw, xStart, rcLine, ll, subLine);
+ }
+ }
+ }
+ }
}
void Editor::DrawAnnotation(Surface *surface, ViewStyle &vsDraw, int line, int xStart,
@@ -3483,17 +3505,22 @@ void Editor::Paint(Surface *surfaceWindow, PRectangle rcArea) {
rcLine.top = ypos;
rcLine.bottom = ypos + vs.lineHeight;
+ bool bracesIgnoreStyle = false;
+ if ((vs.braceHighlightIndicatorSet && (bracesMatchStyle == STYLE_BRACELIGHT)) ||
+ (vs.braceBadLightIndicatorSet && (bracesMatchStyle == STYLE_BRACEBAD))) {
+ bracesIgnoreStyle = true;
+ }
Range rangeLine(pdoc->LineStart(lineDoc), pdoc->LineStart(lineDoc + 1));
// Highlight the current braces if any
ll->SetBracesHighlight(rangeLine, braces, static_cast<char>(bracesMatchStyle),
- highlightGuideColumn * vs.spaceWidth);
+ highlightGuideColumn * vs.spaceWidth, bracesIgnoreStyle);
// Draw the line
DrawLine(surface, vs, lineDoc, visibleLine, xStart, rcLine, ll, subLine);
//durPaint += et.Duration(true);
// Restore the previous styles for the brace highlights in case layout is in cache.
- ll->RestoreBracesHighlight(rangeLine, braces);
+ ll->RestoreBracesHighlight(rangeLine, braces, bracesIgnoreStyle);
bool expanded = cs.GetExpanded(lineDoc);
const int level = pdoc->GetLevel(lineDoc);
@@ -3625,6 +3652,9 @@ long Editor::FormatRange(bool draw, Sci_RangeToFormat *pfr) {
vsPrint.whitespaceBackgroundSet = false;
vsPrint.whitespaceForegroundSet = false;
vsPrint.showCaretLineBackground = false;
+ // Don't highlight matching braces using indicators
+ vsPrint.braceHighlightIndicatorSet = false;
+ vsPrint.braceBadLightIndicatorSet = false;
// Set colours for printing according to users settings
for (size_t sty = 0; sty < vsPrint.stylesSize; sty++) {
@@ -8363,10 +8393,24 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
SetBraceHighlight(static_cast<int>(wParam), lParam, STYLE_BRACELIGHT);
break;
+ case SCI_BRACEHIGHLIGHTINDICATOR:
+ if (lParam >= 0 && lParam <= INDIC_MAX) {
+ vs.braceHighlightIndicatorSet = wParam != 0;
+ vs.braceHighlightIndicator = lParam;
+ }
+ break;
+
case SCI_BRACEBADLIGHT:
SetBraceHighlight(static_cast<int>(wParam), -1, STYLE_BRACEBAD);
break;
+ case SCI_BRACEBADLIGHTINDICATOR:
+ if (lParam >= 0 && lParam <= INDIC_MAX) {
+ vs.braceBadLightIndicatorSet = wParam != 0;
+ vs.braceBadLightIndicator = lParam;
+ }
+ break;
+
case SCI_BRACEMATCH:
// wParam is position of char to find brace for,
// lParam is maximum amount of text to restyle to find it
diff --git a/src/Editor.h b/src/Editor.h
index 50aa36686..ef3fb78f0 100644
--- a/src/Editor.h
+++ b/src/Editor.h
@@ -370,6 +370,8 @@ protected: // ScintillaBase subclass needs access to much of Editor
int line, int lineEnd, int xStart, int subLine, int subLineStart,
bool overrideBackground, ColourAllocated background,
bool drawWrapMark, ColourAllocated wrapColour);
+ void DrawIndicator(int indicNum, int startPos, int endPos, Surface *surface, ViewStyle &vsDraw,
+ int xStart, PRectangle rcLine, LineLayout *ll, int subLine);
void DrawIndicators(Surface *surface, ViewStyle &vsDraw, int line, int xStart,
PRectangle rcLine, LineLayout *ll, int subLine, int lineEnd, bool under);
void DrawAnnotation(Surface *surface, ViewStyle &vsDraw, int line, int xStart,
diff --git a/src/PositionCache.cxx b/src/PositionCache.cxx
index 2ed152455..52c4326c0 100644
--- a/src/PositionCache.cxx
+++ b/src/PositionCache.cxx
@@ -151,15 +151,15 @@ void LineLayout::SetLineStart(int line, int start) {
}
void LineLayout::SetBracesHighlight(Range rangeLine, Position braces[],
- char bracesMatchStyle, int xHighlight) {
- if (rangeLine.ContainsCharacter(braces[0])) {
+ char bracesMatchStyle, int xHighlight, bool ignoreStyle) {
+ if (!ignoreStyle && rangeLine.ContainsCharacter(braces[0])) {
int braceOffset = braces[0] - rangeLine.start;
if (braceOffset < numCharsInLine) {
bracePreviousStyles[0] = styles[braceOffset];
styles[braceOffset] = bracesMatchStyle;
}
}
- if (rangeLine.ContainsCharacter(braces[1])) {
+ if (!ignoreStyle && rangeLine.ContainsCharacter(braces[1])) {
int braceOffset = braces[1] - rangeLine.start;
if (braceOffset < numCharsInLine) {
bracePreviousStyles[1] = styles[braceOffset];
@@ -172,14 +172,14 @@ void LineLayout::SetBracesHighlight(Range rangeLine, Position braces[],
}
}
-void LineLayout::RestoreBracesHighlight(Range rangeLine, Position braces[]) {
- if (rangeLine.ContainsCharacter(braces[0])) {
+void LineLayout::RestoreBracesHighlight(Range rangeLine, Position braces[], bool ignoreStyle) {
+ if (!ignoreStyle && rangeLine.ContainsCharacter(braces[0])) {
int braceOffset = braces[0] - rangeLine.start;
if (braceOffset < numCharsInLine) {
styles[braceOffset] = bracePreviousStyles[0];
}
}
- if (rangeLine.ContainsCharacter(braces[1])) {
+ if (!ignoreStyle && rangeLine.ContainsCharacter(braces[1])) {
int braceOffset = braces[1] - rangeLine.start;
if (braceOffset < numCharsInLine) {
styles[braceOffset] = bracePreviousStyles[1];
diff --git a/src/PositionCache.h b/src/PositionCache.h
index 754545877..a76da574c 100644
--- a/src/PositionCache.h
+++ b/src/PositionCache.h
@@ -63,8 +63,8 @@ public:
bool InLine(int offset, int line) const;
void SetLineStart(int line, int start);
void SetBracesHighlight(Range rangeLine, Position braces[],
- char bracesMatchStyle, int xHighlight);
- void RestoreBracesHighlight(Range rangeLine, Position braces[]);
+ char bracesMatchStyle, int xHighlight, bool ignoreStyle);
+ void RestoreBracesHighlight(Range rangeLine, Position braces[], bool ignoreStyle);
int FindBefore(int x, int lower, int upper) const;
int EndLineStyle() const;
};
diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx
index 1c1f93170..58e0edea9 100644
--- a/src/ViewStyle.cxx
+++ b/src/ViewStyle.cxx
@@ -204,6 +204,10 @@ ViewStyle::ViewStyle(const ViewStyle &source) {
marginStyleOffset = source.marginStyleOffset;
annotationVisible = source.annotationVisible;
annotationStyleOffset = source.annotationStyleOffset;
+ braceHighlightIndicatorSet = source.braceHighlightIndicatorSet;
+ braceHighlightIndicator = source.braceHighlightIndicator;
+ braceBadLightIndicatorSet = source.braceBadLightIndicatorSet;
+ braceBadLightIndicator = source.braceBadLightIndicator;
}
ViewStyle::~ViewStyle() {
@@ -312,6 +316,10 @@ void ViewStyle::Init(size_t stylesSize_) {
marginStyleOffset = 0;
annotationVisible = ANNOTATION_HIDDEN;
annotationStyleOffset = 0;
+ braceHighlightIndicatorSet = false;
+ braceHighlightIndicator = 0;
+ braceBadLightIndicatorSet = false;
+ braceBadLightIndicator = 0;
}
void ViewStyle::RefreshColourPalette(Palette &pal, bool want) {
diff --git a/src/ViewStyle.h b/src/ViewStyle.h
index 74efa6abd..b038a9b54 100644
--- a/src/ViewStyle.h
+++ b/src/ViewStyle.h
@@ -129,6 +129,10 @@ public:
int marginStyleOffset;
int annotationVisible;
int annotationStyleOffset;
+ bool braceHighlightIndicatorSet;
+ int braceHighlightIndicator;
+ bool braceBadLightIndicatorSet;
+ int braceBadLightIndicator;
ViewStyle();
ViewStyle(const ViewStyle &source);