Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility issues with built in Vim #13

Open
CuteWaterBeary opened this issue Nov 29, 2024 · 4 comments
Open

Compatibility issues with built in Vim #13

CuteWaterBeary opened this issue Nov 29, 2024 · 4 comments

Comments

@CuteWaterBeary
Copy link

So I really like this plugin and want to keep using it but when running it alongside the built in VIM keybindings it cause an annoying issue:

If I call vimium: show markers then they show up but whatever I press does not get captured by vimium because the VIM keybindings capture it first and do not allow passthrough. The only way I can get vimium to capture the key strokes is to press a first to get into insert mode and then call vimium: show markers.

Is there any way this extra step can be removed? Its most problematic when I'm in a area where there is no insert mode possibility like a side panel.

Maybe making the vimium event listener higher priority than vim?

@CuteWaterBeary
Copy link
Author

I tried to figure out a way I could use a shortcut key to run a macro that first send a keypress of the letter a and then does the vimium: show markers command but I could not find a way to send that letter a keypress

@CuteWaterBeary
Copy link
Author

A silly method that just crossed my mind would be to prepend A in front of all the generated vimium markers using css

@entropax
Copy link

entropax commented Dec 26, 2024

I tried to figure out a way I could use a shortcut key to run a macro that first send a keypress of the letter a and then does the vimium: show markers command but I could not find a way to send that letter a keypress

Hi there!)
This very annoying bug. But i found temporary solution for that. Maybe this will help you)
Just patch your .obsidian/pluging/viminum/main.js file

function isEditingWithVim(app) {
    const activeLeaf = app.workspace.activeLeaf;
    if (!activeLeaf) return false;

    const view = activeLeaf.view;
    console.log(view)

    // Check source mode
    if (view.getMode() === "source") {
        const editorEl = document.querySelector('.vimrc-support-vim-mode');
        return editorEl?.getAttribute('data-vim-mode') === "insert";
    }
    return false;
}

function simulateKeyPress(targetElement, key, code, keyCode) {
    const eventInit = {
        key: key,
        code: code,
        keyCode: keyCode,
        which: keyCode,
        bubbles: true,
        cancelable: true,
        composed: true
    };

    // keydown event
    const keydownEvent = new KeyboardEvent("keydown", eventInit);
    targetElement.dispatchEvent(keydownEvent);

    // keyup event
    const keyupEvent = new KeyboardEvent("keyup", eventInit);
    targetElement.dispatchEvent(keyupEvent);
}


  createMarkers() {
    // patch for vim visual mode (just enter to editor mode)
    // note - MARKERS SELECTIONS NOT WORK in visual mode
    if (isEditingWithVim(this.app)) {
        console.log("Редактор находится в режиме редактирования и вставки (Vim Insert Mode).");
    } else {
        simulateKeyPress(document.activeElement || document, "i", "KeyI", 73);
        console.log("Редактор либо не в режиме редактирования, либо не в режиме вставки.");
    }
...

@Zevan770
Copy link

Zevan770 commented Jan 7, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants