From ded2336ca1002c13229db3072c2291826024fe49 Mon Sep 17 00:00:00 2001 From: Brent Swisher Date: Wed, 15 Nov 2017 20:12:52 -0500 Subject: [PATCH 1/2] When run is called, check if the selection is at the same line as the last call, if so, hide the phantom --- git-blame.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/git-blame.py b/git-blame.py index 7ced011..005f444 100644 --- a/git-blame.py +++ b/git-blame.py @@ -177,22 +177,23 @@ def on_phantom_close(self, href): def run(self, edit): phantoms = [] self.view.erase_phantoms('git-blame') - - for region in self.view.sel(): - line = self.view.line(region) - (row, col) = self.view.rowcol(region.begin()) - full_path = self.view.file_name() - result = self.get_blame(int(row) + 1, full_path) - if not result: - # Unable to get blame - return - - sha, user, date, time = self.parse_blame(result) - - body = template_one.format(sha=sha, user=user, date=date, time=time, stylesheet=stylesheet_one) - - phantom = sublime.Phantom(line, body, sublime.LAYOUT_BLOCK, self.on_phantom_close) - phantoms.append(phantom) + #Before adding the phantom, see if the current phantom that is displayed is at the same spot at the selection + if not (self.phantom_set.phantoms and self.view.line(self.view.sel()[0]) == self.view.line(self.phantom_set.phantoms[0].region)): + for region in self.view.sel(): + line = self.view.line(region) + (row, col) = self.view.rowcol(region.begin()) + full_path = self.view.file_name() + result = self.get_blame(int(row) + 1, full_path) + if not result: + # Unable to get blame + return + + sha, user, date, time = self.parse_blame(result) + + body = template_one.format(sha=sha, user=user, date=date, time=time, stylesheet=stylesheet_one) + + phantom = sublime.Phantom(line, body, sublime.LAYOUT_BLOCK, self.on_phantom_close) + phantoms.append(phantom) self.phantom_set.update(phantoms) From aeaf33754217c74ef86bec42f1dd27d913476b4d Mon Sep 17 00:00:00 2001 From: Brent Swisher Date: Thu, 16 Nov 2017 16:47:52 -0500 Subject: [PATCH 2/2] Update to return out of the run function if called from the same line as the last open phantom, instead of wrapping in an if statement --- git-blame.py | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/git-blame.py b/git-blame.py index 005f444..c54b57d 100644 --- a/git-blame.py +++ b/git-blame.py @@ -178,22 +178,25 @@ def run(self, edit): phantoms = [] self.view.erase_phantoms('git-blame') #Before adding the phantom, see if the current phantom that is displayed is at the same spot at the selection - if not (self.phantom_set.phantoms and self.view.line(self.view.sel()[0]) == self.view.line(self.phantom_set.phantoms[0].region)): - for region in self.view.sel(): - line = self.view.line(region) - (row, col) = self.view.rowcol(region.begin()) - full_path = self.view.file_name() - result = self.get_blame(int(row) + 1, full_path) - if not result: - # Unable to get blame - return - - sha, user, date, time = self.parse_blame(result) - - body = template_one.format(sha=sha, user=user, date=date, time=time, stylesheet=stylesheet_one) - - phantom = sublime.Phantom(line, body, sublime.LAYOUT_BLOCK, self.on_phantom_close) - phantoms.append(phantom) + if self.phantom_set.phantoms and self.view.line(self.view.sel()[0]) == self.view.line(self.phantom_set.phantoms[0].region): + self.phantom_set.update(phantoms) + return + + for region in self.view.sel(): + line = self.view.line(region) + (row, col) = self.view.rowcol(region.begin()) + full_path = self.view.file_name() + result = self.get_blame(int(row) + 1, full_path) + if not result: + # Unable to get blame + return + + sha, user, date, time = self.parse_blame(result) + + body = template_one.format(sha=sha, user=user, date=date, time=time, stylesheet=stylesheet_one) + + phantom = sublime.Phantom(line, body, sublime.LAYOUT_BLOCK, self.on_phantom_close) + phantoms.append(phantom) self.phantom_set.update(phantoms)