fixes highlighting for tags inside comment, needs improvement
parent
7b2b640357
commit
e37354842d
|
@ -143,7 +143,7 @@ bool XmlMatchedTagsHighlighter::getXmlMatchedTagsPos(XmlMatchedTagsPos &xmlTags)
|
||||||
openFound = findText("<", searchStartPoint, 0, 0);
|
openFound = findText("<", searchStartPoint, 0, 0);
|
||||||
styleAt = _pEditView->execute(SCI_GETSTYLEAT, openFound.start);
|
styleAt = _pEditView->execute(SCI_GETSTYLEAT, openFound.start);
|
||||||
searchStartPoint = openFound.start - 1;
|
searchStartPoint = openFound.start - 1;
|
||||||
} while (openFound.success && (styleAt == SCE_H_DOUBLESTRING || styleAt == SCE_H_SINGLESTRING) && searchStartPoint > 0);
|
} while (openFound.success && (styleAt == SCE_H_DOUBLESTRING || styleAt == SCE_H_SINGLESTRING || insideComment(openFound.start)) && searchStartPoint > 0);
|
||||||
|
|
||||||
if (openFound.success && styleAt != SCE_H_CDATA)
|
if (openFound.success && styleAt != SCE_H_CDATA)
|
||||||
{
|
{
|
||||||
|
@ -155,7 +155,7 @@ bool XmlMatchedTagsHighlighter::getXmlMatchedTagsPos(XmlMatchedTagsPos &xmlTags)
|
||||||
closeFound = findText(">", searchStartPoint, caret, 0);
|
closeFound = findText(">", searchStartPoint, caret, 0);
|
||||||
styleAt = _pEditView->execute(SCI_GETSTYLEAT, closeFound.start);
|
styleAt = _pEditView->execute(SCI_GETSTYLEAT, closeFound.start);
|
||||||
searchStartPoint = closeFound.end;
|
searchStartPoint = closeFound.end;
|
||||||
} while (closeFound.success && (styleAt == SCE_H_DOUBLESTRING || styleAt == SCE_H_SINGLESTRING) && searchStartPoint <= caret);
|
} while (closeFound.success && (styleAt == SCE_H_DOUBLESTRING || styleAt == SCE_H_SINGLESTRING || insideComment(closeFound.start)) && searchStartPoint <= caret);
|
||||||
|
|
||||||
if (!closeFound.success)
|
if (!closeFound.success)
|
||||||
{
|
{
|
||||||
|
@ -282,7 +282,7 @@ bool XmlMatchedTagsHighlighter::getXmlMatchedTagsPos(XmlMatchedTagsPos &xmlTags)
|
||||||
std::string tagName;
|
std::string tagName;
|
||||||
nextChar = _pEditView->execute(SCI_GETCHARAT, position);
|
nextChar = _pEditView->execute(SCI_GETCHARAT, position);
|
||||||
// Checking for " or ' is actually wrong here, but it means it works better with invalid XML
|
// Checking for " or ' is actually wrong here, but it means it works better with invalid XML
|
||||||
while(position < docLength && !isWhitespace(nextChar) && nextChar != '/' && nextChar != '>' && nextChar != '\"' && nextChar != '\'')
|
while(position < docLength && !isWhitespace(nextChar) && nextChar != '/' && nextChar != '>' && nextChar != '\"' && nextChar != '\'' && !insideComment(position))
|
||||||
{
|
{
|
||||||
tagName.push_back((char)nextChar);
|
tagName.push_back((char)nextChar);
|
||||||
++position;
|
++position;
|
||||||
|
@ -381,6 +381,33 @@ bool XmlMatchedTagsHighlighter::getXmlMatchedTagsPos(XmlMatchedTagsPos &xmlTags)
|
||||||
return tagFound;
|
return tagFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool XmlMatchedTagsHighlighter::insideComment(int pos) {
|
||||||
|
bool foundComment = false;
|
||||||
|
int cur = pos-1;
|
||||||
|
int nextChar, nextChar2, nextChar3;
|
||||||
|
//int styleAt = _pEditView->execute(SCI_GETSTYLEAT, pos);
|
||||||
|
while (cur > 3 && !foundComment) {
|
||||||
|
nextChar = _pEditView->execute(SCI_GETCHARAT, cur);
|
||||||
|
if (nextChar == '-') {
|
||||||
|
nextChar2 = _pEditView->execute(SCI_GETCHARAT, cur-1);
|
||||||
|
if (nextChar2 == '-') {
|
||||||
|
nextChar3 = _pEditView->execute(SCI_GETCHARAT, cur-2);
|
||||||
|
if (nextChar3 == '!') {
|
||||||
|
foundComment = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (nextChar == '>') {
|
||||||
|
// check if it's closing comment tag
|
||||||
|
if (_pEditView->execute(SCI_GETCHARAT, cur-2) == '-' && _pEditView->execute(SCI_GETCHARAT, cur-1) == '-')
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
cur--;
|
||||||
|
}
|
||||||
|
|
||||||
|
return foundComment;
|
||||||
|
}
|
||||||
|
|
||||||
XmlMatchedTagsHighlighter::FindResult XmlMatchedTagsHighlighter::findOpenTag(const std::string& tagName, int start, int end)
|
XmlMatchedTagsHighlighter::FindResult XmlMatchedTagsHighlighter::findOpenTag(const std::string& tagName, int start, int end)
|
||||||
{
|
{
|
||||||
|
@ -402,7 +429,7 @@ XmlMatchedTagsHighlighter::FindResult XmlMatchedTagsHighlighter::findOpenTag(con
|
||||||
{
|
{
|
||||||
nextChar = _pEditView->execute(SCI_GETCHARAT, result.end);
|
nextChar = _pEditView->execute(SCI_GETCHARAT, result.end);
|
||||||
styleAt = _pEditView->execute(SCI_GETSTYLEAT, result.start);
|
styleAt = _pEditView->execute(SCI_GETSTYLEAT, result.start);
|
||||||
if (styleAt != SCE_H_CDATA && styleAt != SCE_H_DOUBLESTRING && styleAt != SCE_H_SINGLESTRING)
|
if (styleAt != SCE_H_CDATA && styleAt != SCE_H_DOUBLESTRING && styleAt != SCE_H_SINGLESTRING && !insideComment(result.start))
|
||||||
{
|
{
|
||||||
// We've got an open tag for this tag name (i.e. nextChar was space or '>')
|
// We've got an open tag for this tag name (i.e. nextChar was space or '>')
|
||||||
// Now we need to find the end of the start tag.
|
// Now we need to find the end of the start tag.
|
||||||
|
@ -472,7 +499,7 @@ int XmlMatchedTagsHighlighter::findCloseAngle(int startPosition, int endPosition
|
||||||
{
|
{
|
||||||
int style = _pEditView->execute(SCI_GETSTYLEAT, closeAngle.start);
|
int style = _pEditView->execute(SCI_GETSTYLEAT, closeAngle.start);
|
||||||
// As long as we're not in an attribute ( <TAGNAME attrib="val>ue"> is VALID XML. )
|
// As long as we're not in an attribute ( <TAGNAME attrib="val>ue"> is VALID XML. )
|
||||||
if (style != SCE_H_DOUBLESTRING && style != SCE_H_SINGLESTRING)
|
if (style != SCE_H_DOUBLESTRING && style != SCE_H_SINGLESTRING && !insideComment(closeAngle.start))
|
||||||
{
|
{
|
||||||
returnPosition = closeAngle.start;
|
returnPosition = closeAngle.start;
|
||||||
isValidClose = true;
|
isValidClose = true;
|
||||||
|
@ -521,7 +548,7 @@ XmlMatchedTagsHighlighter::FindResult XmlMatchedTagsHighlighter::findCloseTag(co
|
||||||
searchStart = result.start - 1;
|
searchStart = result.start - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (styleAt != SCE_H_CDATA && styleAt != SCE_H_SINGLESTRING && styleAt != SCE_H_DOUBLESTRING) // If what we found was in CDATA section, it's not a valid tag.
|
if (styleAt != SCE_H_CDATA && styleAt != SCE_H_SINGLESTRING && styleAt != SCE_H_DOUBLESTRING && !insideComment(result.start)) // If what we found was in CDATA section, it's not a valid tag.
|
||||||
{
|
{
|
||||||
// Common case - '>' follows the tag name directly
|
// Common case - '>' follows the tag name directly
|
||||||
if (nextChar == '>')
|
if (nextChar == '>')
|
||||||
|
|
|
@ -63,7 +63,7 @@ private:
|
||||||
// Allowed whitespace characters in XML
|
// Allowed whitespace characters in XML
|
||||||
bool isWhitespace(int ch) { return ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n'; }
|
bool isWhitespace(int ch) { return ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n'; }
|
||||||
|
|
||||||
|
bool insideComment(int p); // added by Amy
|
||||||
FindResult findText(const char *text, int start, int end, int flags = 0);
|
FindResult findText(const char *text, int start, int end, int flags = 0);
|
||||||
FindResult findOpenTag(const std::string& tagName, int start, int end);
|
FindResult findOpenTag(const std::string& tagName, int start, int end);
|
||||||
FindResult findCloseTag(const std::string& tagName, int start, int end);
|
FindResult findCloseTag(const std::string& tagName, int start, int end);
|
||||||
|
|
Loading…
Reference in New Issue