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

Selection is off when using nyaovim-tree-view #76

Open
city41 opened this issue Aug 28, 2016 · 1 comment
Open

Selection is off when using nyaovim-tree-view #76

city41 opened this issue Aug 28, 2016 · 1 comment

Comments

@city41
Copy link

city41 commented Aug 28, 2016

When using nyaovim-tree-view, the mouse selection algorithm of neovim-editor doesn't account for the width of the tree-view, causing the selection to be off.

Expected Behavior

When clicking in the editor, and dragging a selection, the text that was dragged over becomes selected

Actual Behavior

Text to the right of what was dragged over gets selected, how far right is dependent on how wide nyaovim-tree-view is

Steps to Reproduce (including precondition)

  1. install nyaovim-tree-view plugin as its README shows
  2. start nyaovim and edit a file
  3. using the mouse, select a sentence

Screenshot on This Problem (if possible)

screenshot

Notice how the mouse cursor is off to the left compared to the selected text

Your Environment

  • OS: Debian 8.5
  • NyaoVim version:
NyaoVim version 0.0.20
  electron : 1.3.4
  chrome : 52.0.2743.82
  node : 6.3.0
  v8 : 5.2.361.43
  • nvim version: 0.1.5
  • Keyboard layout: US ANSI Qwertry
  • Linux: Window manager: i3

Additional Comments (if any)

I was able to fix this bug by patching ScreenDrag.

I changed this:

    ScreenDrag.prototype.getPos = function (e) {
        return [
            Math.floor(e.clientY / this.store.font_attr.height),
            Math.floor(e.clientX / this.store.font_attr.width),
        ];
    };

To this:

    ScreenDrag.prototype._getRelCoord = function(e, container) {
        var pos = {}, offset = {}, ref;

        ref = container.offsetParent;

        pos.x = e.clientX;
        pos.y = e.clientY;

        offset.left = container.offsetLeft;
        offset.top = container.offsetTop;

        while ( ref ) {

            offset.left += ref.offsetLeft;
            offset.top += ref.offsetTop;

            ref = ref.offsetParent;
        }

        return { 
            x : pos.x - offset.left,
            y : pos.y - offset.top,
        }; 

    };
    ScreenDrag.prototype.getPos = function (e) {
        const target = document.querySelector('.neovim-canvas');
        const relCoords = this._getRelCoord(e, target);
        return [
            Math.floor(relCoords.y / this.store.font_attr.height),
            Math.floor(relCoords.x / this.store.font_attr.width),
        ];
    };
@rhysd
Copy link
Owner

rhysd commented Aug 30, 2016

Thank you for catching this bug. I could confirm 😄

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

No branches or pull requests

2 participants