-
Notifications
You must be signed in to change notification settings - Fork 115
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
Conversation
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. |
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... |
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 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. |
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.
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. |
I don't like the idea of having stuff in an I believe it's possible to capture mouse commands, but I don't know how it's done. |
Has this been closed because you don't like the approach or because you have fixed the issue in another way? |
(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) |
|
Closing this as there are open issues addressing this problem and ST's .mouse-map files can't handle contexts yet. |
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.