Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Apply these styles to page" does not work for "code" style #1543

Open
erikwihlborg76 opened this issue Aug 15, 2024 · 7 comments
Open

"Apply these styles to page" does not work for "code" style #1543

erikwihlborg76 opened this issue Aug 15, 2024 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@erikwihlborg76
Copy link

Problem to Solve

The feature "Apply style to page" should apply all styles that can be mapped to any of the OneNote default styles. It works great for headers, but it does not work for the "code" style.

To Reproduce

  1. Write a text
  2. Apply the OneNote default "code" style to the text.
  3. Select "Apply these styles to page"
  4. The text tagged as "code" is changed to normal text

Expected Behavior

Applying the styles to a page should change the text tagged as "code" to the style defined in the OneMore add-on.

Screenshots

n/a

Environment (if applicable)

  • OneNote Version: O365, 64bit

Additional Context

@erikwihlborg76 erikwihlborg76 added bug Something isn't working unread I have seen it or had time to refine it yet labels Aug 15, 2024
@stevencohn stevencohn removed the unread I have seen it or had time to refine it yet label Aug 15, 2024
@stevencohn
Copy link
Owner

Was your custom Code style based on the default code style, and then customized? Is the name of your custom style either "code" or "source code"?

Here's an animated GIF showing OneMore 6.5 applying styles including a custom "Code" style based on the default code style, using a different font and color. Since my style was based on the default code style, it still indicates in the OneNote style dropdown that it is code, however it has applied my custom styling to it as well.

image-demo

@erikwihlborg76
Copy link
Author

Apologies, this is so strange. I can´t reproduce it now 🫢 Will try some more.

I use default settings for OneMore styles.

I may have noticed another bug though. If I tag a text with the "code" style and then apply the OneMore styles to the page, the formatting of the text changes to the OneMore code style, but the "code" tag is removed from the text when I check the default styles.

Headers, on the other hand, work as I would expect. For example, if I tag a text with the "header 1" tag and then apply the OneMore styles to the complete page, the text is still tagged as "header 1" but the formatting is set based on the OneMore header 1 style.

@stevencohn
Copy link
Owner

I can't seem to reproduce that code style mapping issue.

@stevencohn stevencohn added the no-repro Cannot reproduce label Oct 15, 2024
@cspotcode
Copy link

cspotcode commented Oct 19, 2024

I am hitting this now, I've recorded a video reproduction.

If I set the OneMore's "Code" style, it loses OneNote's "Code" classification. Subsequently, "Apply styles to this page" removes the monospaced font because it thinks it's "Normal" text with a monospaced font.

But if I set the "Code" style using OneNote's button, it keeps the "Code" classification, and OneMore's "Apply styles to this page" does not break it.

Ignore the printer dialog; I got the Ctrl+, hotkey mixed up and accidentally pressed Ctrl+P

2024-10-19.12-29-31.mp4

I also noticed that the "Code" style in OneMore does not fully erase the "Quote" style from OneMore.
Using OneMore: set style to Quote, then to Code. Text is monospace and still italics.
Using OneNote: set style to Quote, then to Code. Text is monospace, not italic.

2024-10-19.12-34-46.mp4

I hope this is helpful! Let me know if there's more I can do to help reproduce.

@stevencohn stevencohn removed the no-repro Cannot reproduce label Oct 19, 2024
@stevencohn stevencohn self-assigned this Oct 19, 2024
@cspotcode
Copy link

I learned about Ctrl+Alt+Shift+X and did another experiment, inspecting the XML after each edit. I also learned a lot from OneMore's excellent developer docs. I think this is related to QuickStyleDef names.

https://onemoreaddin.com/developers/TechNote%20-%20Styles.htm

When you create a new style, you can choose whether it is a paragraph style, a character style, or a heading.

When a new heading style is created ... By reusing the standard h1..h6 internal names...
All other custom styles are represented by a new "p" Quick Style.

I believe the fix is for OneMore's custom style "Code" to have name="code" instead of name="p".

<!-- must have name="code" -->
<one:QuickStyleDef index="???" name="code" 

My hunch is, when you "Apply These Styles to Page", OneMore modifies each QuickStyleDef in-place, replacing the formatting attributes but preserving the name.

But when you apply an individual OneMore style to a line, OneMore writes a new QuickStyleDef with name="p". This loses the semantic classification of that line as "Code."

Reproduction

  1. New page
  2. Add line "this is onenote code" and format it as code using OneNote style
  3. Add line "this is onemore code" and format it as code using OneMore style
  4. Ctrl+Alt+Shift+X to Inspect XML
  <one:QuickStyleDef index="1" name="code" fontColor="automatic" highlightColor="automatic" font="Consolas" fontSize="11.0" spaceBefore="0.0" spaceAfter="0.0" />
  <one:QuickStyleDef index="2" name="p" fontColor="automatic" highlightColor="automatic" font="Calibri" fontSize="11.0" spaceBefore="0.0" spaceAfter="0.0" />
...
      <one:OE alignment="left" quickStyleIndex="1">
        <one:T><![CDATA[this is onenote code]]></one:T>
      </one:OE>
      <one:OE alignment="left" quickStyleIndex="2">
        <one:T><![CDATA[]]></one:T>
      </one:OE>
      <one:OE alignment="left" quickStyleIndex="2" style="font-family:Consolas;font-size:11.0pt">
        <one:T><![CDATA[this is onemore code]]></one:T>
      </one:OE>
  1. OneMore "Apply these styles to page"
  2. Ctrl+Alt+Shift+X to inspect XML
  <one:QuickStyleDef index="1" name="code" fontColor="#000000" highlightColor="automatic" font="Consolas" fontSize="11.0" spaceBefore="0.0" spaceAfter="0.0" />
  <one:QuickStyleDef index="2" name="p" fontColor="#000000" highlightColor="automatic" font="Calibri" fontSize="11.0" spaceBefore="0.0" spaceAfter="0.0" />
...
      <one:OE alignment="left" quickStyleIndex="1">
        <one:T><![CDATA[this is onenote code]]></one:T>
      </one:OE>
      <one:OE alignment="left" quickStyleIndex="2">
        <one:T><![CDATA[]]></one:T>
      </one:OE>
      <one:OE alignment="left" quickStyleIndex="2">
        <one:T><![CDATA[this is onemore code]]></one:T>
      </one:OE>

For OneMore's code style, QuickStyleDef index="2", I'm not sure why the StyleDef has font=Calibri and the <one:T> has font=Consolas. Is this OneNote "normalizing" styles in an unexpected way?

@stevencohn
Copy link
Owner

Your analysis is exactly right. It does need to use the built-in "code" quickstyle. OneNote allows multiple definitions of each quickstyle so that would work. And it would need its own Style Type in the OneMOre edit styles dialog box, "Code - entire paragraph". Unfortunately, the code quickstyle can only apply to and entire paragraph, not an inline text run. The OneMore style definition library XML files would each need updating with an upgrade reader-makes-right path.

@stevencohn
Copy link
Owner

This ticket blocks #1612

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants