nmrium icon indicating copy to clipboard operation
nmrium copied to clipboard

OCL editor does not catch key events

Open lpatiny opened this issue 7 months ago • 7 comments

When pressing 'c' in the prediction tool the atom is converted to 'C' but the event bubbles and the spectrum is centered as well

Image

@targos Not sure where it should be fixed.

lpatiny avatar Jun 04 '25 15:06 lpatiny

We could add a "stopPropagation" to the OCL editor but it's not even sure we listen to the same events. Normally it's up to the event listener to only handle the event it cares about. I'd say NMRium should filter the events that are not on expected targets (this is a general issue that can happen with any component used inside NMRium).

targos avatar Jun 05 '25 06:06 targos

So the one letter shortcuts + the numbers to store the view state should only be active if the mouse if over the spectrum of left toolbar

Image

Do we agree on this ? @hamed-musallam ?

lpatiny avatar Jun 05 '25 10:06 lpatiny

It should not be based on where the mouse is located, but on the value of event.target

targos avatar Jun 05 '25 10:06 targos

For KeyListener, we used a global listener. I remember we did it that way, in case we had multiple viewers.

hamed-musallam avatar Jun 05 '25 10:06 hamed-musallam

@hamed-musallam Could you add a condition in the global listener to ignore the event if the event if over the ocl-editor ? Something like:

  const specificDiv = document.getElementById('your-div-id');
  
  if (specificDiv && specificDiv.contains(event.target)) {
    event.stopPropagation();
  }

lpatiny avatar Jul 14 '25 13:07 lpatiny

In fact because ocl-editor is in a shadow dom the event target will always be the element on which the shadow dom element is attached. Michael will add an identifier on the element.

lpatiny avatar Jul 14 '25 13:07 lpatiny

[email protected] sets a custom attribute on the root editor element: https://github.com/cheminfo/openchemlib-js/pull/305

targos avatar Jul 14 '25 13:07 targos