setSelectParentIfSelected is bugged?


Something I noticed when setSelectParentIfSelected is set to false. Step to reproduce:

  1. setSelectParentIfSelected to false on the selection manager
  2. In the viewer click on a child node
  3. Click on the child node again and it selects the parent node
  4. Click on on child node again and it selects just the child

See selectionArray returning the parent node.

This keeps cycling between the parent and child nodes.

Node 66 is parent of node 68.

But when I keep clicking the node, it selects the parent, then the child again, then the parent again.

Here’s a video showing what I mean.
parent bug (1.0 MB)

Is this intended?

Thank you!


so for better or for worse, this does seem to be the intended behavior, basically the selection toggles between the selected element and its parent. What setSelectParentIfSelected(false) prevents is having the selected object go to to the parent of the parent, etc.

You can actually look at the logic itself, it is all driven by the SelectionOperator class. You can find its implementation in the HC package (webviewer/typescript/operators/selectionOperator.ts). The relevant code is around line 156. You could use a modified version of this operator if you want to alter this behavior directly (removing the first else case of the if statement should do the trick).

This behavior does seem a bit confusing, so I’m happy to create a ticket for you in our support portal. Just let me know.

Ha, that’s awesome! I actually ended up doing something similar (although kinda hacky). However, I am not sure what would be the best way to “replace” / “intercept” the SelectionOperator or how to provide our own but only change what we need. Is there an example I can look at?

A support ticket would be great :slight_smile:

Thank you for your quick help!!

The docs go into some detail with regard to TS (link) but apparently it is not possible to convert the source code for the operators to usable JS automatically, so I ended up using chatGPT for that, which got me about 70% of the way there (had to deal with some namespace issues manually).

The code below should fix that selection issue. To use it (or replace any other operators), just do this:
let operatorid = hwv.operatorManager.registerCustomOperator(new MySelectionOperator(hwv, new Communicator.Markup.Note.NoteTextManager(hwv)))
hwv.operatorManager.replaceOperator(Communicator.OperatorId.Select,operatorid )

I hope this helps

mySelectionOperator.js (4.4 KB)

Wonderful! Thank you so much Guido! I got the behavior that I wanted :+1:

1 Like