aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Document.cxx
diff options
context:
space:
mode:
authornyamatongwe <unknown>2005-12-09 22:22:10 +0000
committernyamatongwe <unknown>2005-12-09 22:22:10 +0000
commitbddae2d12fd9a0856bfa2395c6a041f9603f73f1 (patch)
treee6c97c5de9d065a204e6d685c0794f8d889b5cdf /src/Document.cxx
parentc40ba04c83a54fddea6b2f80aa945298316b1de1 (diff)
downloadscintilla-mirror-bddae2d12fd9a0856bfa2395c6a041f9603f73f1.tar.gz
Fixed bug #1373855 by taking DBCS into account when matching braces.
Moved brace matching from Editor into Document.
Diffstat (limited to 'src/Document.cxx')
-rw-r--r--src/Document.cxx52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/Document.cxx b/src/Document.cxx
index fcd5c91d7..7b189541a 100644
--- a/src/Document.cxx
+++ b/src/Document.cxx
@@ -1539,3 +1539,55 @@ int Document::ExtendStyleRange(int pos, int delta, bool singleLine) {
}
return pos;
}
+
+static char BraceOpposite(char ch) {
+ switch (ch) {
+ case '(':
+ return ')';
+ case ')':
+ return '(';
+ case '[':
+ return ']';
+ case ']':
+ return '[';
+ case '{':
+ return '}';
+ case '}':
+ return '{';
+ case '<':
+ return '>';
+ case '>':
+ return '<';
+ default:
+ return '\0';
+ }
+}
+
+// TODO: should be able to extend styled region to find matching brace
+int Document::BraceMatch(int position, int /*maxReStyle*/) {
+ char chBrace = CharAt(position);
+ char chSeek = BraceOpposite(chBrace);
+ if (chSeek == '\0')
+ return - 1;
+ char styBrace = static_cast<char>(StyleAt(position) & stylingBitsMask);
+ int direction = -1;
+ if (chBrace == '(' || chBrace == '[' || chBrace == '{' || chBrace == '<')
+ direction = 1;
+ int depth = 1;
+ position = position + direction;
+ while ((position >= 0) && (position < Length())) {
+ position = MovePositionOutsideChar(position, direction);
+ char chAtPos = CharAt(position);
+ char styAtPos = static_cast<char>(StyleAt(position) & stylingBitsMask);
+ if ((position > GetEndStyled()) || (styAtPos == styBrace)) {
+ if (chAtPos == chBrace)
+ depth++;
+ if (chAtPos == chSeek)
+ depth--;
+ if (depth == 0)
+ return position;
+ }
+ position = position + direction;
+ }
+ return - 1;
+}