highlight paired bracket, part 1

This commit is contained in:
Vadim Lopatin 2015-02-10 18:31:42 +03:00
parent 8afcc1ff9c
commit a08d03887e
2 changed files with 61 additions and 1 deletions

View File

@ -8,8 +8,15 @@ Currently supported features:
* Can open DUB (dub.json) projects
* Shows tree with project source files
* Can open and edit source files from project or file system in multi-tab editor
* D language source code syntax highlight (basic)
* Build and run project with DUB
* Build log highlight and navigation to place of error or warning by clicking on log line
Editor features:
* D language source code syntax highlight (basic)
* Indent / unindent text with Tab and Shift+Tab
* Toggle line or block comments by Ctrl+/ and Ctrl+Shift+/
![screenshot](http://buggins.github.io/dlangui/screenshots/screenshot-dlangide.png "screenshot")

View File

@ -118,6 +118,59 @@ class SimpleDSyntaxHighlighter : SyntaxHighlighter {
return this;
}
static dchar pairedBracket(dchar ch) {
switch (ch) {
case '(':
return ')';
case ')':
return '(';
case '{':
return '}';
case '}':
return '{';
case '[':
return ']';
case ']':
return '[';
default:
return 0; // not a bracket
}
}
static bool isOpenBracket(dchar ch) {
switch (ch) {
case '(':
case '{':
case '[':
return true;
default:
return false;
}
}
static bool isCloseBracket(dchar ch) {
switch (ch) {
case ')':
case '}':
case ']':
return true;
default:
return false;
}
}
/// returns paired bracket {} () [] for char at position p, returns paired char position or p if not found or not bracket
override TextPosition findPairedBracket(TextPosition p) {
if (p.line < 0 || p.line >= content.length)
return p;
dstring s = content.line(p.line);
if (p.pos < 0 || p.pos >= s.length)
return p;
dchar ch = s[p.pos];
dchar paired = pairedBracket(ch);
int dir = isOpenBracket(ch) ? 1 : -1;
return p;
}
/// return true if toggle line comment is supported for file type
override @property bool supportsToggleLineComment() {
return true;