ScottinPollock wrote: ↑2018-07-19 10:13:47
Think I am seeing a bug here... not in your Macro but in NWP.
I think this is a "feature", not a bug
Page breaks are treated as text characters, and are not counted as start of paragraphs, though they allow different paragraph styles on either side. It's a bit weird, but, I believe, a result of Nisus' legacy treatment of page breaks.
There even seems to be some confusion on Nisus Co.'s part about this, as the Find Wildcard "Any" is
(?:.|\n|\f)+ where the '\f' seems to be superfluous.
But…
When you write:
It missed every "Heading 1" after the page breaks. In fact, those paragraphs were not in the array created by $doc.text.find('^.+\n','Ea'). It wasn't until I put a CR in front of those header 1 paragraphs (after the page breaks) that text.find actually included them in the array.
Did you not have CRs
before the page breaks? (That is where I would put them.)
So if you are in the habit of using page breaks without CRs you might want to use the find expression '(?<=^|\f)[^\f]+(?:\n|\f|$)' instead to locate your 'lines'.
I realized I had some text after the result codes with a 'Heading 1' style as well. Each one was after an inserted page break. No problem I figure... so in your 'as you go' method I just changed:
Code: Select all
if $attr.paragraphStyleName == "Heading 2"
$gear2 = @false
else
$resultSels.push $para
end
to:
[snip]
I would suggest the following instead:
Code: Select all
if $attr.paragraphStyleName.find("Heading \d",'E')
$gear2 = @false
else
$resultSels.push $para
end
That will cover all Heading styles. But of course it will also not work, if you have page breaks inside paragraphs. It will still depend on using the more complicated find string for "paragraphs"
On the other hand... The following works perfectly (although much slower):
Code: Select all
Select Document Start
While Find 'Result Codes', '-W'
while Select Next Paragraph
$sel = TextSelection.active
$attr = $sel.text.attributesAtIndex $sel.location
if $attr.paragraphStyleName == 'Heading 2'
break
elseIf $attr.paragraphStyleName == 'Heading 1'
break
end
Paragraph Style:result codes it
end
end
NB: In this code too, you can use the
.find('Heading') condition instead.
You're right. The Select Next Paragraph command treats text terminated by a PB as a paragraph. The above code is slow, because it does all the work via the visual interface (the "light show" of Classic days). It just doesn't look as flashy anymore, since computers are faster (and Nisus probably has some optimizations to suppress redrawing, or something). So in the end I would really recommend the 'holistic' method, though that too would require some adjustments for handling multiple Heading styles.
But just to summarize the break character ('\f') is treated as a text character in grep. So it's not a bug, and it isn't something Nisus can change.