rhysd / vim.wasm

Vim editor ported to WebAssembly
http://rhysd.github.io/vim.wasm
5.5k stars 144 forks source link

Access to vim api and context from a containing app #52

Open pieper opened 6 months ago

pieper commented 6 months ago

What is an issue which you want to solve with your feature request?

We have a Qt-based desktop application for medical image processing and we use python code as a kind of macro language to extend and automate the program.

We'd like to be able to use a full featured editor integrated within the application to work with our python code.

Because our app uses Qt, we have the QWebEngine available and can embed a full featured web browser in our app, and we can call browser's javascript environment from python (e.g. like in this test code). Note that it's all asynchronous on both the javascript and python sides.

Recently the question came up about using a full editor to edit the python code in our app, and I found that I can run you vim.wasm code in our embedded browser:

https://discourse.slicer.org/t/directly-interacting-with-python-console/34455/7

But I don't see any easy way to get/set the contents of the editor window or be notified in javascript of vim events.

Describe the solution you'd like

I'd like to be able to start the vim.wasm context in the browser and then call a javascript function to populate the current text buffer for editing. Then I'd like to be able to use vim keystrokes to trigger javascript code in the browser that would make calls back to the python code, for example to send selection buffers to python for execution.

Additional context (if any)

I tried using the ?debug argument to set the vim object as window.vim and while I could access vim in the debug console I didn't see any way to set or get the values of the current vim buffers. It would be great if window.vim were available to interact with the browser's javascript enviornment.

Thanks in advance - I'm a long-time vi/vim user and having this available would make me very happy : )

pieper commented 6 months ago

Update: I was able to host your simple example page and run if from our app. From there I was able to access the vim object from the debug console by setting window.vim = vim in index.js.

But I'm still not seeing any way to get/set the contents of the vim buffer from javascript. Would this require changes to the vim c / wasm code?

Or maybe I can do it by sending synthetic keystrokes?