Select All in Highlight
Select All in Highlight
There is no standard menu "Select All in Highlight", though this can by done manually ( in the Menu with the mini icons on the bottom of the page. (Wich appears if the cursor is inside highlighted text). I wonder if it is possible to create a macro that selects All in Highlight.
Re: Select All in Highlight
Here is a quick example of how to do this. The ugly bit is that it prompts the user with color objects which are hard to read.
- Attachments
-
Select All in HighLight.nwm
- (7.28 KiB) Downloaded 488 times
philip
Re: Select All in Highlight
I think Kino's macro "SelectByColor" does exactly that.
I think Kino has a nice solution to this problem. He offers the option "Show Samples".
See: <http://www.nisus.com/forum/viewtopic.php?f=18&t=4151>
-------
In the Nisus Macro Reference I found this command:
.textHighlightColor
and—not surprisingly— no examples of how to use this command. :–(
What am I supposed to put in front of the the dot?
Re: Select All in Highlight
Hey Þorvarður,
If your current selection includes some highlight this will show you the color (in color code form).
The most obvious/useful way to work with attributes is to use, what I call, a "Kino-loop"; basically cycle though the whole document attribute section by attribute section:
Then you can process the attributes in some way inside the loop.
You may need to use .rangeOfDisplayAttributesAtIndex instead, depending on the purpose.
I don't know that one. Though Color and Highlight (color) are not really the same thing. The former affects the text/font, while the latter is a special marking attribute.
To be honest I was just being lazy. It would have required a lot of extra work on my part, and I just didn't feel like spending the time on that kind of thing. Kino obviously worked hard to make some very well worked out macros.Þorvarður wrote: ↑2023-08-20 12:06:02I think Kino has a nice solution to this problem. He offers the option "Show Samples".
See: <http://www.nisus.com/forum/viewtopic.php?f=18&t=4151>
Well, you find that command (actually a property, but who's keeping track) under the attribute object, which means you need an attribute object before the dot. You can get attribute objects in any of half a dozen different ways. For example:
Code: Select all
$attr = Attributes.selectedAttributes
prompt $attr.textHighlightColor
The most obvious/useful way to work with attributes is to use, what I call, a "Kino-loop"; basically cycle though the whole document attribute section by attribute section:
Code: Select all
$doc = Document.active
$loc = 0
while $loc < $doc.text.length
$range = $doc.text.rangeOfAttributesAtIndex $loc
...
$loc = $range.bound
end
You may need to use .rangeOfDisplayAttributesAtIndex instead, depending on the purpose.
philip
Re: Select All in Highlight
Thank you both for your help. The macro sent by Philip can in fact do more than I need, but there is a problem:
As to more than I need:
I use highlights by defining one color only which I insert by a macro. To find all highlights created by that macro I just had to adapt Philip's Macro. Instead of the lines providing user choice I just inserted what I defined as $myHilite, like this:
As to the problem:
The macro works fine with contiguous text. But I need it also with a table which has some of its elements marked with that highlight. While the menu at the bottom of the page selects the elements as expected, the macro does not. Can you see why?
As to more than I need:
I use highlights by defining one color only which I insert by a macro. To find all highlights created by that macro I just had to adapt Philip's Macro. Instead of the lines providing user choice I just inserted what I defined as $myHilite, like this:
Code: Select all
if $highLights.keys.count
$myHilite = Color.newWithHexTriplet 0x0FFFFA3
$doc.setSelection $highLights{$myHilite}
...
The macro works fine with contiguous text. But I need it also with a table which has some of its elements marked with that highlight. While the menu at the bottom of the page selects the elements as expected, the macro does not. Can you see why?
Re: Select All in Highlight
Yes, of course. My macro crudely uses $doc.text. If one wants to find highlight in all text areas of the document one needs to use $doc.allTexts and loop through each of the text objects separately. Fortunately this does not require a huge change.
I'm submitting a changed version of my macro, and will let you do the adjustments for your purpose

- Attachments
-
Select All in HighLight.nwm
- (7.42 KiB) Downloaded 504 times
philip
Re: Select All in Highlight
Thank you Philip. That works fine now!
Re: Select All in Highlight
I'm all for using the right terminology, so thanks for reminding me, and thanks for the examples.
I think one difference to Kino's macro is that his macro enables one to find and select any Highlighted and any Background color as well as colored text in the document. No part of the document needs to be first selected.
The "samples":
I just thought I should point this out, as this might perhaps be useful for someone else who needs to work with Highlight and Background colors.