Skip to content

Commit

Permalink
Fixed ctrl+' shortcut to toggle between the three types of quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
robcrocombe committed Dec 1, 2016
1 parent e53e25b commit 8d23fa3
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions toggle_quotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
from sublime import Region

re_quotes = re.compile("^(['\"`])(.*)\\1$")
quoteList = ['\'', '"', '`']


class ToggleQuotesCommand(sublime_plugin.TextCommand):
def run(self, edit, **kwargs):
v = self.view
if v.sel()[0].size() == 0:
v.run_command("expand_selection", {"to": "scope"})
v.run_command('expand_selection', {'to': 'scope'})

for sel in v.sel():
text = v.substr(sel)
Expand All @@ -24,7 +25,10 @@ def run(self, edit, **kwargs):
# still no match... skip it!
continue
oldQuotes = res.group(1)
newQuotes = kwargs["key"]
if 'key' in kwargs:
newQuotes = kwargs['key']
else:
newQuotes = quoteList[(quoteList.index(oldQuotes) + 1) % len(quoteList)]
text = res.group(2)
text = text.replace(newQuotes, "\\" + newQuotes)
text = text.replace("\\" + oldQuotes, oldQuotes)
Expand Down

0 comments on commit 8d23fa3

Please sign in to comment.