-
Notifications
You must be signed in to change notification settings - Fork 1
/
command_goto_file.py
33 lines (31 loc) · 1.16 KB
/
command_goto_file.py
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
32
33
from .core.git_commands import Git
from .core.git_diff_view import GitDiffView
from .utils import get_line
from os import path
import sublime
import sublime_plugin
# command: git_diff_view_goto_file
class GitDiffViewGotoFileCommand(sublime_plugin.TextCommand):
def run(self, _: sublime.Edit) -> None:
window = self.view.window()
if not window:
return
line = get_line(self.view)
if line is None:
return
git = Git(window)
git_statuses = GitDiffView.git_statuses[window.id()]
git_status = git_statuses[line]
if not git_status:
return
if 'D' in git_status["modification_type"]:
window.status_message("GitDiffVIew: Can't go to a deleted file")
return
file_name = git_status["file_name"]
if not git.git_root_dir or not file_name:
return
absolute_path_to_file = path.join(git.git_root_dir,
git_status["file_name"])
window.run_command('toggle_git_diff_view')
view = window.open_file(absolute_path_to_file)
sublime.set_timeout(lambda: window.focus_view(view))