Problem adding Named Styles to Text.Ranges


#1

In OmniOutliner (5.4.1/GM-v194.5), I have:

  • An Item (“textObj”) containing text (“This is a very simple test”) that’s entirely unstyled
  • A Named Style “Bold” that has only a “font weight: Bold” attribute
  • A Named Style “Italic” that has only a “font italic: yes” attribute

What does work as I expect:

If I retrieve my “This is a very simple test” text like this:

var textObj = item.valueForColumn(topicColumn);

…then construct a range (“bigStyleRange”) including just the words “is a very simple” and apply the “Bold” Named Style like this:

textObj.styleForRange(bigStyleRange).addNamedStyle(myBoldNamedStyle);

…and then construct a smaller range (“smallStyleRange”) including just the word “very” and apply the “Italic” Named Style like this:

textObj.styleForRange(smallStyleRange).addNamedStyle(myItalicNamedStyle);

…the results are as-expected, and the text in the node then looks like this:

  • This is a very simple test

What does not work as I expect:

If I flip the order of application, and apply the Italic to the single word first, and then apply the Bold to the larger range of words that includes the single word, the italics are lost, and I get this:

  • This is a very simple test

My question:

How can I apply a named style to a larger range of words in a manner that won’t override the styling of words within it?

Or do I misunderstand the problem?