From bddae2d12fd9a0856bfa2395c6a041f9603f73f1 Mon Sep 17 00:00:00 2001 From: nyamatongwe Date: Fri, 9 Dec 2005 22:22:10 +0000 Subject: Fixed bug #1373855 by taking DBCS into account when matching braces. Moved brace matching from Editor into Document. --- src/Document.cxx | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'src/Document.cxx') 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(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(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; +} -- cgit v1.2.3