diff --git a/pkg/gui/controllers/switch_to_diff_files_controller.go b/pkg/gui/controllers/switch_to_diff_files_controller.go index 10a3d19cc..86e927558 100644 --- a/pkg/gui/controllers/switch_to_diff_files_controller.go +++ b/pkg/gui/controllers/switch_to_diff_files_controller.go @@ -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{}) diff --git a/pkg/gui/filetree/commit_file_tree_view_model.go b/pkg/gui/filetree/commit_file_tree_view_model.go index 3a93d6eb3..02b0fff9a 100644 --- a/pkg/gui/filetree/commit_file_tree_view_model.go +++ b/pkg/gui/filetree/commit_file_tree_view_model.go @@ -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 {