Skip to content

Commit fe73ef0

Browse files
committed
added filenames back, instead of 'from_file' and 'to_file'
1 parent 4aa35d9 commit fe73ef0

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

file_diffs.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,28 +65,29 @@ def diff_content(self):
6565
content = self.view.substr(sublime.Region(0, self.view.size()))
6666
return content
6767

68-
def run_diff(self, a, b):
68+
def run_diff(self, a, b, from_file=None, to_file=None):
6969
from_content = a
70-
from_file = None
71-
7270
to_content = b
73-
to_file = None
7471

7572
if os.path.exists(a):
76-
from_file = a
73+
if from_file is None:
74+
from_file = a
7775
with codecs.open(from_file, mode='U', encoding='utf-8') as f:
7876
from_content = f.readlines()
7977
else:
8078
from_content = a.splitlines(True)
81-
from_file = 'from_file'
79+
if from_file is None:
80+
from_file = 'from_file'
8281

8382
if os.path.exists(b):
84-
to_file = b
83+
if to_file is None:
84+
to_file = b
8585
with codecs.open(to_file, mode='U', encoding='utf-8') as f:
8686
to_content = f.readlines()
8787
else:
8888
to_content = b.splitlines(True)
89-
to_file = 'to_file'
89+
if to_file is None:
90+
to_file = 'to_file'
9091

9192
diff = difflib.unified_diff(from_content, to_content, from_file, to_file)
9293

@@ -111,7 +112,9 @@ def show_diff(self, diff):
111112
class FileDiffClipboardCommand(FileDiffCommand):
112113
def run(self, edit, **kwargs):
113114
current = sublime.get_clipboard()
114-
diff = self.run_diff(self.diff_content(), current)
115+
diff = self.run_diff(self.diff_content(), current,
116+
from_file=self.view.file_name(),
117+
to_file='(clipboard)')
115118
self.show_diff(diff)
116119

117120

@@ -154,7 +157,9 @@ def run(self, edit, **kwargs):
154157
if indent:
155158
diff = u"\n".join(line[len(indent):] for line in diff.splitlines())
156159

157-
self.show_diff(self.run_diff(current, diff))
160+
self.show_diff(self.run_diff(current, diff),
161+
from_file='first selection',
162+
to_file='second selection')
158163

159164

160165
class FileDiffSavedCommand(FileDiffCommand):
@@ -168,7 +173,9 @@ def run(self, edit, **kwargs):
168173
if not content:
169174
content = self.view.substr(sublime.Region(0, self.view.size()))
170175

171-
diff = self.run_diff(self.view.file_name(), content)
176+
diff = self.run_diff(self.view.file_name(), content,
177+
from_file=self.view.file_name(),
178+
to_file=self.view.file_name() + u' (Unsaved)')
172179
self.show_diff(diff)
173180

174181

@@ -194,7 +201,8 @@ def run(self, edit, **kwargs):
194201

195202
def on_done(index):
196203
if index > -1:
197-
diff = self.run_diff(self.diff_content(), files[index])
204+
diff = self.run_diff(self.diff_content(), files[index],
205+
from_file=self.view.file_name())
198206
self.show_diff(diff)
199207
self.view.window().show_quick_panel(file_picker, on_done)
200208

@@ -244,7 +252,9 @@ def run(self, edit, **kwargs):
244252

245253
def on_done(index):
246254
if index > -1:
247-
diff = self.run_diff(self.diff_content(), contents[index])
255+
diff = self.run_diff(self.diff_content(), contents[index],
256+
from_file=self.view.file_name(),
257+
to_file=files[index])
248258
self.show_diff(diff)
249259

250260
if len(files) == 1:

0 commit comments

Comments
 (0)