1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-10-08 22:52:12 +02:00

fixup! When entering a commit in path filtering mode, select the filtered path

This commit is contained in:
Stefan Haller
2025-10-08 10:40:17 +02:00
parent e24e1618bb
commit c2d83f9a77
2 changed files with 10 additions and 2 deletions

View File

@@ -1,6 +1,8 @@
package controllers
import (
"path/filepath"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
@@ -91,8 +93,12 @@ func (self *SwitchToDiffFilesController) enter() error {
})
if filterPath := self.c.Modes().Filtering.GetPath(); filterPath != "" {
path, err := filepath.Rel(self.c.Git().RepoPaths.RepoPath(), filterPath)
if err != nil {
path = filterPath
}
commitFilesContext.CommitFileTreeViewModel.SelectPath(
filterPath, self.c.UserConfig().Gui.ShowRootItemInFileTree)
filepath.ToSlash(path), self.c.UserConfig().Gui.ShowRootItemInFileTree)
}
self.c.Context().Push(commitFilesContext, types.OnFocusOpts{})

View File

@@ -194,7 +194,9 @@ func (self *CommitFileTreeViewModel) ExpandAll() {
// Try to select the given path if present. If it doesn't exist, or one of the parent directories is
// collapsed, do nothing.
// Note that filepath is an actual file path, not an internal tree path as with e.g. ToggleCollapsed.
// Note that filepath is an actual file path, not an internal tree path as with e.g.
// ToggleCollapsed. It must be a relative path (relative to the repo root), and it must contain
// forward slashes rather than backslashes even on Windows.
func (self *CommitFileTreeViewModel) SelectPath(filepath string, showRootItem bool) {
index, found := self.GetIndexForPath(InternalTreePathForFilePath(filepath, showRootItem))
if found {