Questions re highlighting and keyboard shortcuts

Everything related to our flagship word processor.
dgbchr
Posts: 7
Joined: 2022-02-17 08:50:51

Questions re highlighting and keyboard shortcuts

Post by dgbchr »

Hello. I'm new here!

Two questions regarding highlighting and keyboard shortcuts:

1) Can I toggle highlighting via keyboard shortcut?

> I know I can assign one keyboard shortcut to a highlight color, and assign another keyboard shortcut to "Remove Highlight Formatting". But what I want is to do is turn on and off highlighting using the same keyboard shortcut (much as one would toggle bold or italic formatting with CMD B or I). Basically I would like my keyboard shortcut to function identically to clicking on the "highlight" toolbar icon: when I do this, Nisus highlights text that is not highlighted, and it removes highlighting from text that is already highlighted. ... Have I described this clearly enough? And is it possible to do this?

2) Can I "Select Next in Highlight" via keyboard shortcut?

> If my cursor is sitting in the midst of highlighted text, then a little box of matching color appears in the status bar. When I click on it, I see the option to "Select Next in Highlight." But can I select this option via keyboard shortcut instead? Better yet, can I select it without first putting my cursor into highlighted text? And what about "Select Previous in Highlight" -- is there any such command?

I'm coming to Nisus Writer Pro from Mellel, in which all of the above is possible via the "Markers" feature, which I am starting to miss. I hope to find some ways to fill this gap in NWP and would appreciate any help!

Thanks :)
johseb
Posts: 47
Joined: 2016-02-13 10:01:29

Re: Questions re highlighting and keyboard shortcuts

Post by johseb »

1) How about defining a character style (based on Normal style + highlighting) and add a keyboard shortcut to it?

Screen Shot 2022-02-18 at 21.01.53.png
Screen Shot 2022-02-18 at 21.01.53.png (10.27 KiB) Viewed 5290 times

The shortcut acts as a toggle: you can use it to both add and remove the character style.
One caveat only when removing the style: you have to select exactly the highlighted text.
Notice that I set a multi-key shortcut. That's a nice NWP feature worth exploring.

2) NWP is outstanding whet it comes to keyboard customization so yes, you can easily assign a shorcut to the command "Select next in style" (character style in your case).
As for a "Select previous in style" I'm afraid it will be no so easy. AFAIK there's no such command but it could be possible to create a macro that perform the selection and assign a shortcut to it.
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 »

Using character styles could be a good solution, depending on dgbchr's needs– thanks johseb!

Another idea: bookmarks. Those won't interfere with text formatting and you can jump between them using Next/Prev menus, the Bookmarks palette, or the Navigator pane set to bookmarks mode. You can control the color of on-screen bookmark highlighting in your Nisus Writer appearance preferences. As for a single keyboard shortcut to add or remove a bookmark depending on the selection, here's a macro:

Code: Select all

$bookmark = Bookmark.selectedBookmark(@true)
If $bookmark
	Remove Bookmark $bookmark.name
Else
	Add Bookmark
End
Þorvarður
Posts: 410
Joined: 2012-12-19 05:02:52

Re: Questions re highlighting and keyboard shortcuts

Post by Þorvarður »

Hello. I'm new here!
Hello and welcome to the Nisus forum!
Can I "Select Next in Highlight" via keyboard shortcut? […] can I select it without first putting my cursor into highlighted text? And what about "Select Previous in Highlight"
Yes, you can. You can even use the same default keyboard shortcuts as in Mellel to do this!

In addition to working with styles, another easy way to achieve this is to use a macroized PowerFind search for all 6 Highlighters.
1.png
1.png (54.61 KiB) Viewed 5271 times
When this has been macroized, it looks like this:
2.png
2.png (20.29 KiB) Viewed 5271 times
3.png
3.png (31.15 KiB) Viewed 5271 times

1. Now execute the command "Show Macros Folder in Finder" from the Macro menu
2. Create a new folder and name it "Markers"
3. Drag the two uploaded macros into the folder
4. Close the Macros folder
5. Open "Menu Keys" in Nisus Preferences
6. Select Macros > Markers > "Find next marker" and assign the default shortcut from Mellel (Cmd + Ctrl + ])



[…to be continued…]
Last edited by Þorvarður on 2022-02-22 20:28:34, edited 5 times in total.
Þorvarður
Posts: 410
Joined: 2012-12-19 05:02:52

Re: Questions re highlighting and keyboard shortcuts

Post by Þorvarður »

… Continuation

