Prevent HTML tags with no closing tags from being autocompleted.

Closes #1068
pull/1065/merge
squarefractal 9 years ago committed by Don Ho
parent 624e5fa1ae
commit 74a0c8c398

@ -364,11 +364,12 @@ bool AutoCompletion::showFunctionComplete()
return false; return false;
} }
void AutoCompletion::getCloseTag(char *closeTag, size_t closeTagSize, size_t caretPos) void AutoCompletion::getCloseTag(char *closeTag, size_t closeTagSize, size_t caretPos, bool isHTML)
{ {
int flags = SCFIND_REGEXP | SCFIND_POSIX; int flags = SCFIND_REGEXP | SCFIND_POSIX;
_pEditView->execute(SCI_SETSEARCHFLAGS, flags); _pEditView->execute(SCI_SETSEARCHFLAGS, flags);
TCHAR tag2find[] = TEXT("<[^\\s>]*"); TCHAR tag2find[] = TEXT("<[^\\s>]*");
int targetStart = _pEditView->searchInTarget(tag2find, lstrlen(tag2find), caretPos, 0); int targetStart = _pEditView->searchInTarget(tag2find, lstrlen(tag2find), caretPos, 0);
if (targetStart == -1 || targetStart == -2) if (targetStart == -1 || targetStart == -2)
@ -382,8 +383,8 @@ void AutoCompletion::getCloseTag(char *closeTag, size_t closeTagSize, size_t car
if (size_t(foundTextLen) > closeTagSize - 2) // buffer size is not large enough. -2 for '/' & '\0' if (size_t(foundTextLen) > closeTagSize - 2) // buffer size is not large enough. -2 for '/' & '\0'
return; return;
char tagHead[5]; char tagHead[10];
_pEditView->getText(tagHead, targetStart, targetStart+4); _pEditView->getText(tagHead, targetStart, targetStart+9);
if (tagHead[1] == '/') // "</toto>" will be ignored if (tagHead[1] == '/') // "</toto>" will be ignored
return; return;
@ -391,6 +392,16 @@ void AutoCompletion::getCloseTag(char *closeTag, size_t closeTagSize, size_t car
if (strncmp(tagHead, "<!--", 4) == 0) // Comments will be ignored if (strncmp(tagHead, "<!--", 4) == 0) // Comments will be ignored
return; return;
if (isHTML) // for HTML: "br", "hr", "img", "link" and "meta" will be ignored
{
char *disallowed_tags[] = { "br", "hr", "img", "link", "meta" };
for (int i = 0; i < 5; ++i)
{
if (strnicmp(tagHead + 1, disallowed_tags[i], strlen(disallowed_tags[i])) == 0)
return;
}
}
char tagTail[2]; char tagTail[2];
_pEditView->getText(tagTail, caretPos-2, caretPos-1); _pEditView->getText(tagTail, caretPos-2, caretPos-1);
@ -615,7 +626,7 @@ void AutoCompletion::insertMatchedChars(int character, const MatchedPairConf & m
{ {
if (matchedPairConf._doHtmlXmlTag && (_curLang == L_HTML || _curLang == L_XML)) if (matchedPairConf._doHtmlXmlTag && (_curLang == L_HTML || _curLang == L_XML))
{ {
getCloseTag(closeTag, closeTagLen, caretPos); getCloseTag(closeTag, closeTagLen, caretPos, _curLang == L_HTML);
if (closeTag[0] != '\0') if (closeTag[0] != '\0')
matchedChars = closeTag; matchedChars = closeTag;
} }

@ -90,7 +90,7 @@ public:
void insertMatchedChars(int character, const MatchedPairConf & matchedPairConf); void insertMatchedChars(int character, const MatchedPairConf & matchedPairConf);
void update(int character); void update(int character);
void callTipClick(int direction); void callTipClick(int direction);
void getCloseTag(char *closeTag, size_t closeTagLen, size_t caretPos); void getCloseTag(char *closeTag, size_t closeTagLen, size_t caretPos, bool isHTML);
private: private:
bool _funcCompletionActive; bool _funcCompletionActive;

Loading…
Cancel
Save