From f5df1354fe1936a3d8dc126a8ae2d8fa0a481d88 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Mon, 7 Sep 2026 18:57:40 +0200 Subject: [PATCH] fixup! Truncate the repo and branch names in the recent repos menu --- pkg/gui/controllers/helpers/repos_helper.go | 71 +++++++++++---------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/pkg/gui/controllers/helpers/repos_helper.go b/pkg/gui/controllers/helpers/repos_helper.go index b8e39af76..ff2a1b546 100644 --- a/pkg/gui/controllers/helpers/repos_helper.go +++ b/pkg/gui/controllers/helpers/repos_helper.go @@ -132,6 +132,42 @@ func (self *ReposHelper) recentRepoTooltip(repoName string, branchName string) s }), "\n") } +func (self *ReposHelper) recentRepoMenuItem(path string, branchName string) *types.MenuItem { + repoName := filepath.Base(path) + + displayedBranchName := utils.TruncateWithEllipsis(branchName, recentReposColumnMaxWidth) + if icons.IsIconEnabled() { + displayedBranchName = icons.BRANCH_ICON + " " + displayedBranchName + } + + return &types.MenuItem{ + LabelColumns: []string{ + utils.TruncateWithEllipsis(repoName, recentReposColumnMaxWidth), + style.FgCyan.Sprint(displayedBranchName), + // The last segment of the path is already in the first column, so + // showing the directory that contains the repo is enough to tell + // repos with the same name apart. + style.FgMagenta.Sprint(utils.ContractTilde(filepath.Dir(path))), + }, + // Filtering matches the full text, including the parts that the columns + // above truncate or leave out. + FilterColumns: []string{repoName, branchName, path}, + Tooltip: self.recentRepoTooltip(repoName, branchName), + OnPress: func() error { + // Check before clearing the stack, so a refused switch doesn't + // forget the submodule breadcrumb (which would leave escape + // unable to return to the parent repo). + if self.switchRefusedBecauseBusy() { + return nil + } + // if we were in a submodule, we want to forget about that stack of repos + // so that hitting escape in the new repo does nothing + self.c.State().GetRepoPathStack().Clear() + return self.switchTo(path, self.c.Tr.ErrRepositoryMovedOrDeleted, context.NO_CONTEXT) + }, + } +} + func (self *ReposHelper) CreateRecentReposMenu() error { // we'll show an empty panel if there are no recent repos recentRepoPaths := []string{} @@ -155,40 +191,7 @@ func (self *ReposHelper) CreateRecentReposMenu() error { wg.Wait() menuItems := lo.Map(recentRepoPaths, func(path string, i int) *types.MenuItem { - repoName := filepath.Base(path) - branchName := currentBranches[i] - - displayedBranchName := utils.TruncateWithEllipsis(branchName, recentReposColumnMaxWidth) - if icons.IsIconEnabled() { - displayedBranchName = icons.BRANCH_ICON + " " + displayedBranchName - } - - return &types.MenuItem{ - LabelColumns: []string{ - utils.TruncateWithEllipsis(repoName, recentReposColumnMaxWidth), - style.FgCyan.Sprint(displayedBranchName), - // The last segment of the path is already in the first column, - // so showing the directory that contains the repo is enough to - // tell repos with the same name apart. - style.FgMagenta.Sprint(utils.ContractTilde(filepath.Dir(path))), - }, - // Filtering matches the full text, including the parts that the - // columns above truncate or leave out. - FilterColumns: []string{repoName, branchName, path}, - Tooltip: self.recentRepoTooltip(repoName, branchName), - OnPress: func() error { - // Check before clearing the stack, so a refused switch doesn't - // forget the submodule breadcrumb (which would leave escape - // unable to return to the parent repo). - if self.switchRefusedBecauseBusy() { - return nil - } - // if we were in a submodule, we want to forget about that stack of repos - // so that hitting escape in the new repo does nothing - self.c.State().GetRepoPathStack().Clear() - return self.switchTo(path, self.c.Tr.ErrRepositoryMovedOrDeleted, context.NO_CONTEXT) - }, - } + return self.recentRepoMenuItem(path, currentBranches[i]) }) return self.c.Menu(types.CreateMenuOptions{