oni
oni copied to clipboard
[WIP] Handle missing mouse events
Handle the other mouse events:
-<MouseRight>: enters visual mode if not into it and sets the selection from the cursor to the mouse position
-<MouseMiddle>: If OS is linux and running X, paste the selection clipboard.
I ran into this because I was looking for a way to make middle click paste work. At first I looked into using clipboard.readText('selection') but decided to let vim handle it instead, also used the opportunity to let vim handle the right click as well.
I'll remove WIP when I add some tests and receive feedback.
See all possible events we can pass to vim (source):
<LeftMouse> - Left mouse button press
<RightMouse> - Right mouse button press
<MiddleMouse> - Middle mouse button press
<LeftRelease> - Left mouse button release
<RightRelease> - Right mouse button release
<MiddleRelease> - Middle mouse button release
<LeftDrag> - Mouse drag while Left mouse button is pressed
<RightDrag> - Mouse drag while Right mouse button is pressed
<MiddleDrag> - Mouse drag while Middle mouse button is pressed
<2-LeftMouse> - Left mouse button double-click
<2-RightMouse> - Right mouse button double-click
<3-LeftMouse> - Left mouse button triple-click
<3-RightMouse> - Right mouse button triple-click
<4-LeftMouse> - Left mouse button quadruple-click
<4-RightMouse> - Right mouse button quadruple-click
<X1Mouse> - X1 button press
<X2Mouse> - X2 button press
<X1Release> - X1 button release
<X2Release> - X2 button release
<X1Drag> - Mouse drag while X1 button is pressed
<X2Drag> - Mouse drag while X2 button is pressed
Fix #1068
Codecov Report
Merging #2513 into master will decrease coverage by
0.03%. The diff coverage is0%.
@@ Coverage Diff @@
## master #2513 +/- ##
==========================================
- Coverage 44.26% 44.23% -0.04%
==========================================
Files 345 345
Lines 13933 13945 +12
Branches 1829 1831 +2
==========================================
Hits 6168 6168
- Misses 7525 7537 +12
Partials 240 240
| Impacted Files | Coverage Δ | |
|---|---|---|
| browser/src/Input/Mouse.ts | 5.26% <0%> (-1.41%) |
:arrow_down: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update 910559c...20a2bc4. Read the comment docs.
@CrossR @Akin909 Any feedback on this?
I'd like to know if you think this is a good direction, keeping in mind we can also map a lot of other mouse events that we aren't currently.
It is improbable that a user has a particular mouse mapping, but it's good to cover this. Also we may in the future map mouse events directly from Oni, before passing to vim.
Hi, At the moment, I can't copy/paste with middle clic in Oni. Is it related to this issue ?
@badosu looks good to me, I actually work almost exclusively off a laptop with a monitor so can't actually test it out properly
@daxid If on Linux and X11, yes
Testing this has been a challenge, I exposed the raw sendInputEvents function and the clipboard from electron and it still does not work, see:
export const test = async (oni: Oni.Plugin.Api) => { if (!isLinux()) { return }
await oni.automation.waitForEditors() await createNewFile("js", oni) oni.automation.sendKeys("i") await oni.automation.waitFor(() => oni.editors.activeEditor.mode === "insert") const expectedResult = [ "const test = {", " window.setTimeout(() => {", ' let testString = "Oni"', " })", "}", ] oni.automation.writeToClipboard(expectedResult.join(os.EOL), 'selection') const mouseDown:any = {type: 'mouseDown', x: 10, y: 10, button: 'middle'} oni.automation.sendInputEvent(mouseDown) const mouseUp:any = {type: 'mouseUp', x: 10, y: 10, button: 'middle'} oni.automation.sendInputEvent(mouseUp) oni.automation.sendKeys("<esc>") // Because the input is asynchronous, we need to use `waitFor` to wait // for them to complete. await oni.automation.waitFor(() => oni.editors.activeEditor.mode === "normal") const lines: string[] = await oni.editors.activeEditor.activeBuffer.getLines(0, 5) assert.deepEqual(lines, expectedResult, "Verify lines are as expected")}
Any help is welcome
@bryphe @Akin909 Any insights on how to test? It's the only thing missing to merge this.
@badosu Tell me how I can test it and I will try to help. I am currently running ONI on Ubuntu bionic and this feature is really essential for me.
I think the issue is our Automation API doesn't have a sendInputEvent method: https://github.com/onivim/oni/blob/74a4dc7f2240a1f5f7a799b2f3f9d01d69b01bac/browser/src/Services/Automation.ts
A couple of ways you can exercise this locally:
- In developer tools, you can use the automation API right from the console - ie
Oni.automation.sendKeys(":new test.txt")
The WebContents object in Electron does expose this event: https://electronjs.org/docs/api/web-contents#contentssendinputeventevent - we could either get a reference to the webcontents from the test (using require("electron").remote.getCurrentWebContents), or add a method to the Automation API to proxy it.