Select between selected nodes

I had the functionality of being able to select everything between two selected nodes by pressing Command+Option+Shift+; This function didn’t survive my migration to a new mac, and I want it back but I can’t for the life of me remember which Plugin it was. I’m pretty sure it was an additional or minor feature of a plugin, and that it possibly wasn’t installed using the plugin manager.

Does it ring a bell?

Could yo describe in more detail how this selection was performed? Needed there something else to be selected first, or did it use the mouse pointer?

Just with the mouse pointer, then the shortcut would select everything between then two initially selected nodes. Sometimes it would take the wrong way around, but they you just invert it.

This should do the trick:

def select_all_nodes_between_selected_nodes():
	selected_nodes = [selection for selection in Layer.selection if type(selection) == GSNode]  # get all the selected nodes
	
	if len(selected_nodes) >= 2:  # if at least two nodes are selected
		parent_path = selected_nodes[0].parent
		for selected_node in selected_nodes:  # check whether all nodes belong to the same path
			if selected_node.parent != parent_path:
				return  # if not, cancel
		node_indices = [parent_path.nodes.index(selected_node) for selected_node in selected_nodes]  # collect the indices of all selected nodes
		nodes_in_between = [node for node in parent_path.nodes[min(node_indices):max(node_indices) + 1]]  # get the nodes for all indices between the smallest and biggest selected node index
		for node in nodes_in_between:
			node.selected = True  # select all nodes in between
			
select_all_nodes_between_selected_nodes()

Edit: You can now find it in my scripts, also available in the plugin manager.

I’ll try it tomorrow thanks! I am still curious what the original plugin was. Perhaps it will come to me.

Got it working, and the script works. Unfortunately the keyboard shortcuts in Glyph are still broken, so I couldn’t get Glyphs to accept my usual Cmd+Opt+: combo.

@SCarewe If you want to make the script even better, then tag on a functionality that inverts the selection – but only of the outline that is currently selected – when the script is run again after the first run. Meaning, the inverse selection is not of everything else in the glyph, but only the inverse of whatever outline was selected.

That will be difficult/not possible to implement, as the script cannot know whether you selected the nodes or the nodes were selected by the script. I would like to avoid writing a userData entry for each node saving this.

But I do of course see the merit of this functionality. Would a modifier key work? As in, holding down Option while running the script selects the inverse?

This is true, and very annoying. For the time being, at least what works for me is going into the Mac system settings and adding a keyboard shortcut in Keyboard > Keyboard Shortcuts > App Shortcuts. Add Glyphs 3 as an app in the list, then write the exact menu title of the script as it appears in Glyphs.

1 Like

I see. In that case you could add a modifier key to ‘go the other way around’.

What modifier key would make sense to you? I would use Option, but I see you are already using Option in your preferred keyboard shortcut, as well as Shift in order to type :. I don’t think Control makes sense here, would you be ok with adapting your preferred keyboard shortcut?

I suppose Cmd+Opt+; could be the one way, and Cmd+Opt+: the other. That would work fine. I’m not married to the shortcuts, they were just the ones that happened to be hardcoded in the unknown original plugin.

That wouldn’t be a modifier key, but two separate keyboard shortcuts, essentially for two different scripts.

There needs to be a way of running the script from the menu by clicking it and holding down a modifier key, which is also compatible with a keyboard shortcut.

As an alternative, you might want a script that inverts the selection for all selected paths. That way, you run the select-in-between-script first, and if you wanted the inverse selection, run this script afterwards:

selected_paths = set([x.parent for x in Layer.selection if type(x) == GSNode])
for path in selected_paths:
	for node in path.nodes:
		node.selected = not node.selected

This script might also proof useful in other contexts.

2 Likes

On my keyboard the : is the Shift + ;

Probably the better solution, thanks Florian.

Interesting. Off-topic, sorry, but what keyboard layout is this?

That would be the Dutch Apple Extended (which is essentially the same layout as the en-US and en-GB layouts).

You can compare them here https://www.apple.com/nl/shop/product/MMMR3N/A/magic-keyboard-met-touch-id-en-numeriek-toetsenblok-voor-mac-modellen-met-apple-silicon-nederlands-zwarte-toetsen?fnode=dafd6dd3b57467742dd9516a33eea9f7cce43b082ae736d88ac8fb72a653d830cc5908f78134f37b8488a4daaed695154c6a3055289049c9ca4165a692ad1949372df697c5dd4da627b5bc6521013547ca416c41164208a576630cf4bdc984f6

Urg. I seem to have overlooked that the two originally selected nodes should remain selected when the selection is inverted.

Example: I select two nodes and run ‘select between’

but I want the other half, so I run your ‘invert’ script.


but now the two original nodes also have their select state inverted.

What I wanted was to have them included in the selection regardless of the selection ran on one half or the other, like so:

Was it the Selection Palette?

The plug-in needs an update for Glyphs 3.

You know what, that was probably it! I left a bark in the issues tracker.