Sublime Forum

Insert text at current cursor position

#1

Hi,

I’m sorry to ask what I assume to be such a basic question, but I can’t for the life of me figure our how to insert text at the current cursor position:

I thought I had the following code working for a little while:

edit = self.window.active_view().begin_edit()
self.window.active_view().insert(edit, self.window.active_view().sel()[0].begin(), attribute)
self.window.active_view().end_edit()

Hower, this appears to only work in some cases. What is the proper way of doing this?

Thanks in advance!

1 Like

#2

As well as self.view rather than self.window.active_view()

1 Like

#3

Hi guys,

Passing the edit object to the end_edit() function did the trick - thanks!

BTW, I’m my command is a WindowCommand, so if I’ve understood correctly, I need to both begin the edit and get the active_view(). However, I’m not sure that making my command a WindowCommand is correct - after reading the API documentation I’ve had some problems understanding which command to use when.

1 Like

#4

I think that if your plugin is doing some action on the contents of the current view, then you should use a text command.

1 Like

#5

It’s also making use of the show_quick_panel() function of the window object. Doesn’t that mean that it needs to be a WindowCommand? Or where would I otherwise locate the window to call the show_quick_panel() function on?

1 Like

#6

view.window()

sublimetext.com/docs/2/api_r … blime.View

1 Like