Skip to content

fix: enable HTML tag folding (#97)#98

Open
hybridmachine wants to merge 1 commit intomacos-portfrom
fix/html-tag-folding
Open

fix: enable HTML tag folding (#97)#98
hybridmachine wants to merge 1 commit intomacos-portfrom
fix/html-tag-folding

Conversation

@hybridmachine
Copy link
Copy Markdown
Owner

Summary

  • Enable HTML tag folding by setting fold.html=1 for hypertext, phpscript, and xml lexers in applyLanguageToView()
  • Add fold.hypertext.comment=1 for embedded script comment folding (Windows parity)
  • Set lexer.xml.allow.scripts=0 for XML files to match upstream setXmlLexer() behavior

Closes #97

Test plan

  • Open an HTML file — verify fold markers appear next to tag pairs (<div>, <section>, etc.)
  • Click a fold marker — content between open/close tags should collapse
  • Verify nested tags create nested, independently foldable regions
  • Verify self-closing tags (<br/>, <img/>) do NOT create fold points
  • Open an XML file — verify tag folding works
  • Open a PHP file — verify tag folding works
  • Open a C++ file — verify brace folding still works (no regression)
  • Open a Python file — verify indent folding still works (no regression)

🤖 Generated with Claude Code

The macOS port's applyLanguageToView() only set generic fold properties,
but LexHTML.cxx requires fold.html=1 to activate tag-based folding.
Add HTML-family fold properties for hypertext, phpscript, and xml lexers,
and disable embedded scripts for XML, matching upstream setXmlLexer().

Closes #97

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 8, 2026 06:08
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Enables HTML/XML tag folding support in the macOS Scintilla integration by setting LexHTML-related folding (and XML script-handling) properties during language application.

Changes:

  • Set fold.html=1 for hypertext, phpscript, and xml lexers to enable tag folding.
  • Enable embedded-script comment folding via fold.hypertext.comment=1 (Windows parity).
  • Disable embedded scripts for XML via lexer.xml.allow.scripts=0 to match upstream behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +342 to +354
// HTML-family fold properties (hypertext, phpscript, xml all use LexHTML.cxx)
if (strcmp(lang.lexerName, "hypertext") == 0 ||
strcmp(lang.lexerName, "phpscript") == 0 ||
strcmp(lang.lexerName, "xml") == 0)
{
ScintillaBridge_sendMessage(sci, SCI_SETPROPERTY, (uintptr_t)"fold.html", (intptr_t)"1");
ScintillaBridge_sendMessage(sci, SCI_SETPROPERTY, (uintptr_t)"fold.hypertext.comment", (intptr_t)"1");
}

// XML: disable embedded scripts (matches upstream setXmlLexer behavior)
if (strcmp(lang.lexerName, "xml") == 0)
{
ScintillaBridge_sendMessage(sci, SCI_SETPROPERTY, (uintptr_t)"lexer.xml.allow.scripts", (intptr_t)"0");
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lexer.xml.allow.scripts is only set to "0" for the XML lexer, but never reset when switching to other LexHTML-based lexers (e.g., "hypertext"). In LexHTML.cxx this flag controls whether <script> tags enter a script state at all, so opening an XML file first could disable script lexing (and related folding) in subsequent HTML/PHP views. Consider explicitly setting this property to "1" for non-XML lexers (or at least for "hypertext"/"phpscript") inside applyLanguageToView() so language switches don’t inherit the XML-only setting.

Suggested change
// HTML-family fold properties (hypertext, phpscript, xml all use LexHTML.cxx)
if (strcmp(lang.lexerName, "hypertext") == 0 ||
strcmp(lang.lexerName, "phpscript") == 0 ||
strcmp(lang.lexerName, "xml") == 0)
{
ScintillaBridge_sendMessage(sci, SCI_SETPROPERTY, (uintptr_t)"fold.html", (intptr_t)"1");
ScintillaBridge_sendMessage(sci, SCI_SETPROPERTY, (uintptr_t)"fold.hypertext.comment", (intptr_t)"1");
}
// XML: disable embedded scripts (matches upstream setXmlLexer behavior)
if (strcmp(lang.lexerName, "xml") == 0)
{
ScintillaBridge_sendMessage(sci, SCI_SETPROPERTY, (uintptr_t)"lexer.xml.allow.scripts", (intptr_t)"0");
// HTML-family properties (hypertext, phpscript, xml all use LexHTML.cxx)
if (strcmp(lang.lexerName, "hypertext") == 0 ||
strcmp(lang.lexerName, "phpscript") == 0 ||
strcmp(lang.lexerName, "xml") == 0)
{
ScintillaBridge_sendMessage(sci, SCI_SETPROPERTY, (uintptr_t)"fold.html", (intptr_t)"1");
ScintillaBridge_sendMessage(sci, SCI_SETPROPERTY, (uintptr_t)"fold.hypertext.comment", (intptr_t)"1");
// XML disables embedded scripts; other LexHTML-based lexers must re-enable them
// so switching away from XML does not inherit the XML-only setting.
ScintillaBridge_sendMessage(
sci,
SCI_SETPROPERTY,
(uintptr_t)"lexer.xml.allow.scripts",
(intptr_t)(strcmp(lang.lexerName, "xml") == 0 ? "0" : "1"));

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

P0-17: Add HTML tag folding support

2 participants