Thanks for this code. I implemented this feature in a previous editor but your code works much nicer than what I did before. I use this quite a bit but I found a few issues with the code that bothered me a little.
1) The cursor moves to the left if code is run and it isn't in a string. The code should have no effect.
2) When starting on the opening quote, the cursor ends up moving to the right. The cursor should stay on the opening quote.
3) The code doesn't support multiple selects.
I made a few simple changes to resolve these issues. Below is a patch to add the fixes to your code.
--- toggle_quotes_original.py Wed Jul 13 10:03:17 2011
+++ toggle_quotes.py Mon Jul 11 09:38:24 2011
@@ -2,6 +2,7 @@
def run(self, edit):
+ sels = list(self.view.sel())
for region in self.view.sel():
scope = self.view.scope_name(region.begin())
@@ -63,15 +64,10 @@
self.view.replace(edit, sublime.Region(start - 1, start), '')
end -= 1
- # fix for cursor moving outside string, thanks to adzenith
+ # fix for cursor moving outside string
rs = self.view.sel()
- scope = self.view.scope_name(rs.begin())
- if scope.find('string.quoted') == -1:
- p = rs.begin() - 1
- region = sublime.Region(p, p)
+ for region in sels:
def is_escaped(self, point):