mirror of https://github.com/buggins/dlangui.git
matching brackets highlight in editors
This commit is contained in:
parent
579b297147
commit
f703b74408
|
@ -647,6 +647,22 @@ class EditableContent {
|
||||||
handleContentChange(new EditOperation(EditAction.SaveContent), rangeBefore, rangeAfter, this);
|
handleContentChange(new EditOperation(EditAction.SaveContent), rangeBefore, rangeAfter, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool findMatchedBraces(TextPosition p, out TextRange range) {
|
||||||
|
if (!_syntaxHighlighter)
|
||||||
|
return false;
|
||||||
|
TextPosition p2 = _syntaxHighlighter.findPairedBracket(p);
|
||||||
|
if (p == p2)
|
||||||
|
return false;
|
||||||
|
if (p < p2) {
|
||||||
|
range.start = p;
|
||||||
|
range.end = p2;
|
||||||
|
} else {
|
||||||
|
range.start = p2;
|
||||||
|
range.end = p;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
protected void updateTokenProps(int startLine, int endLine) {
|
protected void updateTokenProps(int startLine, int endLine) {
|
||||||
clearTokenProps(startLine, endLine);
|
clearTokenProps(startLine, endLine);
|
||||||
if (_syntaxHighlighter) {
|
if (_syntaxHighlighter) {
|
||||||
|
|
|
@ -1629,6 +1629,7 @@ class EditBox : EditWidgetBase {
|
||||||
new Action(EditorActions.ZoomOut, KeyCode.SUB, KeyFlag.Control),
|
new Action(EditorActions.ZoomOut, KeyCode.SUB, KeyFlag.Control),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
protected uint _matchingBracketHightlightColor = 0xFFF0E0;
|
||||||
|
|
||||||
protected int _firstVisibleLine;
|
protected int _firstVisibleLine;
|
||||||
|
|
||||||
|
@ -2109,6 +2110,20 @@ class EditBox : EditWidgetBase {
|
||||||
//measuredContent(parentWidth, parentHeight, textSz.x + vsbwidth, textSz.y + hsbheight);
|
//measuredContent(parentWidth, parentHeight, textSz.x + vsbwidth, textSz.y + hsbheight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void highlightLineRange(DrawBuf buf, Rect lineRect, uint color, TextRange r) {
|
||||||
|
Rect startrc = textPosToClient(r.start);
|
||||||
|
Rect endrc = textPosToClient(r.end);
|
||||||
|
Rect rc = lineRect;
|
||||||
|
rc.left = _clientRect.left + startrc.left;
|
||||||
|
rc.right = _clientRect.left + endrc.right;
|
||||||
|
if (!rc.empty) {
|
||||||
|
// draw selection rect for matching bracket
|
||||||
|
Log.d("highlight bracket 1: ", rc);
|
||||||
|
buf.fillRect(rc, 0xFFDD80);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// override to custom highlight of line background
|
/// override to custom highlight of line background
|
||||||
protected void drawLineBackground(DrawBuf buf, int lineIndex, Rect lineRect, Rect visibleRect) {
|
protected void drawLineBackground(DrawBuf buf, int lineIndex, Rect lineRect, Rect visibleRect) {
|
||||||
// highlight odd lines
|
// highlight odd lines
|
||||||
|
@ -2130,6 +2145,17 @@ class EditBox : EditWidgetBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_matchingBraces.start.line == lineIndex) {
|
||||||
|
TextRange r = TextRange(_matchingBraces.start, _matchingBraces.start);
|
||||||
|
r.end.pos++;
|
||||||
|
highlightLineRange(buf, lineRect, _matchingBracketHightlightColor, r);
|
||||||
|
}
|
||||||
|
if (_matchingBraces.end.line == lineIndex) {
|
||||||
|
TextRange r = TextRange(_matchingBraces.end, _matchingBraces.end);
|
||||||
|
r.end.pos++;
|
||||||
|
highlightLineRange(buf, lineRect, _matchingBracketHightlightColor, r);
|
||||||
|
}
|
||||||
|
|
||||||
// frame around current line
|
// frame around current line
|
||||||
if (focused && lineIndex == _caretPos.line && _selectionRange.singleLine && _selectionRange.start.line == _caretPos.line) {
|
if (focused && lineIndex == _caretPos.line && _selectionRange.singleLine && _selectionRange.start.line == _caretPos.line) {
|
||||||
buf.drawFrame(visibleRect, 0xA0808080, Rect(1,1,1,1));
|
buf.drawFrame(visibleRect, 0xA0808080, Rect(1,1,1,1));
|
||||||
|
@ -2207,7 +2233,15 @@ class EditBox : EditWidgetBase {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TextRange _matchingBraces;
|
||||||
|
|
||||||
override protected void drawClient(DrawBuf buf) {
|
override protected void drawClient(DrawBuf buf) {
|
||||||
|
// update matched braces
|
||||||
|
if (!content.findMatchedBraces(_caretPos, _matchingBraces)) {
|
||||||
|
_matchingBraces.start.line = -1;
|
||||||
|
_matchingBraces.end.line = -1;
|
||||||
|
}
|
||||||
|
|
||||||
Rect rc = _clientRect;
|
Rect rc = _clientRect;
|
||||||
|
|
||||||
FontRef font = font();
|
FontRef font = font();
|
||||||
|
|
Loading…
Reference in New Issue