Skip to content

Commit

Permalink
Toggle String/Symbol: Support multiple carets
Browse files Browse the repository at this point in the history
This commit makes the "Toggle String/Symbol" command to works correctly with discontinuous selections. Now it toggles each selected string/symbol.
  • Loading branch information
estum authored and infininight committed Aug 3, 2015
1 parent 944e8de commit 6c5431d
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions Commands/Toggle String:Symbol.tmCommand
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,24 @@
<key>command</key>
<string>#!/usr/bin/env ruby18
print case str = STDIN.read
# Handle standard quotes
when /\A["'](\w+)["']\z/ then ":" + $1
when /\A:(\w+)\z/ then '"' + $1 + '"'
# Default case
else str
require ENV['TM_SUPPORT_PATH'] + '/lib/exit_codes'
def toggle_string_symbol(str)
case str
# "string" =&gt; :symbol
when /("|')(\w+)\1/
str.gsub!(/("|')(\w+)\1/, ':\2')
# :symbol =&gt; "string"
when /:(\w+)/
str.gsub!(/:(\w+)/, '"\1"')
# initial case (no changes)
else
str
end
end
while str = $stdin.gets
print toggle_string_symbol(str)
end
</string>
<key>fallbackInput</key>
Expand All @@ -28,7 +40,7 @@ end
<key>output</key>
<string>replaceSelectedText</string>
<key>scope</key>
<string>source.ruby string.quoted, source.ruby constant.other.symbol.ruby</string>
<string>source.ruby string.quoted, source.ruby constant.other.symbol</string>
<key>uuid</key>
<string>B297E4B8-A8FF-49CE-B9C4-6D4911724D43</string>
</dict>
Expand Down

0 comments on commit 6c5431d

Please sign in to comment.