Skip to content

Instantly share code, notes, and snippets.

@TheClams
Created May 22, 2020 20:31
Show Gist options
  • Save TheClams/8222664e8bbe7cf4ebf260161258c05a to your computer and use it in GitHub Desktop.
Save TheClams/8222664e8bbe7cf4ebf260161258c05a to your computer and use it in GitHub Desktop.
Click anywhere for sublime Text (virtual space)
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)
[
{"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