Skip to content

Commit 251cacc

Browse files
committed
Add new "Insta Diff" command to do [Show] immediately
Closes #57
1 parent 99d0bef commit 251cacc

File tree

6 files changed

+70
-7
lines changed

6 files changed

+70
-7
lines changed
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
[
22
{"keys": ["ctrl+shift+q"], "command": "blame"},
3-
{"keys": ["ctrl+shift+c"], "command": "blame_show_all"}
3+
{"keys": ["ctrl+shift+c"], "command": "blame_show_all"},
4+
//{"keys": ["f5"], "command": "toggle_inline_git_blame"},
5+
//{"keys": ["f8"], "command": "blame_insta_diff"},
46
]

Keymaps/Default (OSX).sublime-keymap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[
22
{"keys": ["ctrl+alt+b"], "command": "blame"},
33
{"keys": ["ctrl+alt+shift+b"], "command": "blame_show_all"},
4-
5-
//{"keys": ["f8"], "command": "toggle_inline_git_blame"},
4+
//{"keys": ["f5"], "command": "toggle_inline_git_blame"},
5+
//{"keys": ["f8"], "command": "blame_insta_diff"},
66
]
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
[
22
{"keys": ["ctrl+alt+b"], "command": "blame"},
3-
{"keys": ["ctrl+alt+shift+b"], "command": "blame_show_all"}
3+
{"keys": ["ctrl+alt+shift+b"], "command": "blame_show_all"},
4+
// {"keys": ["f5"], "command": "toggle_inline_git_blame"},
5+
// {"keys": ["f8"], "command": "blame_insta_diff"},
46
]

boot.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from .src.blame import * # noqa: F401,F403
44
from .src.blame_all import * # noqa: F401,F403
55
from .src.blame_inline import * # noqa: F401,F403
6+
from .src.blame_instadiff import * # noqa: F401,F403
7+
68

79
def plugin_loaded():
810
pass

src/blame.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
from .base import BaseBlame
77
from .templates import blame_phantom_css, blame_phantom_html_template
88

9-
# @todo Make a command to open the latest diff ("CommitDescription") for the current line in a single keystroke.
10-
# @body Currently it takes a keystroke and then a mouse click on "Show"
11-
129

1310
class Blame(BaseBlame, sublime_plugin.TextCommand):
1411

src/blame_instadiff.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from urllib.parse import quote_plus
2+
3+
import sublime_plugin
4+
5+
from .base import BaseBlame
6+
7+
8+
class BlameInstaDiff(BaseBlame, sublime_plugin.TextCommand):
9+
10+
# Overrides (TextCommand) ----------------------------------------------------------
11+
12+
def run(self, edit):
13+
if not self.has_suitable_view():
14+
self.tell_user_to_save()
15+
return
16+
17+
if len(self.view.sel()) != 1:
18+
self.communicate_error(
19+
"{0} requires there to be exactly 1 selection".format(
20+
self.__class__.__name__
21+
)
22+
)
23+
return
24+
sel0 = self.view.sel()[0]
25+
26+
row_num, _ = self.view.rowcol(sel0.begin())
27+
line_num = row_num + 1
28+
try:
29+
blame_output = self.get_blame_text(self.view.file_name(), line_num=line_num)
30+
except Exception as e:
31+
self.communicate_error(e)
32+
return
33+
34+
blame = self.parse_line(blame_output)
35+
if not blame:
36+
self.communicate_error(
37+
"Failed to parse anything for {0}. Has git's output format changed?".format(
38+
self.__class__.__name__
39+
)
40+
)
41+
return
42+
43+
href = "show?sha={0}".format(quote_plus(blame["sha_normalised"]))
44+
self.handle_phantom_button(href)
45+
46+
# Overrides (BaseBlame) ------------------------------------------------------------
47+
48+
def _view(self):
49+
return self.view
50+
51+
def close_by_user_request(self):
52+
raise NotImplementedError()
53+
54+
def extra_cli_args(self, line_num):
55+
return ["-L", "{0},{0}".format(line_num)]
56+
57+
def rerun(self, **kwargs):
58+
self.run(None)
59+
60+
# Overrides end --------------------------------------------------------------------

0 commit comments

Comments
 (0)