MouseDragged to move vs to select

Hi! In a Select Tool plugin, I’m running stuff on mouseDragged but it also runs when you drag the mouse to select more nodes. Is there a direct way to differentiate between dragging to select and dragging to move?

What exactly are you trying to do?

mouseDragged changes the position of the selected nodes depending on how you drag the cursor. But when you hold shift it runs as well no matter what, because nodes are selected and mouse is dragged. Moreover, it applies every frame, so the Undo quickly fills up.

Here’s a little screen grab (1. expected behavior, 2. trying to select the other node with shift on, and 3. trying to undo):

ezgif-1-f2ff09e03d

I suppose Glyphs knows when you drag mouse to move nodes vs to select, doesn’t it? What does trigger the marquee rectangle to appear?

I think you might need to re-post that link :wink:

1 Like

Ouch, that expired quickly. Reuploaded!

What function do you use?

You might like to overwrite - (void)moveSelectionWithPoint:(NSPoint)offset withModifier:(NSEventModifierFlags)modifierFlag (or def moveSelectionWithPoint_withModifier_(offset, modifierFlag): in python).

Do you mean to turn off moving it with Shift key on? I would want to keep that because it’s a different ‘mode’ in the tool. I guess I’ll have to look into distance to cursor or lastChange

Again: What method do you use to run your code?

mouseDragged_, I think it was the one from templates.
Also considering keyDown_ for moving with arrow keys.

Don’t do that. Implement the method I mentioned above. MouseDragged is very low level and you need to do a lot yourself. Use what is already there.

1 Like