diff options
-rw-r--r-- | src/Document.cxx | 52 | ||||
-rw-r--r-- | src/Document.h | 1 | ||||
-rw-r--r-- | src/Editor.cxx | 60 | ||||
-rw-r--r-- | src/Editor.h | 1 |
4 files changed, 56 insertions, 58 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; +} diff --git a/src/Document.h b/src/Document.h index 5a85abe5d..3c0273d0f 100644 --- a/src/Document.h +++ b/src/Document.h @@ -234,6 +234,7 @@ public: int ParaUp(int pos); int ParaDown(int pos); int IndentSize() { return actualIndentInChars; } + int BraceMatch(int position, int maxReStyle); private: void CheckReadOnly(); diff --git a/src/Editor.cxx b/src/Editor.cxx index f748bacc1..4ec9be190 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -53,7 +53,7 @@ static bool CanEliminate(const DocModification& mh) { in a [possibly lengthy] multi-step Undo/Redo sequence */ static bool IsLastStep(const DocModification& mh) { - return + return (mh.modificationType & (SC_PERFORMED_UNDO|SC_PERFORMED_REDO)) != 0 && (mh.modificationType & SC_MULTISTEPUNDOREDO) != 0 && (mh.modificationType & SC_LASTSTEPINUNDOREDO) != 0 @@ -2840,7 +2840,7 @@ void Editor::Paint(Surface *surfaceWindow, PRectangle rcArea) { if (lineDoc != lineDocPrevious) { ll.Set(0); // For rectangular selection this accesses the layout cache so should be after layout returned. - lineIterator.SetAt(lineDoc); + lineIterator.SetAt(lineDoc); ll.Set(RetrieveLineLayout(lineDoc)); LayoutLine(lineDoc, surface, vs, ll, wrapWidth); lineDocPrevious = lineDoc; @@ -5439,60 +5439,6 @@ void Editor::CheckForChangeOutsidePaint(Range r) { } } -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 -// TODO: may need to make DBCS safe -// so should be moved into Document -int Editor::BraceMatch(int position, int /*maxReStyle*/) { - char chBrace = pdoc->CharAt(position); - char chSeek = BraceOpposite(chBrace); - if (chSeek == '\0') - return - 1; - char styBrace = static_cast<char>( - pdoc->StyleAt(position) & pdoc->stylingBitsMask); - int direction = -1; - if (chBrace == '(' || chBrace == '[' || chBrace == '{' || chBrace == '<') - direction = 1; - int depth = 1; - position = position + direction; - while ((position >= 0) && (position < pdoc->Length())) { - char chAtPos = pdoc->CharAt(position); - char styAtPos = static_cast<char>(pdoc->StyleAt(position) & pdoc->stylingBitsMask); - if ((position > pdoc->GetEndStyled()) || (styAtPos == styBrace)) { - if (chAtPos == chBrace) - depth++; - if (chAtPos == chSeek) - depth--; - if (depth == 0) - return position; - } - position = position + direction; - } - return - 1; -} - void Editor::SetBraceHighlight(Position pos0, Position pos1, int matchStyle) { if ((pos0 != braces[0]) || (pos1 != braces[1]) || (matchStyle != bracesMatchStyle)) { if ((braces[0] != pos0) || (matchStyle != bracesMatchStyle)) { @@ -7052,7 +6998,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { case SCI_BRACEMATCH: // wParam is position of char to find brace for, // lParam is maximum amount of text to restyle to find it - return BraceMatch(wParam, lParam); + return pdoc->BraceMatch(wParam, lParam); case SCI_GETVIEWEOL: return vs.viewEOL; diff --git a/src/Editor.h b/src/Editor.h index f779e21cc..9243d3a2f 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -509,7 +509,6 @@ protected: // ScintillaBase subclass needs access to much of Editor virtual bool PaintContains(PRectangle rc); bool PaintContainsMargin(); void CheckForChangeOutsidePaint(Range r); - int BraceMatch(int position, int maxReStyle); void SetBraceHighlight(Position pos0, Position pos1, int matchStyle); void SetDocPointer(Document *document); |