From a08d03887e081bca9c58edf59ee8d6f21f79ec7e Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Tue, 10 Feb 2015 18:31:42 +0300 Subject: [PATCH] highlight paired bracket, part 1 --- README.md | 9 +++++- src/dlangide/ui/dsourceedit.d | 53 +++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 70bcc7b..c15e4d8 100644 --- a/README.md +++ b/README.md @@ -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") diff --git a/src/dlangide/ui/dsourceedit.d b/src/dlangide/ui/dsourceedit.d index 950be2d..ba23955 100644 --- a/src/dlangide/ui/dsourceedit.d +++ b/src/dlangide/ui/dsourceedit.d @@ -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;