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 by non vim-commands doesn't track correctly #193

Closed
wants to merge 2 commits into from
Closed

Selection by non vim-commands doesn't track correctly #193

wants to merge 2 commits into from

Conversation

ashb
Copy link

@ashb ashb commented Jun 22, 2013

For example if you use shift+v to enter visual line then hit up/down arrow you can expand the selection, but if you select with the mouse then hit up/down it clears the selection and moves the caret instead.

You can also get similar behavior by the Expand selection to Brackets (cmd+shift+m on OSX) command.

@ashb
Copy link
Author

ashb commented May 23, 2013

Got any pointers on what I'd need to look at to fix this? Would like to try a pull request if you can give me some guidance.

@guillermooo
Copy link
Owner

I'm not familiar at all with the mouse api/files. Look for .sublime-mousemap files (I've just made that up!) inside the Default package and see how events are intercepted within Sublime Text. It can't be too hard, but I honestly haven't got the first idea either and little to no interest in this stuff right now...

@ashb
Copy link
Author

ashb commented Jun 22, 2013

Finally got around to looking at this.

So the first thing I tried was looking at the mouse map and a command. So the default mouse map has the "drag_select" command. I got a plugin that proxied to drag select (turns out for this you have to def run_ as run gets called with some args already stripped out) but this just gives us when the mouse is click - we can't yet tell if they are actually dragging.

So instead I went for EventListener with the on_selection_modified event - again this also gives us click events but this is workable:

import sublime
import sublime_plugin

from Vintageous.state import VintageState
from Vintageous.vi.constants import MODE_VISUAL, MODE_VISUAL_LINE

class ViSelectionListener(sublime_plugin.EventListener):
    def on_selection_modified(self, view):
        non_zero_range = next((True for sel in view.sel() if not sel.empty()), False)
        if not non_zero_range:
            return

        vintage_state = VintageState(view)
        # print("Current mode: %r" % vintage_state.mode)
        if vintage_state.mode not in (MODE_VISUAL, MODE_VISUAL_LINE):
            # We've got a non-zero selection and are not currently in visual
            # mode - this was likely the result of drag select or similar.
            vintage_state.enter_visual_mode()

Not too happy with the list comprehension just in general principle but I think its the 'best' solution here.

I'll work on turning this into a pull request now - will probably put this directly in VintageStateTracker class - seems appropriate to me.

@ashb
Copy link
Author

ashb commented Jun 22, 2013

So this does seem to work (had to deal with select mode and clicking off a selection needs to leave visual mode too) but.

Bringing up the normal find panel (cmd+f/ctrl+f) seems to now behave oddly - if you bring it up in normal mode you can't actually type in it - it's like the input in visual mode is still.

It doesn't look like there's any way currently to see if a panel is open from a plugin, nor can you run sublime.query_context or similar (on_query_context always for panel_visible seems to return false)

Back to the drawing board - this approach works for simple case but causes all other things to be really.... fruity.

…command

For instance cmd+d/ctrl+d or drag-selecting with mouse.
@ashb
Copy link
Author

ashb commented Jun 22, 2013

Haha victory!

if view.id() not in (v.id() for v in view.window().views()):
    print("Not a main-window view, returning")
    return

Seems to do the trick.

@guillermooo
Copy link
Owner

I don't like the idea of having stuff in an on_selection_modified event.

I believe it's possible to capture mouse commands, but I don't know how it's done.

@ashb
Copy link
Author

ashb commented Jul 17, 2013

Has this been closed because you don't like the approach or because you have fixed the issue in another way?

@ashb
Copy link
Author

ashb commented Jul 17, 2013

(Just asking since if its not yet done I'll might try taking another crack at getting it working the way you'd like as this is reasonably important to me)

@guillermooo
Copy link
Owner

.on_selection_modified() should be overloaded with care. I think the .mouse-map files is the way to go here. I'll reopen the PR.

@guillermooo guillermooo reopened this Jul 17, 2013
@guillermooo
Copy link
Owner

#329

@guillermooo
Copy link
Owner

Closing this as there are open issues addressing this problem and ST's .mouse-map files can't handle contexts yet.

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

Successfully merging this pull request may close these issues.

2 participants