-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoggle_slashes.py
More file actions
31 lines (24 loc) · 1 KB
/
toggle_slashes.py
File metadata and controls
31 lines (24 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import sublime
import sublime_plugin
def swap_slashes(str):
split_on_bs = str.split("\\")
rejoin_w_fs = []
for _ in split_on_bs:
rejoin_w_fs.append(_.replace("/", "\\"))
return("/".join(rejoin_w_fs))
class ToggleSlashesCommand(sublime_plugin.TextCommand):
def run(self, edit):
# Go through all the regions that might be selected
for selection in self.view.sel():
if (selection.empty()):
# An empty selection region means we have a single cursor on a line.
line = self.view.line(selection)
# Line contents
contents = self.view.substr(line)
# Replace with slash-swapped contents
self.view.replace(edit, line, swap_slashes(contents))
else:
# Region contents
contents = self.view.substr(selection)
# Replace with slash-swapped contents
self.view.replace(edit, selection, swap_slashes(contents))