-
-
Save God-damnit-all/113a41f4ec5d96c56a09eefd97607ba5 to your computer and use it in GitHub Desktop.
Click anywhere for sublime Text (virtual space)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sublime, sublime_plugin | |
class ClickAnywhereCommand(sublime_plugin.TextCommand): | |
def run_(self,edit, args): | |
if args and 'event' in args: | |
self.mouse_coord = (args['event']['x'],args['event']['y']) | |
else : | |
self.mouse_coord = None | |
super().run_(edit,args) | |
def run(self, edit,mode='insert',max_space=200): | |
if self.mouse_coord: | |
point = self.view.window_to_text(self.mouse_coord) | |
row,col = self.view.rowcol(point) | |
r_line = self.view.line(self.view.text_point(row,0)) | |
line = self.view.substr(r_line) | |
# print('Click at {} : line {} has {} characters : click found at col {}'.format(point,row,len(line),col)) | |
if col>=len(line): | |
self.view.replace(edit, sublime.Region(point,point), ' '*max_space) | |
new_point = self.view.window_to_text(self.mouse_coord) | |
_,new_col = self.view.rowcol(new_point) | |
# print(' After line expansion : {} -> {},{}'.format(new_point,row,new_col)) | |
self.view.replace(edit, sublime.Region(point,point+max_space), ' '*(new_col-col)) | |
fs = sublime.Region(new_point,new_point) | |
else : | |
fs = sublime.Region(point,point) | |
self.view.sel().clear() | |
self.view.sel().add(fs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
[ | |
{"button": "button2", "modifiers": ["alt"],"press_command": "click_anywhere"} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment