From 215b5c0049c63c1be99a28677ca323ffc587dbb3 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Tue, 24 Nov 2009 00:32:54 +0000 Subject: [PATCH] [NEW_FEATURE] Add indent guide line highlighting for html/xml tags. git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@571 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/src/Notepad_plus.cpp | 33 +++++++++++++++++-- .../xmlMatchedTagsHighlighter.cpp | 6 ++-- .../xmlMatchedTagsHighlighter.h | 2 +- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 182afff1..d0518864 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -2688,7 +2688,36 @@ BOOL Notepad_plus::notify(SCNotification *notification) if (nppGui._enableTagsMatchHilite) { XmlMatchedTagsHighlighter xmlTagMatchHiliter(_pEditView); - xmlTagMatchHiliter.tagMatch(nppGui._enableTagAttrsHilite); + pair tagPos = xmlTagMatchHiliter.tagMatch(nppGui._enableTagAttrsHilite); + + int braceAtCaret = tagPos.first; + int braceOpposite = tagPos.second; + + if ((braceAtCaret != -1) && (braceOpposite == -1)) + { + _pEditView->execute(SCI_SETHIGHLIGHTGUIDE, 0); + } + else if (_pEditView->isShownIndentGuide()) + { + int columnAtCaret = int(_pEditView->execute(SCI_GETCOLUMN, braceAtCaret)); + int columnOpposite = int(_pEditView->execute(SCI_GETCOLUMN, braceOpposite)); + + int lineAtCaret = int(_pEditView->execute(SCI_LINEFROMPOSITION, braceAtCaret)); + int lineOpposite = int(_pEditView->execute(SCI_LINEFROMPOSITION, braceOpposite)); + if (lineAtCaret != lineOpposite) + { + StyleArray & stylers = nppParam->getMiscStylerArray(); + int iFind = stylers.getStylerIndexByID(SCE_UNIVERSAL_TAGMATCH); + if (iFind) + { + Style *pStyle = &(stylers.getStyler(iFind)); + _pEditView->execute(SCI_STYLESETFORE, STYLE_BRACELIGHT, pStyle->_bgColor); + } + // braceAtCaret - 1, braceOpposite-1 : walk around to not highlight the '<' + _pEditView->execute(SCI_BRACEHIGHLIGHT, braceAtCaret-1, braceOpposite-1); + _pEditView->execute(SCI_SETHIGHLIGHTGUIDE, (columnAtCaret < columnOpposite)?columnAtCaret:columnOpposite); + } + } } if (nppGui._enableSmartHilite) @@ -3090,7 +3119,7 @@ void Notepad_plus::braceMatch() if ((braceAtCaret != -1) && (braceOpposite == -1)) { _pEditView->execute(SCI_BRACEBADLIGHT, braceAtCaret); - _pEditView->execute(SCI_SETHIGHLIGHTGUIDE); + _pEditView->execute(SCI_SETHIGHLIGHTGUIDE, 0); } else { diff --git a/PowerEditor/src/ScitillaComponent/xmlMatchedTagsHighlighter.cpp b/PowerEditor/src/ScitillaComponent/xmlMatchedTagsHighlighter.cpp index 844fd722..be625290 100644 --- a/PowerEditor/src/ScitillaComponent/xmlMatchedTagsHighlighter.cpp +++ b/PowerEditor/src/ScitillaComponent/xmlMatchedTagsHighlighter.cpp @@ -439,7 +439,7 @@ vector< pair > XmlMatchedTagsHighlighter::getAttributesPos(int start, -void XmlMatchedTagsHighlighter::tagMatch(bool doHiliteAttr) +pair XmlMatchedTagsHighlighter::tagMatch(bool doHiliteAttr) { // Clean up all marks of previous action _pEditView->clearIndicator(SCE_UNIVERSAL_TAGMATCH); @@ -449,7 +449,7 @@ void XmlMatchedTagsHighlighter::tagMatch(bool doHiliteAttr) LangType lang = (_pEditView->getCurrentBuffer())->getLangType(); if (lang != L_XML && lang != L_HTML && lang != L_PHP && lang != L_ASP) - return; + return pair(-1, -1); // Get the original targets and search options to restore after tag matching operation int originalStartPos = _pEditView->execute(SCI_GETTARGETSTART); @@ -490,4 +490,6 @@ void XmlMatchedTagsHighlighter::tagMatch(bool doHiliteAttr) _pEditView->execute(SCI_SETTARGETSTART, originalStartPos); _pEditView->execute(SCI_SETTARGETEND, originalEndPos); _pEditView->execute(SCI_SETSEARCHFLAGS, originalSearchFlags); + + return pair(xmlTags.tagOpenStart, xmlTags.tagCloseStart); } diff --git a/PowerEditor/src/ScitillaComponent/xmlMatchedTagsHighlighter.h b/PowerEditor/src/ScitillaComponent/xmlMatchedTagsHighlighter.h index b0b40b9f..6c3f9960 100644 --- a/PowerEditor/src/ScitillaComponent/xmlMatchedTagsHighlighter.h +++ b/PowerEditor/src/ScitillaComponent/xmlMatchedTagsHighlighter.h @@ -27,7 +27,7 @@ enum TagCateg {tagOpen, tagClose, inSingleTag, outOfTag, invalidTag, unknownPb}; class XmlMatchedTagsHighlighter { public: XmlMatchedTagsHighlighter(ScintillaEditView *pEditView):_pEditView(pEditView){}; - void tagMatch(bool doHiliteAttr); + pair tagMatch(bool doHiliteAttr); private: struct XmlMatchedTagsPos {