Home Download Buy Blog Forum Support

Insert text at current cursor position

Insert text at current cursor position

Postby nmeirik on Tue Sep 13, 2011 7:11 pm

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!
nmeirik
 
Posts: 8
Joined: Fri Sep 09, 2011 9:10 am

Re: Insert text at current cursor position

Postby jbjornson on Wed Sep 14, 2011 8:25 am

As well as self.view rather than self.window.active_view()
jbjornson
 
Posts: 349
Joined: Tue Oct 27, 2009 4:25 pm
Location: Zurich, Switzerland

Re: Insert text at current cursor position

Postby nmeirik on Wed Sep 14, 2011 1:59 pm

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.
nmeirik
 
Posts: 8
Joined: Fri Sep 09, 2011 9:10 am

Re: Insert text at current cursor position

Postby jbjornson on Wed Sep 14, 2011 2:01 pm

nmeirik wrote: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.


I think that if your plugin is doing some action on the contents of the current view, then you should use a text command.
jbjornson
 
Posts: 349
Joined: Tue Oct 27, 2009 4:25 pm
Location: Zurich, Switzerland

Re: Insert text at current cursor position

Postby nmeirik on Wed Sep 14, 2011 2:04 pm

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?
nmeirik
 
Posts: 8
Joined: Fri Sep 09, 2011 9:10 am

Re: Insert text at current cursor position

Postby jbjornson on Wed Sep 14, 2011 2:49 pm

jbjornson
 
Posts: 349
Joined: Tue Oct 27, 2009 4:25 pm
Location: Zurich, Switzerland


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 10 guests