|
10 | 10 |
|
11 | 11 |
|
12 | 12 | CLIPBOARD = u'Diff file with Clipboard' |
| 13 | +SELECTIONS = u'Diff Selections' |
13 | 14 | SAVED = u'Diff file with Saved' |
14 | 15 | FILE = u'Diff file with File in Project…' |
15 | 16 | TAB = u'Diff file with Open Tab…' |
|
21 | 22 | class FileDiffMenuCommand(sublime_plugin.TextCommand): |
22 | 23 | def run(self, edit): |
23 | 24 | menu_items = FILE_DIFFS |
24 | | - regions = [region for region in self.view.sel()] |
25 | | - for region in regions: |
26 | | - if not region.empty(): |
27 | | - menu_items = [f.replace(u'Diff file', u'Diff selection') for f in FILE_DIFFS] |
28 | | - break |
| 25 | + regions = self.view.sel() |
| 26 | + if len(regions) == 1 and not regions[0].empty(): |
| 27 | + menu_items = [f.replace(u'Diff file', u'Diff selection') for f in FILE_DIFFS] |
| 28 | + elif len(regions) == 2: |
| 29 | + menu_items.insert(1, SELECTIONS) |
29 | 30 |
|
30 | 31 | def on_done(index): |
31 | 32 | if index == -1: |
32 | 33 | return |
33 | 34 | elif FILE_DIFFS[index] == CLIPBOARD: |
34 | 35 | self.view.run_command('file_diff_clipboard') |
| 36 | + elif FILE_DIFFS[index] == SELECTIONS: |
| 37 | + self.view.run_command('file_diff_selections') |
35 | 38 | elif FILE_DIFFS[index] == SAVED: |
36 | 39 | self.view.run_command('file_diff_saved') |
37 | 40 | elif FILE_DIFFS[index] == FILE: |
@@ -104,6 +107,15 @@ def run(self, edit, **kwargs): |
104 | 107 | self.show_diff(diff) |
105 | 108 |
|
106 | 109 |
|
| 110 | +class FileDiffSelectionsCommand(FileDiffCommand): |
| 111 | + def run(self, edit, **kwargs): |
| 112 | + regions = self.view.sel() |
| 113 | + current = self.view.substr(regions[0]) |
| 114 | + diff = self.view.substr(regions[1]) |
| 115 | + diff = self.run_diff(current, diff) |
| 116 | + self.show_diff(diff) |
| 117 | + |
| 118 | + |
107 | 119 | class FileDiffSavedCommand(FileDiffCommand): |
108 | 120 | def run(self, edit, **kwargs): |
109 | 121 | content = '' |
|
0 commit comments