4.png
4.png (71.03 KiB) Viewed 5271 times
6. Repeat with "Find previous marker" and assign the default shortcut from Mellel (Cmd + Ctrl + [)

You are now ready to go. You won't feel any difference to Mellel. :–)
Attachments
Markers.zip
(4.77 KiB) Downloaded 268 times
Last edited by Þorvarður on 2022-02-22 20:29:15, edited 1 time in total.
Þorvarður
Posts: 410
Joined: 2012-12-19 05:02:52

Re: Questions re highlighting and keyboard shortcuts

Post by Þorvarður »

In addition to "Select next in style", as johseb pointed out, you can also use "Go to Text in Style…" (from the Character Style menu.) That will give you interesting options not found in Mellel.
This command will show you a list of all text in this style. You can also filter the list to find just the text you want,

1.png
1.png (161.43 KiB) Viewed 5266 times

or you can click on the icon with the red circle on the screenshot to see hot links to all text with this style.

2.png
2.png (182.26 KiB) Viewed 5266 times
Þorvarður
Posts: 410
Joined: 2012-12-19 05:02:52

Re: Questions re highlighting and keyboard shortcuts

Post by Þorvarður »

Can I toggle highlighting via keyboard shortcut?
I think it's possible to write a macro that does what you want. In pseudo-macro language:

Is the text highlighted?
If not then
highlight the text
# To highlight text one could use for the color yellow
#$Yellow = Color.newWithRGB255(239, 252, 118)
#Set Highlight Color $Yellow
else
remove the highlight formatting from the text

To find out whether the text is highlighted or not, one would probably use
.textHighlightColor
This command returns the Color object used to highlight the text. It can be @undefined if no highlighting is drawn.

Unfortunately, I don't know what must precede the dot in .textHighlightColor.
The Macro Language Reference gives no examples how to use this command.

Can someone help…?
Vanceone
Posts: 211
Joined: 2013-05-03 07:06:31

Re: Questions re highlighting and keyboard shortcuts

Post by Vanceone »

According to the macro guide, .texthighlightcolor is attached to the attributes object of a piece of text. So the flow would be to get a piece of text, ask for its attribute object, then ask that attribute object for it's .texthighlightcolor, and if undefined it is not highlighted. The Attribute object will return the first attribute object of the selected text or text object, so perhaps you'd need to cycle through all the attribute objects.

My guess is that the attributes object is a thin wrapper around an NSAttributedString object which is applied to the text, and it's the specific attributes attached to that NSAttributedString.
dgbchr
Posts: 7
Joined: 2022-02-17 08:50:51

Re: Questions re highlighting and keyboard shortcuts

Post by dgbchr »

Wow, thank you everyone for the replies and the awesome set of ideas!! I am going to try everything you've suggested.

BTW, sorry to be slow to reply -- I had turned on email notifications for subscribed topics, but then forgot to subscribe to my own topic! (Guess I incorrectly assumed I'd be automatically subscribed to any topic I created myself...)

@johseb --
How about defining a character style (based on Normal style + highlighting) and add a keyboard shortcut to it?
Indeed, this lets me toggle highlighting on/off with a keyboard shortcut. But the problem (as noted elsewhere in these forums) is that toggling highlighting via character styles is destructive of other styles (eg, emphasis) -- there is, I imagine, no way to avoid this? On the other hand, toggling highlighting via the toolbar retains any previously applied styles (which is the behavior I want).
so yes, you can easily assign a shortcut to the command "Select next in style" (character style in your case)
I see how to assign a shortcut for the "Select Next in Style" command, but if (for the reason given above) I want to highlight without using a character style, then 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. Is there indeed a way to assign a shortcut to this command? Or would it have to earn a place in the menu bar for this to be possible?

@martin --
Another idea: bookmarks
This is fantastic! I did not know that bookmarks could be colored. And the fact that this color can be different in light vs dark mode gives this option an advantage over using highlighting. I also like the ability to use the navigator pane, and that that there is a "Select Previous Bookmark" command. (It seems strange to me that there is no "Select Previous" option for styles or highlighting ... is something you might add at some point?)

@Þorvarður -- I will take a look at your suggestions next! Lots for me to learn there!
dgbchr
Posts: 7
Joined: 2022-02-17 08:50:51

Re: Questions re highlighting and keyboard shortcuts

Post by dgbchr »

@Þorvarður --

Thanks for all the ideas you shared! The "Go to Text in Style…" command is lovely and I look forward to using it all the time. Your "Markers" macros work perfectly, and are a nice introduction to what can be done with macros. For my learning, I attempted to recreate these macros by "macroizing" the same "PowerFind" search, but ran into an issue ...

@developers --

... in which the metacharacters are situated too high, no matter how I resize or scroll the Find & Replace window. If I type normal text into these fields, the metacharacters come down out of their heights. Compare the "Find what" and "Replace with" fields in the screenshot below. Is this a bug? Or am I doing something wrong? I'm using NWP 3.2.2 on macOS 12.2.1.

Image

As for the "Is the text highlighted?" macro question ... seems like a good challenge; I may try to figure it out sometime soon. Thanks for your input regarding .texthighlightcolor, @Vanceone!
Þorvarður
Posts: 410
Joined: 2012-12-19 05:02:52

Re: Questions re highlighting and keyboard shortcuts

Post by Þorvarður »

dgbchr wrote: 2022-02-21 16:12:06 I ran into an issue ...in which the metacharacters are situated too high, no matter how I resize or scroll the Find & Replace window.

I think you need to adjust the zoom level in the View menu. I use 250%.
Place the insertion point first into the "Find what" field and then select your preferred zoom level.

1.png
1.png (137.63 KiB) Viewed 5129 times
Þorvarður
Posts: 410
Joined: 2012-12-19 05:02:52

Re: Questions re highlighting and keyboard shortcuts

Post by Þorvarður »

Another idea: bookmarks
This is fantastic! I did not know that bookmarks could be colored.

Notice that regarding the use of colors there is a fundamental difference between highlighting and bookmarks. Although you can choose between two commands for bookmarks ("Add Bookmark" and "Add Bookmark As…") both can only have *one* color at a time. The default color for "Add Bookmark" is pink. You can change that color, but the new color will then apply to ALL bookmarks in your document. The old bookmarks in pink will adopt the new color.
A colored bookmark will just draw your attention to the fact that there is a bookmark there, whereas highlighted text usually conveys a specific meaning which the user has individually settled on for himself or herself. Example:

Yellow = an important argument
Pink = central theme or argument
Blue = needs to be rewritten
Cyan = needs to be verified
etc.

So, whether you choose to use bookmarks or highlight text, depends entirely on the reason why you want to use colors in the first place.
Þorvarður
Posts: 410
Joined: 2012-12-19 05:02:52

Re: Questions re highlighting and keyboard shortcuts

Post by Þorvarður »

Vanceone wrote: 2022-02-21 14:26:16 My guess is that the attributes object is a thin wrapper around an NSAttributedString object which is applied to the text, and it's the specific attributes attached to that NSAttributedString.
Thank you, Vanceone, for chiming in. Unfortunately, right now, this all sounds like a gobbledygook to me. Mea culpa.
Vanceone
Posts: 211
Joined: 2013-05-03 07:06:31

Re: Questions re highlighting and keyboard shortcuts

Post by Vanceone »

Þorvarður wrote: 2022-02-21 20:00:23
Vanceone wrote: 2022-02-21 14:26:16 My guess is that the attributes object is a thin wrapper around an NSAttributedString object which is applied to the text, and it's the specific attributes attached to that NSAttributedString.
Thank you, Vanceone, for chiming in. Unfortunately, right now, this all sounds like a gobbledygook to me. Mea culpa.
Well, you don't need to know about NSAttributedString to use the Macro language!

The basic concept though is fairly simple. There is a piece of text or string. It has the actual text, and then all the formatting applied to that text: font size, what the font actually is, bold, italic, all the kerning, etc. These formats are the "attributes" of the string.

So for a given piece of text, or for a given string, there are two things (at least) that you need to know to display it: the contents of the text, and what attributes are applied to that string of text.

The macro language works similarly, it appears. You can select some text, ask for its contents and you'll get the text. But in order to get whether it it italicized, you have to ask the text string for its attributes object. Once you have that, you can get and set attributes on that piece of text: it's bold, italics, font, font size, and whether it is highlighted.

Every time an attribute changes, a new attributes object is created with the attributes.
Thus, for a given string, you may have multiple attributes objects as text is highlighted, bolded, unbolded, underlined, etc as you go along. Each attribute object will have a range, or a beginning and ending which will tell you exactly what characters from the text object it is affecting. It's like a train: each character in the text has (I believe) exactly one attribute object, which likely is the same as its neighbor.

Therefore, you would have to get a piece of text: say, the selectedText. Then, you loop through each attribute Object associated with that piece of selected text, because you may have formatting changes. For each attribute object, check to see if the .textHighlightColor is defined: if so, that text has a highlight color attached to it. If it's not defined then there is no highlight.

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.

I'm sure someone can show a practical example rather than this theory craft; I would do it myself but I don't really know the Macro language yet. One of my goals.
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 »

Þorvarður wrote: 2022-02-18 17:39:38 To find out whether the text is highlighted or not, one would probably use
.textHighlightColor
This command returns the Color object used to highlight the text. It can be @undefined if no highlighting is drawn.

Unfortunately, I don't know what must precede the dot in .textHighlightColor.
The core answer is that you need an Attributes object to precede the .textHighlightColor property. There are a variety of ways to get an Attributes object, but if you just want to check the current text selection this is the most straightforward:

Code: Select all

$selection = TextSelection.active
$attributes = $selection.firstAttributes
If $attributes.textHighlightColor
	Prompt "The selection's highlight color is:", $attributes.textHighlightColor
End
Post Reply