diff --git a/Commands/Toggle String:Symbol.tmCommand b/Commands/Toggle String:Symbol.tmCommand index 0619d80..425aa36 100644 --- a/Commands/Toggle String:Symbol.tmCommand +++ b/Commands/Toggle String:Symbol.tmCommand @@ -9,12 +9,24 @@ command #!/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" => :symbol + when /("|')(\w+)\1/ + str.gsub!(/("|')(\w+)\1/, ':\2') + # :symbol => "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 fallbackInput @@ -28,7 +40,7 @@ end output replaceSelectedText scope - source.ruby string.quoted, source.ruby constant.other.symbol.ruby + source.ruby string.quoted, source.ruby constant.other.symbol uuid B297E4B8-A8FF-49CE-B9C4-6D4911724D43