mathlive icon indicating copy to clipboard operation
mathlive copied to clipboard

Contextmenu via right-click is executing commands twice

Open benjaminwols opened this issue 3 years ago • 6 comments

Description

When using the context menu to insert rows or columns the command is executed twice.

https://github.com/arnog/mathlive/assets/12526288/9501ad1e-29d6-469a-af50-9be38837eb45

Steps to Reproduce

  1. Go to https://cortexjs.io/mathlive/demo/ or use the local development environment
  2. Insert a new matrix (size doesn't matter)
  3. Right click the matrix and click on "Add column after"

Actual Behavior

Instead of 1 column, 2 columns are inserted.

Expected Behavior

Only 1 column should be inserted.

Environment

The issue seems to be introduced in 0.97.4 with the refactoring of handleEvent in menu-items.ts. I did some investigation and found that this.select() is called twice, from the click and the pointerup event. There seems to be some code to take this into account (https://github.com/arnog/mathlive/blob/f1963af2ad6c81ae8ac2250babf340f17efd025a/src/ui/menu/menu-item.ts#L363), but the rootMenu.state is equal to open instead of modal.

Operating System macOS 14.1.1

Browser Chrome 119.0.6045.199

benjaminwols avatar Dec 03 '23 11:12 benjaminwols

I'm sorry, I tried to reproduce this but I have not been able to.

Could you describe in more details how you're using the menu, that is when are you pressing the mouse button and when are you releasing it. Or are you using a trackpad? And how are you invoking the context menu? Right-button on a mouse, gesture on a trackpad, other?

arnog avatar Dec 03 '23 19:12 arnog

I'm using the trackpad of a Macbook Pro 13-inch, M1, 2020. I use the secondary click (tap with two fingers) to open the context menu and than use the trackpad to click on "Add column after". I hope this helps to reproduce the issue.

benjaminwols avatar Dec 04 '23 20:12 benjaminwols

Still not luck. I tried reproducing this with a Macbook Pro, using the trackpad. And you are seeing that with the demo page https://cortexjs.io/mathlive/demo/ ?

Does this only affect the matrix commands or do you see that as well for example if you select Paste?

arnog avatar Dec 05 '23 20:12 arnog

Yes, it also happens on the demo page. Here is screen recording on the demo page in Chrome:

https://github.com/arnog/mathlive/assets/12526288/977114b6-aef8-434f-807b-6c6adcc85ec9

I've copied the letter "D" to clipboard and when I paste via the contextmenu it is inserted twice, but via the keyboard (cmd+v) it is only inserted once.

I've also checked in Firefox and Safari and the issue also occurs in those browsers. I've also noticed a styling issue in Safari with the context menu inserting a matrix:

https://github.com/arnog/mathlive/assets/12526288/b6caa20a-2e1a-4647-a4ad-342d21b095e3

Please let me know if I can provide more debugging information. I would also be open to jump on a call to look at it together.

benjaminwols avatar Dec 05 '23 21:12 benjaminwols

OK, I've finally been able to reproduce it. The key thing is that the page has to be scrolled, even by one pixel for this to occur. If the page is not scrolled, the command works as expected.

arnog avatar Dec 06 '23 01:12 arnog

Actually, it was even more subtle than this... In some circumstances, the browser may send a contextmenu event before the pointerup event. Anyway, it should be fixed now.

arnog avatar Dec 07 '23 05:12 arnog