Questions re highlighting and keyboard shortcuts

Everything related to our flagship word processor.
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Questions re highlighting and keyboard shortcuts

Post by martin »

dgbchr wrote: 2022-02-21 15:01:52 I have to rely on the "Select Next in Highlight" command ... and because this appears only in the status bar but not in the menu bar, I do not see how to assign it a shortcut.
This does seem to be an omission. The command should appear in the main menu bar too.
It seems strange to me that there is no "Select Previous" option for styles or highlighting ... is something you might add at some point?
That's a good idea too.
... in which the metacharacters are situated too high, no matter how I resize or scroll the Find & Replace window
This appears to be a bug that occurs on newer versions of macOS. I'm sorry for the clipped PowerFind bubbles.

Thanks for the feedback, suggestions, and bug report!
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Questions re highlighting and keyboard shortcuts

Post by martin »

Vanceone wrote: 2022-02-22 09:20:36 This is how the text system works under the hood in Mac OS X, and Nisus has adopted it as far as I know. "NSAttributedString" is an Apple programming concept which you can be grateful Nisus has abstracted away, as the Nisus Macro language is far easier to use than a pure NSAttributedString.
That's all correct. Nisus Writer generally adopts and extends the macOS text system, including how attributes are attached to text. Understanding that is a good head-start for understanding the way the Nisus macro language handles text formatting. Though this is all "inside baseball" stuff that isn't really necessary.
I'm sure someone can show a practical example rather than this theory craft
I just posted a reply that shows how to inspect the Attributes and highlighting color associated with the current selection.
Þorvarður
Posts: 410
Joined: 2012-12-19 05:02:52

Re: Questions re highlighting and keyboard shortcuts

Post by Þorvarður »

Vanceone wrote:
you don't need to know about NSAttributedString to use the Macro language …
Thanks for the detailed explanation, Vanceone.

I would like to take back the words "this all sounds like a gobbledygook to me." These words were not directed towards you, and I should have made that clear. What I was thinking of is the Macro Language Reference which provides an exhaustive list of available macro features, but doesn't teach us how to use them.
dgbchr
Posts: 7
Joined: 2022-02-17 08:50:51

Re: Questions re highlighting and keyboard shortcuts

Post by dgbchr »

@Þorvarður --
there is a fundamental difference between highlighting and bookmarks
Indeed, and thank you for pointing it out. I think they can both be useful, and it is nice that NWP gives us both tools to play with.

@martin -- thanks for your suggestions and kind responses to my various bits of feedback!

Here is a macro I devised, based on tips here and elsewhere in the forums, that toggles highlighting on/off:

Code: Select all

$selection = TextSelection.active
$attributes = $selection.firstAttributes
If $attributes.textHighlightColor
	Remove Highlight Formatting
Else
	$Yellow = Color.newWithRGB255(239, 252, 118)
	Set Highlight Color $Yellow	
End
It's my very first macro and so could probably be improved! If anyone has suggestions please chime in.

One behavior I wish were different is: If only the first part of my selected text is highlighted (but the remainder is not), this macro will remove highlight formatting. I'd rather it instead add highlight formatting ... much like hitting CMD-B adds bold formatting when only the first part of the selected text is already bold. Does that make sense? Is there a way to do that? If this is getting too much into the weeds, let me know; I can be happy with the above. Thanks again.
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Questions re highlighting and keyboard shortcuts

Post by martin »

dgbchr wrote: 2022-02-23 11:39:24 It's my very first macro and so could probably be improved! If anyone has suggestions please chime in.
Looking good to me! 😎
One behavior I wish were different is: If only the first part of my selected text is highlighted (but the remainder is not), this macro will remove highlight formatting. I'd rather it instead add highlight formatting ... much like hitting CMD-B adds bold formatting when only the first part of the selected text is already bold. Does that make sense? Is there a way to do that?
There's definitely a way to do that and it's conceptually not difficult: the macro needs to check if there's highlighting at the start and end of the text selection. Here's code that gets it done:

Code: Select all

$selection = TextSelection.active
$range = $selection.range
If 0 == $range.length
	Exit "Please select some text."
End

$text = $selection.text
$firstAttributes = $text.displayAttributesAtIndex($range.location)
$lastAttributes = $text.displayAttributesAtIndex($range.lastLocation)

If $firstAttributes.textHighlightColor && $lastAttributes.textHighlightColor
	Remove Highlight Formatting
Else
	$Yellow = Color.newWithRGB255(239, 252, 118)
	Set Highlight Color $Yellow	
End
That macro code only looks at the first and last characters in the selection. The macro ignores uneven highlighting in the intervening middle characters. That's perhaps not a concern for you. Another related but potentially more important concern: multi-part selections. Those are selections that include two or more disjoint regions, e.g. selections created using Find All. The macro doesn't look beyond the first selection.

Writing a macro that's ironclad and looks at all characters in all multi-part selections is possible, but it would be involved. Instead it might be easier to leverage Nisus Writer's existing menu commands, which already calculate and show "mixed" highlighting states when non-uniform highlighting is selected across several multi-part selections. Here's such a macro:

Code: Select all

$highlightMenu = Menu.menuAtPath(':Format:Highlight:Yellow')
If $highlightMenu.state == 1
	Remove Highlight Formatting
Else
	$highlightMenu.activate
End
dgbchr
Posts: 7
Joined: 2022-02-17 08:50:51

Re: Questions re highlighting and keyboard shortcuts

Post by dgbchr »

Thanks again for your help here, Martin! I appreciate the explanations and examples. For now I am using your macro which leverages the existing menu commands. This seems to be doing everything I had hoped for. It's very nice :)
dharmanaut
Posts: 1
Joined: 2022-03-18 15:36:31

Re: Questions re highlighting and keyboard shortcuts

Post by dharmanaut »

All I can say is: consider using Keyboard Maestro. It gives me complete flexibility across my entire Mac, and is largely responsible for keeping me remotely sane. You can create macros operative only in Nisus or across apps. It writes the code for you if you provide the logic.
dgbchr
Posts: 7
Joined: 2022-02-17 08:50:51

Re: Questions re highlighting and keyboard shortcuts

Post by dgbchr »

Thanks @dharmanaut for the suggestion to use Keyboard Maestro! I already do and it is so so central to all my workflows. (The KM about screen tells me my time saved is 23 days — seems like a lot!?)

I had the sense, though, that with Nisus Writer Pro, I could accomplish what I wanted without resorting to KM. And that this might be the better solution, or at least would teach me something useful about NWP. I’m glad I asked for help here in the forums and got the great responses above!
Post Reply