diff options
Diffstat (limited to 'pkg/gui/files_panel.go')
-rw-r--r-- | pkg/gui/files_panel.go | 165 |
1 files changed, 0 insertions, 165 deletions
diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index 04d05df6f..db4bd3a54 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -2,12 +2,8 @@ package gui import ( "github.com/jesseduffield/gocui" - "github.com/jesseduffield/lazygit/pkg/commands/loaders" "github.com/jesseduffield/lazygit/pkg/commands/models" - "github.com/jesseduffield/lazygit/pkg/commands/types/enums" - "github.com/jesseduffield/lazygit/pkg/gui/context" "github.com/jesseduffield/lazygit/pkg/gui/filetree" - "github.com/jesseduffield/lazygit/pkg/gui/mergeconflicts" "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/utils" ) @@ -87,167 +83,6 @@ func (gui *Gui) filesRenderToMain() error { return gui.refreshMainViews(refreshOpts) } -func (gui *Gui) refreshFilesAndSubmodules() error { - gui.Mutexes.RefreshingFilesMutex.Lock() - gui.State.IsRefreshingFiles = true - defer func() { - gui.State.IsRefreshingFiles = false - gui.Mutexes.RefreshingFilesMutex.Unlock() - }() - - prevSelectedPath := gui.getSelectedPath() - - if err := gui.refreshStateSubmoduleConfigs(); err != nil { - return err - } - - if err := gui.refreshMergeState(); err != nil { - return err - } - - if err := gui.refreshStateFiles(); err != nil { - return err - } - - gui.OnUIThread(func() error { - if err := gui.c.PostRefreshUpdate(gui.State.Contexts.Submodules); err != nil { - gui.c.Log.Error(err) - } - - if types.ContextKey(gui.Views.Files.Context) == context.FILES_CONTEXT_KEY { - // doing this a little custom (as opposed to using gui.c.PostRefreshUpdate) because we handle selecting the file explicitly below - if err := gui.State.Contexts.Files.HandleRender(); err != nil { - return err - } - } - - if gui.currentContext().GetKey() == context.FILES_CONTEXT_KEY { - currentSelectedPath := gui.getSelectedPath() - alreadySelected := prevSelectedPath != "" && currentSelectedPath == prevSelectedPath - if !alreadySelected { - gui.takeOverMergeConflictScrolling() - } - - gui.Views.Files.FocusPoint(0, gui.State.Panels.Files.SelectedLineIdx) - return gui.filesRenderToMain() - } - - return nil - }) - - return nil -} - -func (gui *Gui) refreshStateFiles() error { - state := gui.State - - // keep track of where the cursor is currently and the current file names - // when we refresh, go looking for a matching name - // move the cursor to there. - - selectedNode := gui.getSelectedFileNode() - - prevNodes := gui.State.FileTreeViewModel.GetAllItems() - prevSelectedLineIdx := gui.State.Panels.Files.SelectedLineIdx - - // If git thinks any of our files have inline merge conflicts, but they actually don't, - // we stage them. - // Note that if files with merge conflicts have both arisen and have been resolved - // between refreshes, we won't stage them here. This is super unlikely though, - // and this approach spares us from having to call `git status` twice in a row. - // Although this also means that at startup we won't be staging anything until - // we call git status again. - pathsToStage := []string{} - prevConflictFileCount := 0 - for _, file := range state.FileTreeViewModel.GetAllFiles() { - if file.HasMergeConflicts { - prevConflictFileCount++ - } - if file.HasInlineMergeConflicts { - hasConflicts, err := mergeconflicts.FileHasConflictMarkers(file.Name) - if err != nil { - gui.Log.Error(err) - } else if !hasConflicts { - pathsToStage = append(pathsToStage, file.Name) - } - } - } - - if len(pathsToStage) > 0 { - gui.c.LogAction(gui.Tr.Actions.StageResolvedFiles) - if err := gui.git.WorkingTree.StageFiles(pathsToStage); err != nil { - return gui.c.Error(err) - } - } - - files := gui.git.Loaders.Files. - GetStatusFiles(loaders.GetStatusFileOptions{}) - - conflictFileCount := 0 - for _, file := range files { - if file.HasMergeConflicts { - conflictFileCount++ - } - } - - if gui.git.Status.WorkingTreeState() != enums.REBASE_MODE_NONE && conflictFileCount == 0 && prevConflictFileCount > 0 { - gui.OnUIThread(func() error { return gui.promptToContinueRebase() }) - } - - // for when you stage the old file of a rename and the new file is in a collapsed dir - state.FileTreeViewModel.RWMutex.Lock() - for _, file := range files { - if selectedNode != nil && selectedNode.Path != "" && file.PreviousName == selectedNode.Path { - state.FileTreeViewModel.ExpandToPath(file.Name) - } - } - - // only taking over the filter if it hasn't already been set by the user. - // Though this does make it impossible for the user to actually say they want to display all if - // conflicts are currently being shown. Hmm. Worth it I reckon. If we need to add some - // extra state here to see if the user's set the filter themselves we can do that, but - // I'd prefer to maintain as little state as possible. - if conflictFileCount > 0 { - if state.FileTreeViewModel.GetFilter() == filetree.DisplayAll { - state.FileTreeViewModel.SetFilter(filetree.DisplayConflicted) - } - } else if state.FileTreeViewModel.GetFilter() == filetree.DisplayConflicted { - state.FileTreeViewModel.SetFilter(filetree.DisplayAll) - } - - state.FileTreeViewModel.SetFiles(files) - state.FileTreeViewModel.RWMutex.Unlock() - - if err := gui.fileWatcher.addFilesToFileWatcher(files); err != nil { - return err - } - - if selectedNode != nil { - newIdx := gui.findNewSelectedIdx(prevNodes[prevSelectedLineIdx:], state.FileTreeViewModel.GetAllItems()) - if newIdx != -1 && newIdx != prevSelectedLineIdx { - newNode := state.FileTreeViewModel.GetItemAtIndex(newIdx) - // when not in tree mode, we show merge conflict files at the top, so you - // can work through them one by one without having to sift through a large - // set of files. If you have just fixed the merge conflicts of a file, we - // actually don't want to jump to that file's new position, because that - // file will now be ages away amidst the other files without merge - // conflicts: the user in this case would rather work on the next file - // with merge conflicts, which will have moved up to fill the gap left by - // the last file, meaning the cursor doesn't need to move at all. - leaveCursor := !state.FileTreeViewModel.InTreeMode() && newNode != nil && - selectedNode.File != nil && selectedNode.File.HasMergeConflicts && - newNode.File != nil && !newNode.File.HasMergeConflicts - - if !leaveCursor { - state.Panels.Files.SelectedLineIdx = newIdx - } - } - } - - gui.refreshSelectedLine(state.Panels.Files, state.FileTreeViewModel.GetItemsLength()) - return nil -} - // promptToContinueRebase asks the user if they want to continue the rebase/merge that's in progress func (gui *Gui) promptToContinueRebase() error { gui.takeOverMergeConflictScrolling() |