Hello. I'm trying to do something fairly straight-forward. If there is nothing selected in the view, I want to insert a couple of words at the cursor position, but then extend the selection to include these new words.
The following code works in a round-about way, by creating a Region of a known size and adding it to sel(). If I don't specify the size (13) then the text is added but not selected .
How can I extend the current cursor/ selection to include my new text (without specifying a length for my region) please? Andy.
[code]def run(self, edit):
sels = self.view.sel() # sels: RegionSet
for a_sel in sels:
# handle multi-select
if len(sels) != 1: # cancel if multi-select
the_region = sels
if the_region.empty(): # that is, begin() == end()
# print 'nothing selected'
my_edit = self.view.begin_edit()
new_region = sublime.Region(the_region.begin(), the_region.end()+13)
self.view.insert(my_edit, new_region.begin(), ' after cursor')
print '#' + self.view.substr(new_region) + '#'