Skip to content

Commit

Permalink
preserve tag font and highlight colors when embedding (#1748)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevencohn authored Jan 2, 2025
1 parent 8d5a924 commit d6495f5
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
3 changes: 0 additions & 3 deletions OneMore/Commands/Styles/ApplyStyleCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,6 @@ private bool StylizeParagraphs()

private void SetQuickStyle(Page page, XElement element, Style style)
{

System.Diagnostics.Debugger.Launch();

if (style.StyleType == StyleType.Heading &&
// must be in heading range h1=0..h6=5
style.Index < 6)
Expand Down
12 changes: 10 additions & 2 deletions OneMore/Models/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,11 @@ public string AddTagDef(string symbol, string name, int tagType = 0)
int index = 0;
if (tags?.Any() == true)
{
var tag = tags.FirstOrDefault(e => e.Attribute("symbol").Value == symbol);
var tag = tags.FirstOrDefault(e =>
e.Attribute("symbol").Value == symbol &&
e.Attribute("fontColor").Value == "automatic" &&
e.Attribute("highlightColor").Value == "none");

if (tag is not null)
{
return tag.Attribute("index").Value;
Expand All @@ -259,7 +263,11 @@ public void AddTagDef(TagDef tagdef)
var tags = Root.Elements(Namespace + "TagDef");
if (tags?.Any() == true)
{
var tag = tags.FirstOrDefault(e => e.Attribute("symbol").Value == tagdef.Symbol);
var tag = tags.FirstOrDefault(e =>
e.Attribute("symbol").Value == tagdef.Symbol &&
e.Attribute("fontColor").Value == tagdef.FontColor &&
e.Attribute("highlightColor").Value == tagdef.HighlightColor);

if (tag is not null)
{
return;
Expand Down
25 changes: 21 additions & 4 deletions OneMore/Models/TagDef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,19 @@ public int IndexValue


/// <summary>
/// Static, indicates the specific glyph used for the tag
/// Gets the unique font color of this symbol tag
/// </summary>
public string FontColor => Attribute("fontColor").Value;


/// <summary>
/// Gets the unique highlight color of this symbol tag
/// </summary>
public string HighlightColor => Attribute("highlightColor").Value;


/// <summary>
/// Gets the specific glyph used for the tag
/// </summary>
public string Symbol => Attribute("symbol").Value;

Expand All @@ -79,10 +91,15 @@ public int IndexValue
/// <returns>True if the Symbols are equal</returns>
public override bool Equals(object obj)
{
if (obj is XElement other)
if (obj is XElement other && other.Name.LocalName == "TagDef")
{
// this is all we care about; OneNote allows exactly one of each symbol, no more
return Attribute("symbol").Value.Equals(other.Attribute("symbol").Value);
// OneNote typically allows one of each symbol, however, you can have multiple
// instances of each symbol as long as the font/highlight colors are unique

return
Symbol.Equals(other.Attribute("symbol").Value) &&
FontColor.Equals(other.Attribute("fontColor").Value) &&
HighlightColor.Equals(other.Attribute("highlightColor").Value);
}

return false;
Expand Down
2 changes: 1 addition & 1 deletion OneMore/Models/TagMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void MergeTagDefsFrom(Page sourcePage)
// resolve source tagdefs with target tagdefs
foreach (var source in sourcedefs)
{
var mapping = map.Find(m => m.TagDef.Symbol == source.Symbol);
var mapping = map.Find(m => m.TagDef.Equals(source));
if (mapping is null)
{
// no match so add it and set index to maxIndex+1
Expand Down

0 comments on commit d6495f5

Please sign in to comment.