Skip to content

Commit

Permalink
Improve auto close HTML and XML tags.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Mar 24, 2023
1 parent d4261ba commit b85245a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion scintilla/src/Editor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1973,7 +1973,7 @@ void Editor::InsertCharacter(std::string_view sv, CharacterSource charSource) {
uint32_t index = ch - '\"';
if (index == '{' - '\"' || (index < 63 && (UINT64_C(0x4200000000000061) & (UINT64_C(1) << index)))) {
index = (index + (index >> 5)) & 7;
index = (0xc28284U >> (3*index)) & 7;
index = (0x60501204U >> (4*index)) & 15;
if (autoInsertMask & (1U << index)) {
encloseCh = ch + ((41U >> (index*2)) & 3); // 0b101001
}
Expand Down
16 changes: 13 additions & 3 deletions src/EditAutoC.c
Original file line number Diff line number Diff line change
Expand Up @@ -1870,14 +1870,24 @@ void EditAutoCloseXMLTag(void) {
if (tchBuf[iSize - 2] != '/') {
char tchIns[516] = "</";
int cchIns = 2;
const char *pBegin = tchBuf;
const char *pCur = tchBuf + iSize - 2;

while (pCur > pBegin && *pCur != '<' && *pCur != '>') {
while (pCur > tchBuf && *pCur != '<' && *pCur != '>') {
--pCur;
}

if (*pCur == '<') {
const Sci_Position iPos = iStartPos + (pCur - tchBuf);
const int style = SciCall_GetStyleIndexAt(iPos);
if (style) {
if (style == pLexCurrent->operatorStyle || style == pLexCurrent->operatorStyle2) {
return;
}
if (pLexCurrent->iLexer == SCLEX_PHPSCRIPT
&& (style == js_style(SCE_JS_OPERATOR) || style == js_style(SCE_JS_OPERATOR2))) {
return;
}
}

pCur++;
while (IsHtmlTagChar(*pCur)) {
tchIns[cchIns++] = *pCur;
Expand Down
2 changes: 1 addition & 1 deletion tools/GenerateTable.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def GenerateAutoInsertMask(ignore=''):
if diff > 0:
delta |= diff << (2*item[0])
if ignore:
diff = 3*((bit + (bit >> 5)) & 7)
diff = 4*((bit + (bit >> 5)) & 7)
else:
diff = 4*((bit + (bit >> 4)) & 15)
assert diff not in unique
Expand Down

0 comments on commit b85245a

Please sign in to comment.