Skip to content

Commit

Permalink
added 'Diff Selections' command
Browse files Browse the repository at this point in the history
  • Loading branch information
colinta committed Jan 12, 2012
1 parent 4bdd32d commit 8df3a61
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FileDiffs Plugin for Sublime Text 2
===================================

Show diffs between the current file, or selection(s) in the current file, and clipboard, another file, or unsaved changes.
Show diffs between the current file (or selection(s) in the current file) with the clipboard, another file, or unsaved changes.


Installation
Expand All @@ -28,6 +28,8 @@ The rest of the commands are not bound by default:

`file_diff_clipboard`: Shows the diff of the current file or selection(s) and the clipboard (the clipboard is considered the "new" file unless `reverse` is True)

`file_diff_selections`: Shows the diff of the first and second selected regions. The file_diff_menu command checks for exactly two regions selected, otherwise it doesn't display this command.

`file_diff_saved`: Shows the diff of the current file or selection(s) and the saved file.

`file_diff_file`: Shows the diff of the current file or selection(s) and a file that is in the current project.
Expand Down
22 changes: 17 additions & 5 deletions file_diffs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@


CLIPBOARD = u'Diff file with Clipboard'
SELECTIONS = u'Diff Selections'
SAVED = u'Diff file with Saved'
FILE = u'Diff file with File in Project…'
TAB = u'Diff file with Open Tab…'
Expand All @@ -21,17 +22,19 @@
class FileDiffMenuCommand(sublime_plugin.TextCommand):
def run(self, edit):
menu_items = FILE_DIFFS
regions = [region for region in self.view.sel()]
for region in regions:
if not region.empty():
menu_items = [f.replace(u'Diff file', u'Diff selection') for f in FILE_DIFFS]
break
regions = self.view.sel()
if len(regions) == 1 and not regions[0].empty():
menu_items = [f.replace(u'Diff file', u'Diff selection') for f in FILE_DIFFS]
elif len(regions) == 2:
menu_items.insert(1, SELECTIONS)

def on_done(index):
if index == -1:
return
elif FILE_DIFFS[index] == CLIPBOARD:
self.view.run_command('file_diff_clipboard')
elif FILE_DIFFS[index] == SELECTIONS:
self.view.run_command('file_diff_selections')
elif FILE_DIFFS[index] == SAVED:
self.view.run_command('file_diff_saved')
elif FILE_DIFFS[index] == FILE:
Expand Down Expand Up @@ -104,6 +107,15 @@ def run(self, edit, **kwargs):
self.show_diff(diff)


class FileDiffSelectionsCommand(FileDiffCommand):
def run(self, edit, **kwargs):
regions = self.view.sel()
current = self.view.substr(regions[0])
diff = self.view.substr(regions[1])
diff = self.run_diff(current, diff)
self.show_diff(diff)


class FileDiffSavedCommand(FileDiffCommand):
def run(self, edit, **kwargs):
content = ''
Expand Down

0 comments on commit 8df3a61

Please sign in to comment.