# Context menu jumps cursor-bug when opening context menu from keyboard

**URL:** https://discuss.codemirror.net/t/context-menu-jumps-cursor-bug-when-opening-context-menu-from-keyboard/7799
**Category:** v5
**Created:** [February 2, 2024, 6:18am UTC](https://discuss.codemirror.net/t/context-menu-jumps-cursor-bug-when-opening-context-menu-from-keyboard/7799 "2024-02-02T06:18:34Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![arun](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/arun/32/4146_2.png) [@arun](https://discuss.codemirror.net/u/arun)
#### Post date: [February 2, 2024, 6:18am UTC](https://discuss.codemirror.net/t/context-menu-jumps-cursor-bug-when-opening-context-menu-from-keyboard/7799/1 "2024-02-02T06:18:34Z")

</div>

Hi,  
When opening context menu from the context menu key in keyboard, if there is no selection, the cursor jumps one line up.  
 ![jumping context menu](https://discuss.codemirror.net/uploads/default/original/2X/1/127356d0ff4b16ccb7c5f10e38a6845744b407c4.gif)

Additional context:

1. Goto [https://phcode.dev/](https://phcode.dev/) , open any text file and click the keyboard right click button to repro the issue.
2. The issue is only present in modern google chrome/edge browser. Its not present in Firefox, Safari, Edge/webkit Web views.

I did a bit of debugging and found the code below:

> var pos = posFromMouse(cm, e), scrollPos = display.scroller.scrollTop;  
> It appears that the code always assumes context menu is opened with mouse. Is this a valid bug or am i doing something/config wrong at my end.

NB: resetSelectionOnContextMenu is set to true as it is expected behaviot

Below is the code fragment extracted from `codemirror.js`

```js
 TextareaInput.prototype.onContextMenu = function (e) {
    var input = this, cm = input.cm, display = cm.display, te = input.textarea;
    if (input.contextMenuPending) { input.contextMenuPending(); }
    var pos = posFromMouse(cm, e), scrollPos = display.scroller.scrollTop;
    if (!pos || presto) { return } // Opera is difficult.

    // Reset the current text selection only if the click is done outside of the selection
    // and 'resetSelectionOnContextMenu' option is true.
    var reset = cm.options.resetSelectionOnContextMenu;
    if (reset && cm.doc.sel.contains(pos) == -1)
      { operation(cm, setSelection)(cm.doc, simpleSelection(pos), sel_dontScroll); }

```

Thanks,  
Arun
