"Go to Next Comment" fails with nested comments
"Go to Next Comment" fails with nested comments
The "Go to Next Comment" command doesn't seem to work as I would expect when comments are nested (i.e. when more than one separate comment is applied to the same piece of text). The first such comment is selected OK, but subsequent ones are ignored.
Is this a bug or a feature?
I'm posting here because outside the context of macros I don't see this as a big problem. But when I'm trying to use a macro to change the formatting of a whole bunch of comments, it's a nuisance. I'm borrowing heavily from this macro from Martin, and any macro using "Menu 'Go to Next Comment'" will see the same problem.
When comments are added via NWP's nice "+" button, "Go to Next Comment" shows them in their proper order, so I suppose in principle we should not need to use nested comments. But when working with Word users, a stack of "+" comments gets converted to individual comments, and the trouble begins. Besides, even in NWP it's nice to have the option of showing all comments at once, rather than flipping through them with the arrow buttons.
Is this a bug or a feature?
I'm posting here because outside the context of macros I don't see this as a big problem. But when I'm trying to use a macro to change the formatting of a whole bunch of comments, it's a nuisance. I'm borrowing heavily from this macro from Martin, and any macro using "Menu 'Go to Next Comment'" will see the same problem.
When comments are added via NWP's nice "+" button, "Go to Next Comment" shows them in their proper order, so I suppose in principle we should not need to use nested comments. But when working with Word users, a stack of "+" comments gets converted to individual comments, and the trouble begins. Besides, even in NWP it's nice to have the option of showing all comments at once, rather than flipping through them with the arrow buttons.
Re: "Go to Next Comment" fails with nested comments
Well as pointed out on the other thread you should be able to find the answer in the file Help > Macro Language Reference.
There you'll find there is a document propery .allComments which will return the comments and then you should be able to loop through them with code
or something to that effect.
There you'll find there is a document propery .allComments which will return the comments and then you should be able to loop through them with code
Code: Select all
$doc = Document.active
foreach $comment in $doc.allComments
…
end
philip
Re: "Go to Next Comment" fails with nested comments
Anyhow just one more comment to the "Go to Next Comment" you mentioned and used in Martin's macro. That command does work for nested comments. I just tested it. However Martin's macro doesn't find them, since it uses the expedient of placing the selection after the comment to look for the next one. The macro could be improved by returning the cursor to the beginning of the selection instead of the end.
philip
Re: "Go to Next Comment" fails with nested comments
Thank you. After some fiddling:phspaelti wrote:or something to that effect.Code: Select all
$doc = Document.active foreach $comment in $doc.allComments … end
Code: Select all
ForEach $comment in $doc.allComments
$range = Range.new(0, $comment.text.length)
$selection = TextSelection.new($comment.text, $range)
$doc.setSelection($selection)
Menu 'Paragraph Style:Comment'
End
Re: "Go to Next Comment" fails with nested comments
Odd, because for me "Go to Next Comment" skips nested comments even when I choose it from the main menu, so I was not surprised that it didn't work in a macro.phspaelti wrote:Anyhow just one more comment to the "Go to Next Comment" you mentioned and used in Martin's macro. That command does work for nested comments. I just tested it. However Martin's macro doesn't find them, since it uses the expedient of placing the selection after the comment to look for the next one. The macro could be improved by returning the cursor to the beginning of the selection instead of the end.
To be clear, my "nested comments" are multiple comments applied to the identical text range via the "Add Comment" command. If one comment's text range overlaps or encloses the other, then "Go to Next Comment" behaves as expected. And the same is true of comments created by clicking the "+" sign at the bottom of an existing comment.
Re: "Go to Next Comment" fails with nested comments
Note that in the macro reference under Document Object Commands (selection additions) it says…chazzo wrote:Is there a more elegant way to do that?Code: Select all
ForEach $comment in $doc.allComments $range = Range.new(0, $comment.text.length) $selection = TextSelection.new($comment.text, $range) $doc.setSelection($selection) Menu 'Paragraph Style:Comment' End
So in fact you can simplify the above to:Nisus Macro Reference wrote:…
3. A Text object following reference semantics, indicating all its text should be selected.
Code: Select all
ForEach $comment in $doc.allComments
$doc.setSelection $comment.text
Menu 'Paragraph Style:Comment'
End
One alternative (which doesn't save anything here) is to loop throughout $doc.allTexts, and check the texts for their .documentContentType. So like this:
Code: Select all
ForEach $text in $doc.allTexts
if $text.documentContentType == "comment"
$doc.setSelection $text
Menu 'Paragraph Style:Comment'
end
End
philip
Re: "Go to Next Comment" fails with nested comments
Ah! I thought that Nisus didn't allow this kind of thing. (I really don't use comments too often.) I think Nisus doesn't allow such things to be created, but it probably respects them if they exist in an imported document. However the identity of the anchor text would create problems. Maybe Martin can enlighten us on this one.chazzo wrote:To be clear, my "nested comments" are multiple comments applied to the identical text range via the "Add Comment" command.
philip
- martin
- Official Nisus Person
- Posts: 5228
- Joined: 2002-07-11 17:14:10
- Location: San Diego, CA
- Contact:
Re: "Go to Next Comment" fails with nested comments
I'd consider this a bug, especially as the "Go to Previous Comment" command has no troubles. I'll file it, thanks.chazzo wrote:Odd, because for me "Go to Next Comment" skips nested comments even when I choose it from the main menu, so I was not surprised that it didn't work in a macro.
To be clear, my "nested comments" are multiple comments applied to the identical text range via the "Add Comment" command. If one comment's text range overlaps or encloses the other, then "Go to Next Comment" behaves as expected.
- martin
- Official Nisus Person
- Posts: 5228
- Joined: 2002-07-11 17:14:10
- Location: San Diego, CA
- Contact:
Re: "Go to Next Comment" fails with nested comments
Philip already provided some elegant ways to do that with a macro, but here's another:chazzo wrote:Is there a more elegant way to do that?Code: Select all
ForEach $comment in $doc.allComments $range = Range.new(0, $comment.text.length) $selection = TextSelection.new($comment.text, $range) $doc.setSelection($selection) Menu 'Paragraph Style:Comment' End
Code: Select all
Find All '(?:.|\n)+', 'E', '-ac'
Menu 'Paragraph Style:Comment'
I'd also point out that you don't necessarily need a macro for this. You can just place the selection into any comment, Select All to select all text in that comment, and Select All again to select all text in all comments. Then you can manipulate and format all comments however you like.
- martin
- Official Nisus Person
- Posts: 5228
- Joined: 2002-07-11 17:14:10
- Location: San Diego, CA
- Contact:
Re: "Go to Next Comment" fails with nested comments
If you did happen to have an array of all comment text objects, then ".setSelections" would indeed accept that. It actually accepts any of the objects mentioned in the documentation for ".setSelection" and should be updated to reflect that.phspaelti wrote:I was sort of wondering whether .setSelections might allow an array of texts as an argument (which would eliminate the need for the loop too!), but since one doesn't have access to the array of all and only the comment texts you'll need a loop anyhow.
NWP does indeed let the users create such comments, where multiple comments are applied to exactly the same marked/anchoring text in the document, and in general shouldn't have any trouble handling or manipulating them– the bug with "Go To Next Comment" Charles found aside of course.I think Nisus doesn't allow such things to be created, but it probably respects them if they exist in an imported document. However the identity of the anchor text would create problems. Maybe Martin can enlighten us on this one.
Re: "Go to Next Comment" fails with nested comments
I hadn't noticed that "Go to Previous Comment" behaves differently. But the definitions of "previous" and "next" are also quite strange. I've just placed five successive comments on the same text range (using Esc to move back to the document text so as not to disturb the selection). The display order was 3, 5, 4, 1, 2. And when I did it again I got a different ordermartin wrote:I'd consider this a bug, especially as the "Go to Previous Comment" command has no troubles. I'll file it, thanks.
I commonly get a stack of comments like this when exchanging documents, and it helps to be able to read them in the order they were created.
Re: "Go to Next Comment" fails with nested comments
Thank you (and Philip for the previous simplification). That's very useful, and so are some of the other options for searching from a macro. I didn't realise, for instance, that this is the only way to search for a specific footnote reference.martin wrote:Philip already provided some elegant ways to do that with a macro, but here's another:That leverages the Find's "where" argument to only match text in the comment areas.Code: Select all
Find All '(?:.|\n)+', 'E', '-ac' Menu 'Paragraph Style:Comment'
Aha! In a footnote, one round of Select All selects all text in all footnotes. Needing to apply it twice for comments is clever, but inconsistent?martin wrote:I'd also point out that you don't necessarily need a macro for this. You can just place the selection into any comment, Select All to select all text in that comment, and Select All again to select all text in all comments. Then you can manipulate and format all comments however you like.
Re: "Go to Next Comment" fails with nested comments
Well, it's due to the difference in how they are handled. Footnotes all live together inside a single text object (and Nisus "cleverly" uses tabs, returns and page breaks to separate them, much to Kino's chagrin). But Comments and Table cells each form their own text object.chazzo wrote:Aha! In a footnote, one round of Select All selects all text in all footnotes. Needing to apply it twice for comments is clever, but inconsistent?
I assume the reason for the difference treatment has to do with how they need to be formatted. Footnotes all have to be formatted together, so one can figure out how much will fit on a page. But with table cells each cell forms a complete object and formatting of one should't affect the neighbours. For comments too it makes more sense to treat them as completely separate entities, even though independent formatting is perhaps not that crucial.
philip
Re: "Go to Next Comment" fails with nested comments
Thank you -- that makes perfect sense.phspaelti wrote:Well, it's due to the difference in how they are handled. Footnotes all live together inside a single text object (and Nisus "cleverly" uses tabs, returns and page breaks to separate them, much to Kino's chagrin). But Comments and Table cells each form their own text object.
The footnotes in my current document were faultlessly created from comments using your own macro. I imagine converting footnotes to comments would be harder, if that's what Kino is struggling with.
- martin
- Official Nisus Person
- Posts: 5228
- Joined: 2002-07-11 17:14:10
- Location: San Diego, CA
- Contact:
Re: "Go to Next Comment" fails with nested comments
That's a valid point, and perhaps we should change it. Personally I find that the double "Select All" process makes more sense to me, and it gives the user more flexibility. The only downside is lower discoverability.chazzo wrote:Aha! In a footnote, one round of Select All selects all text in all footnotes. Needing to apply it twice for comments is clever, but inconsistent?
Philip is exactly right with his explanation on this, which he no doubt smartly deduced from his experience with the Nisus macro language:
A lot of this is due to the way Nisus Writer leverages Apple's text layout engine, and the need to have footnote content flow between pages or lay out adjacent footnotes naturally.phspaelti wrote:Footnotes all live together inside a single text object (and Nisus "cleverly" uses tabs, returns and page breaks to separate them, much to Kino's chagrin). But Comments and Table cells each form their own text object.
I assume the reason for the difference treatment has to do with how they need to be formatted. Footnotes all have to be formatted together, so one can figure out how much will fit on a page.