Skip to content

Commit c2d83f9

Browse files
committed
fixup! When entering a commit in path filtering mode, select the filtered path
1 parent e24e161 commit c2d83f9

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

pkg/gui/controllers/switch_to_diff_files_controller.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package controllers
22

33
import (
4+
"path/filepath"
5+
46
"github.com/jesseduffield/lazygit/pkg/commands/models"
57
"github.com/jesseduffield/lazygit/pkg/gui/types"
68
)
@@ -91,8 +93,12 @@ func (self *SwitchToDiffFilesController) enter() error {
9193
})
9294

9395
if filterPath := self.c.Modes().Filtering.GetPath(); filterPath != "" {
96+
path, err := filepath.Rel(self.c.Git().RepoPaths.RepoPath(), filterPath)
97+
if err != nil {
98+
path = filterPath
99+
}
94100
commitFilesContext.CommitFileTreeViewModel.SelectPath(
95-
filterPath, self.c.UserConfig().Gui.ShowRootItemInFileTree)
101+
filepath.ToSlash(path), self.c.UserConfig().Gui.ShowRootItemInFileTree)
96102
}
97103

98104
self.c.Context().Push(commitFilesContext, types.OnFocusOpts{})

pkg/gui/filetree/commit_file_tree_view_model.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,9 @@ func (self *CommitFileTreeViewModel) ExpandAll() {
194194

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

0 commit comments

Comments
 (0)