Home Download Buy Blog Forum Support

What is the easiest way to clear the view?

What is the easiest way to clear the view?

Postby aponxi on Tue Dec 25, 2012 12:30 am

Lets say I have a bunch of text written in the editor, and the plugin in knows which view this is. What is the best way to empty the document? Do you select all and then clear?

Do you use these methods:


Methods Return Value Description
begin() int Returns the minimum of a and b.
end() int Returns the maximum of a and b.
erase(edit, region) None Erases the contents of the region from the buffer.

Well I'm not to clear on what Regions are so if you would enlighten me I'd appreciate it : )
aponxi
 
Posts: 7
Joined: Sat Dec 22, 2012 11:53 pm

Re: What is the easiest way to clear the view?

Postby agibsonsw on Tue Dec 25, 2012 1:41 am

Searching the default key-bindings to find the equivalent of Ctrl-A and Delete:
Code: Select all
some_view.run_command("select_all")
some_view.run_command("right_delete")

When working with the ST-API it is easy to forget that often the simplest way is just to run a command.

To do this with the API:
Code: Select all
some_view.erase(edit, sublime.Region(0, some_view.size())


FYI The content of a view can be considered the region (0, view.size()). This does not correspond directly to the number of (single) character-positions as the Tab character, which might cover e.g. four-space, can be regarded as a single character. Internally, it is a little more detailed than this suggests, because ST is able to extract from a region the line (row) and column positions. It must, therefore, (I'm guessing!) maintain an internal map of how different regions correspond to different areas of the view.

RegionSets are far less useful (than Regions) as we cannot arbitrarily create these. The most significant RegionSet is sel(), which we can clear and add-to, etc.. However, we can store Regions in a list which, effectively, can then behave like a RegionSet.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: What is the easiest way to clear the view?

Postby aponxi on Tue Dec 25, 2012 4:03 pm

Thank you for your help again : ) I'm still writing the plugin and will be able to test once I finish the modifications
aponxi
 
Posts: 7
Joined: Sat Dec 22, 2012 11:53 pm


Return to Plugin Development

Who is online

Users browsing this forum: Google [Bot] and 10 guests