I’d like to mimic iTerm’s “copy on select” functionality, that is, when I’m finished selecting something, I’d like it to be automatically copied to the clipboard. I thought of the on_selection_modified event and issuing view.run_command(‘copy’), but that is not going to work. It acts more like a mouse event than a selection event. It fires once on mouse_down and again on mouse_up, even if nothing is selected. I did a simple:
import sublime, sublime_plugin
class CopyOnSelectCommand(sublime_plugin.EventListener):
def on_selection_modified(self, view):
print view.sel()
and selecting the first line from beginning to end prints
(0, 0)]
(0, 1)]
(0, 1)]
(0, 4)]
(0, 4)]
(0, 5)]
(0, 6)]
(0, 6)]
(0, 6)]
(0, 7)]
(0, 8)]
(0, 8)]
(0, 9)]
(0, 10)]
(0, 10)]
(0, 11)]
(0, 12)]
(0, 13)]
(0, 13)]
(0, 13)]
(0, 15)]
(0, 15)]
(0, 15)]
(0, 16)]
(0, 17)]
(0, 17)]
(0, 18)]
(0, 19)]
(0, 19)]
(0, 20)]
(0, 21)]
(0, 21)]
(0, 22)]
(0, 23)]
(0, 23)]
(0, 23)]
(0, 23)]
(0, 24)]
(0, 24)]
(0, 24)]
(0, 24)]
(0, 25)]
(0, 25)]
(0, 26)]
(0, 27)]
(0, 28)]
(0, 28)]
(0, 28)]
(0, 28)]
(0, 29)]
(0, 29)]
(0, 29)]
(0, 29)]
(0, 30)]
(0, 30)]
(0, 30)]
Looking through the API documentation, I don’t see anything that I could use to make this idea work, but I wanted to ask here in case I’m missing anything.
Ideally, I’d like to have an on_selection_complete event that fires when the entire selection event is completed. Then I could just check the view to see if anything is selected and run_command(‘copy’) when necessary. Better than that, though, would be for ST2 to have a copy_on_select option (default to false, of course) that would let ST2 handle this internally. But I’m not sure if enough people would use it to warrant it being part of the core.