aboutsummaryrefslogtreecommitdiffhomepage
path: root/lexers/LexHTML.cxx
diff options
context:
space:
mode:
authorZufu Liu <unknown>2019-10-19 10:24:53 +1100
committerZufu Liu <unknown>2019-10-19 10:24:53 +1100
commit46556449e76b0d3bf1ed65959b97b66a6998c0d6 (patch)
tree169ecef26a157ef2d1948784d512b67a75ef3ca6 /lexers/LexHTML.cxx
parent50c13867d645d79e6ee5b0233d46b3aab353ae01 (diff)
downloadscintilla-mirror-46556449e76b0d3bf1ed65959b97b66a6998c0d6.tar.gz
Backport: Bug [#2128]. Add fold.xml.at.tag.open option to fold tags at the start of the
tag instead of the end. Backport of changeset 7708:54e1c9a68c7c.
Diffstat (limited to 'lexers/LexHTML.cxx')
-rw-r--r--lexers/LexHTML.cxx27
1 files changed, 24 insertions, 3 deletions
diff --git a/lexers/LexHTML.cxx b/lexers/LexHTML.cxx
index 650112220..8fce24581 100644
--- a/lexers/LexHTML.cxx
+++ b/lexers/LexHTML.cxx
@@ -563,6 +563,7 @@ struct OptionsHTML {
bool foldCompact = true;
bool foldComment = false;
bool foldHeredoc = false;
+ bool foldXmlAtTagOpen = false;
OptionsHTML() noexcept {
}
};
@@ -627,6 +628,10 @@ struct OptionSetHTML : public OptionSet<OptionsHTML> {
"Allow folding for heredocs in scripts embedded in HTML. "
"The default is off.");
+ DefineProperty("fold.xml.at.tag.open", &OptionsHTML::foldXmlAtTagOpen,
+ "Enable folding for XML at the start of open tag. "
+ "The default is off.");
+
DefineWordListSets(isPHPScript_ ? phpscriptWordListDesc : htmlWordListDesc);
}
};
@@ -992,6 +997,7 @@ void SCI_METHOD LexerHTML::Lex(Sci_PositionU startPos, Sci_Position length, int
const bool foldCompact = options.foldCompact;
const bool foldComment = fold && options.foldComment;
const bool foldHeredoc = fold && options.foldHeredoc;
+ const bool foldXmlAtTagOpen = isXml && fold && options.foldXmlAtTagOpen;
const bool caseSensitive = options.caseSensitive;
const bool allowScripts = options.allowScripts;
const bool isMako = options.isMako;
@@ -1207,6 +1213,9 @@ void SCI_METHOD LexerHTML::Lex(Sci_PositionU startPos, Sci_Position length, int
i += 2;
visibleChars += 2;
tagClosing = true;
+ if (foldXmlAtTagOpen) {
+ levelCurrent--;
+ }
continue;
}
}
@@ -1532,6 +1541,12 @@ void SCI_METHOD LexerHTML::Lex(Sci_PositionU startPos, Sci_Position length, int
// in HTML, fold on tag open and unfold on tag close
tagOpened = true;
tagClosing = (chNext == '/');
+ if (foldXmlAtTagOpen && !(chNext == '/' || chNext == '?' || chNext == '!' || chNext == '-' || chNext == '%')) {
+ levelCurrent++;
+ }
+ if (foldXmlAtTagOpen && chNext == '/') {
+ levelCurrent--;
+ }
styler.ColourTo(i - 1, StateToPrint);
if (chNext != '!')
state = SCE_H_TAGUNKNOWN;
@@ -1728,7 +1743,7 @@ void SCI_METHOD LexerHTML::Lex(Sci_PositionU startPos, Sci_Position length, int
state = SCE_H_DEFAULT;
}
tagOpened = false;
- if (!tagDontFold) {
+ if (!(foldXmlAtTagOpen || tagDontFold)) {
if (tagClosing) {
levelCurrent--;
} else {
@@ -1747,6 +1762,9 @@ void SCI_METHOD LexerHTML::Lex(Sci_PositionU startPos, Sci_Position length, int
ch = chNext;
state = SCE_H_DEFAULT;
tagOpened = false;
+ if (foldXmlAtTagOpen) {
+ levelCurrent--;
+ }
} else {
if (eClass != SCE_H_TAGUNKNOWN) {
if (eClass == SCE_H_SGML_DEFAULT) {
@@ -1776,7 +1794,7 @@ void SCI_METHOD LexerHTML::Lex(Sci_PositionU startPos, Sci_Position length, int
state = SCE_H_DEFAULT;
}
tagOpened = false;
- if (!tagDontFold) {
+ if (!(foldXmlAtTagOpen || tagDontFold)) {
if (tagClosing) {
levelCurrent--;
} else {
@@ -1802,7 +1820,7 @@ void SCI_METHOD LexerHTML::Lex(Sci_PositionU startPos, Sci_Position length, int
state = SCE_H_DEFAULT;
}
tagOpened = false;
- if (!tagDontFold) {
+ if (!(foldXmlAtTagOpen || tagDontFold)) {
if (tagClosing) {
levelCurrent--;
} else {
@@ -1826,6 +1844,9 @@ void SCI_METHOD LexerHTML::Lex(Sci_PositionU startPos, Sci_Position length, int
ch = chNext;
state = SCE_H_DEFAULT;
tagOpened = false;
+ if (foldXmlAtTagOpen) {
+ levelCurrent--;
+ }
} else if (ch == '?' && chNext == '>') {
styler.ColourTo(i - 1, StateToPrint);
styler.ColourTo(i + 1, SCE_H_XMLEND);