Skip to content

Conversation

@miiizen
Copy link
Contributor

@miiizen miiizen commented Jun 20, 2025

Resolves: #19189

This PR encodes line breaks as <br/> for TextBase items, fixing the loss of newlines after XML tags - eg. formatting & symbols.
This isn't a huge change and preserves backwards compatibility. TextBase still needs to turn \n into newlines when setting text on user input. This means old files using actual newlines in the XML can still be read.

@miiizen miiizen force-pushed the 19189-xml-newline branch from 793aa49 to 5c4c27b Compare June 20, 2025 14:50
@cbjeukendrup
Copy link
Member

If we wanted to be less verbose and use a <br/> tag, we would need to implement a way to condense tags with no inner content in XmlReader::htmlToString.

That would be nice indeed... it looks like TinyXML's XMLElement::ClosingType could help here, but the bigger problem is of course that the interface of XmlStreamReader doesn't offer a way to differentiate between a start tag or a <…/> tag (they are both StartElement). And changing the meaning of StartElement in order to introduce a new enum value for <…/> tags, might be intensive. Perhaps m_xml->node provides enough information to make a new member in XmlStreamReader that just queries whether the current start tag was a <…> or a <…/>.

Also, this is the sort of thing where a unit test would seem nice to me (and perhaps even more appropriate than a VTest).

@miiizen miiizen force-pushed the 19189-xml-newline branch from 5c4c27b to 0b0b693 Compare June 23, 2025 12:38
} else {
LOGD("unknown symbol <%s>", muPrintable(sym));
}
} else if (token == "br/") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Uhm, I don't love the idea that the layout code knows about this, unless it's absolutely necessary. As far as I understand, the problem only involves the XML reading, not the program runtime. The program itself has no problem dealing with line breaks, so I don't see a reason why the substitution of line breaks with tags should be carried all the way into the runtime. If it's possible, I think the ideal approach would be

  • On write: check the string for line breaks just before writing it to the file, and write to the file a version of that string where line breaks are replaced with tags.
  • On read: read the string normally, then do a second pass on it to check it for line-break tags and replace them with actual line breaks.

That way the knowledge about this tag is strictly confined to the read/write modules and no other part of the program needs to deal with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I think you're probably right - though couldn't this be extended to all other tags in the xml text?

@miiizen miiizen force-pushed the 19189-xml-newline branch 3 times, most recently from 114e9bb to cdabfa7 Compare July 2, 2025 07:43
@rpatters1
Copy link
Contributor

rpatters1 commented Jul 20, 2025

I am hoping this PR will also work with instrument names. I frequently have instrument names like this:

Screenshot 2025-07-20 at 7 10 56 AM

MuseScore itself (I have discovered) can handle this if you programmatically insert the new line. But of course the new line gets lost when the file is read back from xml.

What's really needed (but obviously out of scope for this PR) is the ability to edit instrument names in the full text editor.

@its-not-nice its-not-nice added the vtests This PR produces approved changes to vtest results label Nov 11, 2025
@miiizen miiizen merged commit a818143 into musescore:master Nov 11, 2025
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

vtests This PR produces approved changes to vtest results

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Blank lines in formatted text lost on open

5 participants