Skip to content

Commit

Permalink
Enhancement: set cursor to the active branch
Browse files Browse the repository at this point in the history
  • Loading branch information
randy3k committed Aug 18, 2017
1 parent eea7d31 commit ed81f00
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
7 changes: 5 additions & 2 deletions common/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ def render(self, nuke_cursors=False):
"regions": self.regions,
"nuke_cursors": nuke_cursors
})
if hasattr(self, "reset_cursor") and nuke_cursors:
self.reset_cursor()

def _render_template(self):
"""
Expand Down Expand Up @@ -276,16 +278,17 @@ class GsInterfaceRefreshCommand(TextCommand):
Re-render GitSavvy interface view.
"""

def run(self, edit):
def run(self, edit, nuke_cursors=False):
sublime.set_timeout_async(self.run_async, 0)
self.nuke_cursors = nuke_cursors

def run_async(self):
interface_type = self.view.settings().get("git_savvy.interface")
for InterfaceSubclass in subclasses:
if InterfaceSubclass.interface_type == interface_type:
existing_interface = interfaces.get(self.view.id(), None)
if existing_interface:
existing_interface.render(nuke_cursors=False)
existing_interface.render(nuke_cursors=self.nuke_cursors)
else:
interface = InterfaceSubclass(view=self.view)
interfaces[interface.view.id()] = interface
Expand Down
5 changes: 3 additions & 2 deletions common/util/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def get_is_view_of_type(view, typ):
# GLOBAL #
##########

def refresh_gitsavvy(view, refresh_sidebar=False, refresh_status_bar=True):
def refresh_gitsavvy(view, refresh_sidebar=False, refresh_status_bar=True,
interface_reset_cursor=False):
"""
Called after GitSavvy action was taken that may have effected the
state of the Git repo.
Expand All @@ -67,7 +68,7 @@ def refresh_gitsavvy(view, refresh_sidebar=False, refresh_status_bar=True):
return

if view.settings().get("git_savvy.interface") is not None:
view.run_command("gs_interface_refresh")
view.run_command("gs_interface_refresh", {"nuke_cursors": interface_reset_cursor})

if refresh_status_bar:
view.run_command("gs_update_status_bar")
Expand Down
11 changes: 9 additions & 2 deletions core/commands/checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ def on_done(self, branch_name):
branch_name,
self.base_branch if self.base_branch else None)
sublime.status_message("Created and checked out `{}` branch.".format(branch_name))
util.view.refresh_gitsavvy(self.window.active_view())
util.view.refresh_gitsavvy(
self.window.active_view(),
refresh_sidebar=True,
interface_reset_cursor=True)


class GsCheckoutRemoteBranchCommand(WindowCommand, GitCommand):
Expand Down Expand Up @@ -113,7 +116,11 @@ def on_enter_local_name(self, branch_name):
self.git("checkout", "-b", branch_name, "--track", self.remote_branch)
sublime.status_message(
"Checked out `{}` as local branch `{}`.".format(self.remote_branch, branch_name))
util.view.refresh_gitsavvy(self.window.active_view(), refresh_sidebar=True)
util.view.refresh_gitsavvy(
self.window.active_view(),
refresh_sidebar=True,
interface_reset_cursor=True
)


class GsCheckoutCurrentFileCommand(WindowCommand, GitCommand):
Expand Down
20 changes: 19 additions & 1 deletion core/interfaces/branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ def pre_render(self):
self._branches = tuple(self.get_branches(sort_by_recent))

def on_new_dashboard(self):
self.view.run_command("gs_branches_navigate_branch")
self.view.run_command("gs_branches_set_cursor")

def reset_cursor(self):
self.view.run_command("gs_branches_set_cursor")

@ui.partial("branch_status")
def render_branch_status(self):
Expand Down Expand Up @@ -599,6 +602,21 @@ def get_available_regions(self):
for branch_region in self.view.lines(region)]


class GsBranchesSetCursorCommand(GsNavigate):

"""
Move cursor to the active branch.
"""

def get_available_regions(self):
return [
branch_region
for region in self.view.find_by_selector(
"meta.git-savvy.branches.branch string.other.git-savvy.branches.active-branch.sha1"
)
for branch_region in self.view.lines(region)]


class GsBranchesLogCommand(LogMixin, TextCommand, GitCommand):

"""
Expand Down

0 comments on commit ed81f00

Please sign in to comment.