diff options
-rw-r--r-- | pkg/cheatsheet/generate.go | 2 | ||||
-rw-r--r-- | pkg/gui/context/context.go | 8 | ||||
-rw-r--r-- | pkg/gui/context/merge_conflicts_context.go | 63 | ||||
-rw-r--r-- | pkg/gui/context_config.go | 19 | ||||
-rw-r--r-- | pkg/gui/controllers.go | 2 | ||||
-rw-r--r-- | pkg/gui/controllers/files_controller.go | 4 | ||||
-rw-r--r-- | pkg/gui/controllers/helpers/merge_and_rebase_helper.go | 21 | ||||
-rw-r--r-- | pkg/gui/controllers/merge_conflicts_controller.go | 54 | ||||
-rw-r--r-- | pkg/gui/files_panel.go | 2 | ||||
-rw-r--r-- | pkg/gui/global_handlers.go | 4 | ||||
-rw-r--r-- | pkg/gui/gui.go | 29 | ||||
-rw-r--r-- | pkg/gui/keybindings.go | 34 | ||||
-rw-r--r-- | pkg/gui/main_panels.go | 2 | ||||
-rw-r--r-- | pkg/gui/merge_panel.go | 82 | ||||
-rw-r--r-- | pkg/gui/refresh.go | 10 | ||||
-rw-r--r-- | pkg/gui/views.go | 12 |
16 files changed, 215 insertions, 133 deletions
diff --git a/pkg/cheatsheet/generate.go b/pkg/cheatsheet/generate.go index d69a448fb..6d0007653 100644 --- a/pkg/cheatsheet/generate.go +++ b/pkg/cheatsheet/generate.go @@ -106,7 +106,7 @@ func localisedTitle(tr *i18n.TranslationSet, str string) string { "information": tr.InformationTitle, "main": tr.NormalTitle, "patchBuilding": tr.PatchBuildingTitle, - "merging": tr.MergingTitle, + "mergeConflicts": tr.MergingTitle, "staging": tr.StagingTitle, "menu": tr.MenuTitle, "search": tr.SearchTitle, diff --git a/pkg/gui/context/context.go b/pkg/gui/context/context.go index a0925d2b8..131eecf0a 100644 --- a/pkg/gui/context/context.go +++ b/pkg/gui/context/context.go @@ -23,7 +23,7 @@ const ( STAGING_SECONDARY_CONTEXT_KEY types.ContextKey = "stagingSecondary" PATCH_BUILDING_MAIN_CONTEXT_KEY types.ContextKey = "patchBuilding" PATCH_BUILDING_SECONDARY_CONTEXT_KEY types.ContextKey = "patchBuildingSecondary" - MERGING_MAIN_CONTEXT_KEY types.ContextKey = "merging" + MERGE_CONFLICTS_CONTEXT_KEY types.ContextKey = "mergeConflicts" // these shouldn't really be needed for anything but I'm giving them unique keys nonetheless OPTIONS_CONTEXT_KEY types.ContextKey = "options" @@ -60,7 +60,7 @@ var AllContextKeys = []types.ContextKey{ STAGING_SECONDARY_CONTEXT_KEY, PATCH_BUILDING_MAIN_CONTEXT_KEY, PATCH_BUILDING_SECONDARY_CONTEXT_KEY, - MERGING_MAIN_CONTEXT_KEY, + MERGE_CONFLICTS_CONTEXT_KEY, MENU_CONTEXT_KEY, CONFIRMATION_CONTEXT_KEY, @@ -93,7 +93,7 @@ type ContextTree struct { StagingSecondary *PatchExplorerContext CustomPatchBuilder *PatchExplorerContext CustomPatchBuilderSecondary types.Context - Merging types.Context + MergeConflicts *MergeConflictsContext Confirmation types.Context CommitMessage types.Context CommandLog types.Context @@ -127,7 +127,7 @@ func (self *ContextTree) Flatten() []types.Context { self.Confirmation, self.CommitMessage, - self.Merging, + self.MergeConflicts, self.StagingSecondary, self.Staging, self.CustomPatchBuilderSecondary, diff --git a/pkg/gui/context/merge_conflicts_context.go b/pkg/gui/context/merge_conflicts_context.go new file mode 100644 index 000000000..48749373c --- /dev/null +++ b/pkg/gui/context/merge_conflicts_context.go @@ -0,0 +1,63 @@ +package context + +import ( + "github.com/jesseduffield/gocui" + "github.com/jesseduffield/lazygit/pkg/gui/mergeconflicts" + "github.com/jesseduffield/lazygit/pkg/gui/types" +) + +type MergeConflictsContext struct { + types.Context + viewModel *ConflictsViewModel + c *types.HelperCommon +} + +type ConflictsViewModel struct { + state *mergeconflicts.State + + // userVerticalScrolling tells us if the user has started scrolling through the file themselves + // in which case we won't auto-scroll to a conflict. + userVerticalScrolling bool +} + +func NewMergeConflictsContext( + view *gocui.View, + + opts ContextCallbackOpts, + + c *types.HelperCommon, + getOptionsMap func() map[string]string, +) *MergeConflictsContext { + viewModel := &ConflictsViewModel{ + state: mergeconflicts.NewState(), + userVerticalScrolling: false, + } + + return &MergeConflictsContext{ + viewModel: viewModel, + Context: NewSimpleContext( + NewBaseContext(NewBaseContextOpts{ + Kind: types.MAIN_CONTEXT, + View: view, + WindowName: "main", + Key: MERGE_CONFLICTS_CONTEXT_KEY, + OnGetOptionsMap: getOptionsMap, + Focusable: true, + }), + opts, + ), + c: c, + } +} + +func (self *MergeConflictsContext) SetUserScrolling(isScrolling bool) { + self.viewModel.userVerticalScrolling = isScrolling +} + +func (self *MergeConflictsContext) IsUserScrolling() bool { + return self.viewModel.userVerticalScrolling +} + +func (self *MergeConflictsContext) State() *mergeconflicts.State { + return self.viewModel.state +} diff --git a/pkg/gui/context_config.go b/pkg/gui/context_config.go index 1ff8aad75..79f14c68c 100644 --- a/pkg/gui/context_config.go +++ b/pkg/gui/context_config.go @@ -10,7 +10,7 @@ func (gui *Gui) contextTree() *context.ContextTree { Global: context.NewSimpleContext( context.NewBaseContext(context.NewBaseContextOpts{ Kind: types.GLOBAL_CONTEXT, - View: nil, + View: nil, // TODO: see if this breaks anything WindowName: "", Key: context.GLOBAL_CONTEXT_KEY, Focusable: false, @@ -158,27 +158,22 @@ func (gui *Gui) contextTree() *context.ContextTree { }), context.ContextCallbackOpts{}, ), - Merging: context.NewSimpleContext( - context.NewBaseContext(context.NewBaseContextOpts{ - Kind: types.MAIN_CONTEXT, - View: gui.Views.Merging, - WindowName: "main", - Key: context.MERGING_MAIN_CONTEXT_KEY, - OnGetOptionsMap: gui.getMergingOptions, - Focusable: true, - }), + MergeConflicts: context.NewMergeConflictsContext( + gui.Views.MergeConflicts, context.ContextCallbackOpts{ OnFocus: OnFocusWrapper(func() error { - gui.Views.Merging.Wrap = false + gui.Views.MergeConflicts.Wrap = false return gui.renderConflictsWithLock(true) }), OnFocusLost: func(types.OnFocusLostOpts) error { - gui.Views.Merging.Wrap = true + gui.Views.MergeConflicts.Wrap = true return nil }, }, + gui.c, + gui.getMergingOptions, ), Confirmation: context.NewSimpleContext( context.NewBaseContext(context.NewBaseContextOpts{ diff --git a/pkg/gui/controllers.go b/pkg/gui/controllers.go index 1f18cd266..e0c2d5eb6 100644 --- a/pkg/gui/controllers.go +++ b/pkg/gui/controllers.go @@ -22,7 +22,7 @@ func (gui *Gui) resetControllers() { model, ) - rebaseHelper := helpers.NewMergeAndRebaseHelper(helperCommon, gui.State.Contexts, gui.git, gui.takeOverMergeConflictScrolling, refsHelper) + rebaseHelper := helpers.NewMergeAndRebaseHelper(helperCommon, gui.State.Contexts, gui.git, refsHelper) suggestionsHelper := helpers.NewSuggestionsHelper(helperCommon, model, gui.refreshSuggestions) gui.helpers = &helpers.Helpers{ Refs: refsHelper, diff --git a/pkg/gui/controllers/files_controller.go b/pkg/gui/controllers/files_controller.go index 0d2a10b35..ba5e49ad9 100644 --- a/pkg/gui/controllers/files_controller.go +++ b/pkg/gui/controllers/files_controller.go @@ -161,7 +161,7 @@ func (self *FilesController) GetMouseKeybindings(opts types.KeybindingsOpts) []* FocusedView: self.context().GetViewName(), }, { - ViewName: "merging", + ViewName: "mergeConflicts", Key: gocui.MouseLeft, Handler: self.onClickMain, FocusedView: self.context().GetViewName(), @@ -269,7 +269,7 @@ func (self *FilesController) pressWithLock(node *filetree.FileNode) error { file := node.File if file.HasInlineMergeConflicts { - return self.c.PushContext(self.contexts.Merging) + return self.c.PushContext(self.contexts.MergeConflicts) } if file.HasUnstagedChanges { diff --git a/pkg/gui/controllers/helpers/merge_and_rebase_helper.go b/pkg/gui/controllers/helpers/merge_and_rebase_helper.go index 6d2c680e3..4666f103d 100644 --- a/pkg/gui/controllers/helpers/merge_and_rebase_helper.go +++ b/pkg/gui/controllers/helpers/merge_and_rebase_helper.go @@ -14,26 +14,23 @@ import ( ) type MergeAndRebaseHelper struct { - c *types.HelperCommon - contexts *context.ContextTree - git *commands.GitCommand - takeOverMergeConflictScrolling func() - refsHelper *RefsHelper + c *types.HelperCommon + contexts *context.ContextTree + git *commands.GitCommand + refsHelper *RefsHelper } func NewMergeAndRebaseHelper( c *types.HelperCommon, contexts *context.ContextTree, git *commands.GitCommand, - takeOverMergeConflictScrolling func(), refsHelper *RefsHelper, ) *MergeAndRebaseHelper { return &MergeAndRebaseHelper{ - c: c, - contexts: contexts, - git: git, - takeOverMergeConflictScrolling: takeOverMergeConflictScrolling, - refsHelper: refsHelper, + c: c, + contexts: contexts, + git: git, + refsHelper: refsHelper, } } @@ -189,7 +186,7 @@ func (self *MergeAndRebaseHelper) workingTreeStateNoun() string { // PromptToContinueRebase asks the user if they want to continue the rebase/merge that's in progress func (self *MergeAndRebaseHelper) PromptToContinueRebase() error { - self.takeOverMergeConflictScrolling() + self.contexts.MergeConflicts.SetUserScrolling(false) return self.c.Confirm(types.ConfirmOpts{ Title: "continue", diff --git a/pkg/gui/controllers/merge_conflicts_controller.go b/pkg/gui/controllers/merge_conflicts_controller.go new file mode 100644 index 000000000..6ec6170f2 --- /dev/null +++ b/pkg/gui/controllers/merge_conflicts_controller.go @@ -0,0 +1,54 @@ +package controllers + +import ( + "github.com/jesseduffield/lazygit/pkg/gui/context" + "github.com/jesseduffield/lazygit/pkg/gui/types" +) + +type MergeConflictsController struct { + baseController + *controllerCommon +} + +var _ types.IController = &MergeConflictsController{} + +func NewMergeConflictsController( + common *controllerCommon, +) *MergeConflictsController { + return &MergeConflictsController{ + baseController: baseController{}, + controllerCommon: common, + } +} + +func (self *MergeConflictsController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding { + bindings := []*types.Binding{ + { + Key: opts.GetKey(opts.Config.Universal.Edit), + Handler: self.EditFile, + Description: self.c.Tr.LcEditFile, + }, + } + + return bindings +} + +func (self *MergeConflictsController) Context() types.Context { + return self.context() +} + +func (self *MergeConflictsController) context() *context.MergeConflictsContext { + return self.contexts.MergeConflicts +} + +func (self *MergeConflictsController) EditFile() error { + lineNumber := self.context().State().GetSelectedLine() + return self.helpers.Files.EditFileAtLine(self.context().State().GetPath(), lineNumber) +} + +func (self *MergeConflictsController) withMergeConflictLock(f func() error) error { + self.context().State().Lock() + defer self.context().State().Unlock() + + return f() +} diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index 484713bd7..568787089 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -93,7 +93,7 @@ func (gui *Gui) filesRenderToMain() error { } func (gui *Gui) onFocusFile() error { - gui.takeOverMergeConflictScrolling() + gui.State.Contexts.MergeConflicts.SetUserScrolling(false) return nil } diff --git a/pkg/gui/global_handlers.go b/pkg/gui/global_handlers.go index 0844b8ebe..b5a302a45 100644 --- a/pkg/gui/global_handlers.go +++ b/pkg/gui/global_handlers.go @@ -76,7 +76,7 @@ func (gui *Gui) scrollDownView(view *gocui.View) { func (gui *Gui) scrollUpMain() error { if gui.renderingConflicts() { - gui.State.Panels.Merging.UserVerticalScrolling = true + gui.State.Contexts.MergeConflicts.SetUserScrolling(true) } var view *gocui.View @@ -93,7 +93,7 @@ func (gui *Gui) scrollUpMain() error { func (gui *Gui) scrollDownMain() error { if gui.renderingConflicts() { - gui.State.Panels.Merging.UserVerticalScrolling = true + gui.State.Contexts.MergeConflicts.SetUserScrolling(true) } var view *gocui.View diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 908cede2e..fc9ce6e1a 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -19,7 +19,6 @@ import ( "github.com/jesseduffield/lazygit/pkg/config" "github.com/jesseduffield/lazygit/pkg/gui/context" "github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers" - "github.com/jesseduffield/lazygit/pkg/gui/mergeconflicts" "github.com/jesseduffield/lazygit/pkg/gui/modes/cherrypicking" "github.com/jesseduffield/lazygit/pkg/gui/modes/diffing" "github.com/jesseduffield/lazygit/pkg/gui/modes/filtering" @@ -169,7 +168,6 @@ type GuiRepoState struct { Suggestions []*types.Suggestion Updating bool - Panels *panelStates SplitMainPanel bool LimitCommits bool @@ -199,20 +197,6 @@ type GuiRepoState struct { CurrentPopupOpts *types.CreatePopupPanelOpts } -type MergingPanelState struct { - *mergeconflicts.State - - // UserVerticalScrolling tells us if the user has started scrolling through the file themselves - // in which case we won't auto-scroll to a conflict. - UserVerticalScrolling bool -} - -// as we move things to the new context approach we're going to eventually -// remove this struct altogether and store this state on the contexts. -type panelStates struct { - Merging *MergingPanelState -} - type searchingState struct { view *gocui.View isSearching bool @@ -299,13 +283,6 @@ func (gui *Gui) resetState(startArgs types.StartArgs, reuseState bool) { BisectInfo: git_commands.NewNullBisectInfo(), FilesTrie: patricia.NewTrie(), }, - - Panels: &panelStates{ - Merging: &MergingPanelState{ - State: mergeconflicts.NewState(), - UserVerticalScrolling: false, - }, - }, Modes: &types.Modes{ Filtering: filtering.New(startArgs.FilterPath), CherryPicking: cherrypicking.New(), @@ -438,7 +415,7 @@ var RuneReplacements = map[rune]string{ graph.CommitSymbol: "o", } -func (gui *Gui) initGocui() (*gocui.Gui, error) { +func (gui *Gui) initGocui(headless bool) (*gocui.Gui, error) { recordEvents := recordingEvents() playMode := gocui.NORMAL if recordEvents { @@ -447,7 +424,7 @@ func (gui *Gui) initGocui() (*gocui.Gui, error) { playMode = gocui.REPLAYING } - g, err := gocui.NewGui(gocui.OutputTrue, OverlappingEdges, playMode, headless(), RuneReplacements) + g, err := gocui.NewGui(gocui.OutputTrue, OverlappingEdges, playMode, headless, RuneReplacements) if err != nil { return nil, err } @@ -496,7 +473,7 @@ func (gui *Gui) viewTabMap() map[string][]context.TabView { // Run: setup the gui with keybindings and start the mainloop func (gui *Gui) Run(startArgs types.StartArgs) error { - g, err := gui.initGocui() + g, err := gui.initGocui(headless()) if err != nil { return err } diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 8c1a78dd2..9d02d636e 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -326,105 +326,105 @@ func (self *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBi Handler: self.scrollUpSecondary, }, { - ViewName: "merging", + ViewName: "mergeConflicts", Key: opts.GetKey(opts.Config.Universal.ScrollLeft), Handler: self.scrollLeftMain, Description: self.c.Tr.LcScrollLeft, Tag: "navigation", }, { - ViewName: "merging", + ViewName: "mergeConflicts", Key: opts.GetKey(opts.Config.Universal.ScrollRight), Handler: self.scrollRightMain, Description: self.c.Tr.LcScrollRight, Tag: "navigation", }, { - ViewName: "merging", + ViewName: "mergeConflicts", Key: opts.GetKey(opts.Config.Universal.Return), Handler: self.handleEscapeMerge, Description: self.c.Tr.ReturnToFilesPanel, }, { - ViewName: "merging", + ViewName: "mergeConflicts", Key: opts.GetKey(opts.Config.Files.OpenMergeTool), Handler: self.helpers.WorkingTree.OpenMergeTool, Description: self.c.Tr.LcOpenMergeTool, }, { - ViewName: "merging", + ViewName: "mergeConflicts", Key: opts.GetKey(opts.Config.Universal.Select), Handler: self.handlePickHunk, Description: self.c.Tr.PickHunk, }, { - ViewName: "merging", + ViewName: "mergeConflicts", Key: opts.GetKey(opts.Config.Main.PickBothHunks), Handler: self.handlePickAllHunks, Description: self.c.Tr.PickAllHunks, }, { - ViewName: "merging", + ViewName: "mergeConflicts", Key: opts.GetKey(opts.Config.Universal.PrevBlock), Handler: self.handleSelectPrevConflict, Description: self.c.Tr.PrevConflict, }, { - ViewName: "merging", + ViewName: "mergeConflicts", Key: opts.GetKey(opts.Config.Universal.NextBlock), Handler: self.handleSelectNextConflict, Description: self.c.Tr.NextConflict, }, { - ViewName: "merging", + ViewName: "mergeConflicts", Key: opts.GetKey(opts.Config.Universal.PrevItem), Handler: self.handleSelectPrevConflictHunk, Description: self.c.Tr.SelectPrevHunk, }, { - ViewName: "merging", + ViewName: "mergeConflicts", Key: opts.GetKey(opts.Config.Universal.NextItem), Handler: self.handleSelectNextConflictHunk, Description: self.c.Tr.SelectNextHunk, }, { - ViewName: "merging", + ViewName: "mergeConflicts", Key: opts.GetKey(opts.Config.Universal.PrevBlockAlt), Modifier: gocui.ModNone, Handler: self.handleSelectPrevConflict, }, { - ViewName: "merging", + ViewName: "mergeConflicts", Key: opts.GetKey(opts.Config.Universal.NextBlockAlt), Modifier: gocui.ModNone, Handler: self.handleSelectNextConflict, }, { - ViewName: "merging", + ViewName: "mergeConflicts", Key: opts.GetKey(opts.Config.Universal.PrevItemAlt), Modifier: gocui.ModNone, Handler: self.handleSelectPrevConflictHunk, }, { - ViewName: "merging", + ViewName: "mergeConflicts", Key: opts.GetKey(opts.Config.Universal.NextItemAlt), Modifier: gocui.ModNone, Handler: self.handleSelectNextConflictHunk, }, { - ViewName: "merging", + ViewName: "mergeConflicts", Key: opts.GetKey(opts.Config.Universal.Edit), Handler: self.handleMergeConflictEditFileAtLine, Description: self.c.Tr.LcEditFile, }, { - ViewName: "merging", + ViewName: "mergeConflicts", Key: opts.GetKey(opts.Config.Universal.OpenFile), Handler: self.handleMergeConflictOpenFileAtLine, Description: self.c.Tr.LcOpenFile, }, { - ViewName: "merging", + ViewName: "mergeConflicts", Key: opts.GetKey(opts.Config.Universal.Undo), Handler: self.handleMergeConflictUndo, Description: self.c.Tr.LcUndo, diff --git a/pkg/gui/main_panels.go b/pkg/gui/main_panels.go index ea9bfc3b3..f26ba42fd 100644 --- a/pkg/gui/main_panels.go +++ b/pkg/gui/main_panels.go @@ -144,7 +144,7 @@ func (gui *Gui) patchBuildingMainContextPair() MainContextPair { func (gui *Gui) mergingMainContextPair() MainContextPair { return MainContextPair{ - main: gui.State.Contexts.Merging, + main: gui.State.Contexts.MergeConflicts, secondary: nil, } } diff --git a/pkg/gui/merge_panel.go b/pkg/gui/merge_panel.go index f89697be6..a5733e43f 100644 --- a/pkg/gui/merge_panel.go +++ b/pkg/gui/merge_panel.go @@ -14,38 +14,38 @@ import ( func (gui *Gui) handleSelectPrevConflictHunk() error { return gui.withMergeConflictLock(func() error { - gui.takeOverMergeConflictScrolling() - gui.State.Panels.Merging.SelectPrevConflictHunk() + gui.State.Contexts.MergeConflicts.SetUserScrolling(false) + gui.State.Contexts.MergeConflicts.State().SelectPrevConflictHunk() return gui.renderConflictsWithFocus() }) } func (gui *Gui) handleSelectNextConflictHunk() error { return gui.withMergeConflictLock(func() error { - gui.takeOverMergeConflictScrolling() - gui.State.Panels.Merging.SelectNextConflictHunk() + gui.State.Contexts.MergeConflicts.SetUserScrolling(false) + gui.State.Contexts.MergeConflicts.State().SelectNextConflictHunk() return gui.renderConflictsWithFocus() }) } func (gui *Gui) handleSelectNextConflict() error { return gui.withMergeConflictLock(func() error { - gui.takeOverMergeConflictScrolling() - gui.State.Panels.Merging.SelectNextConflict() + gui.State.Contexts.MergeConflicts.SetUserScrolling(false) + gui.State.Contexts.MergeConflicts.State().SelectNextConflict() return gui.renderConflictsWithFocus() }) } func (gui *Gui) handleSelectPrevConflict() error { return gui.withMergeConflictLock(func() error { - gui.takeOverMergeConflictScrolling() - gui.State.Panels.Merging.SelectPrevConflict() + gui.State.Contexts.MergeConflicts.SetUserScrolling(false) + gui.State.Contexts.MergeConflicts.State().SelectPrevConflict() return gui.renderConflictsWithFocus() }) } func (gui *Gui) handleMergeConflictUndo() error { - state := gui.State.Panels.Merging + state := gui.State.Contexts.MergeConflicts.State() ok := state.Undo() if !ok { @@ -63,7 +63,7 @@ func (gui *Gui) handleMergeConflictUndo() error { func (gui *Gui) handlePickHunk() error { return gui.withMergeConflictLock(func() error { - ok, err := gui.resolveConflict(gui.State.Panels.Merging.Selection()) + ok, err := gui.resolveConflict(gui.State.Contexts.MergeConflicts.State().Selection()) if err != nil { return err } @@ -72,7 +72,7 @@ func (gui *Gui) handlePickHunk() error { return nil } - if gui.State.Panels.Merging.AllConflictsResolved() { + if gui.State.Contexts.MergeConflicts.State().AllConflictsResolved() { return gui.onLastConflictResolved() } @@ -91,7 +91,7 @@ func (gui *Gui) handlePickAllHunks() error { return nil } - if gui.State.Panels.Merging.AllConflictsResolved() { + if gui.State.Contexts.MergeConflicts.State().AllConflictsResolved() { return gui.onLastConflictResolved() } @@ -100,9 +100,9 @@ func (gui *Gui) handlePickAllHunks() error { } func (gui *Gui) resolveConflict(selection mergeconflicts.Selection) (bool, error) { - gui.takeOverMergeConflictScrolling() + gui.State.Contexts.MergeConflicts.SetUserScrolling(false) - state := gui.State.Panels.Merging + state := gui.State.Contexts.MergeConflicts.State() ok, content, err := state.ContentAfterConflictResolve(selection) if err != nil { @@ -132,21 +132,21 @@ func (gui *Gui) resolveConflict(selection mergeconflicts.Selection) (bool, error // precondition: we actually have conflicts to render func (gui *Gui) renderConflicts(hasFocus bool) error { - state := gui.State.Panels.Merging.State + state := gui.State.Contexts.MergeConflicts.State() content := mergeconflicts.ColoredConflictFile(state, hasFocus) - if !gui.State.Panels.Merging.UserVerticalScrolling { + if !gui.State.Contexts.MergeConflicts.IsUserScrolling() { // TODO: find a way to not have to do this OnUIThread thing. Why doesn't it work // without it given that we're calling the 'no scroll' variant below? - gui.OnUIThread(func() error { - gui.State.Panels.Merging.Lock() - defer gui.State.Panels.Merging.Unlock() + gui.c.OnUIThread(func() error { + gui.State.Contexts.MergeConflicts.State().Lock() + defer gui.State.Contexts.MergeConflicts.State().Unlock() if !state.Active() { return nil } - gui.centerYPos(gui.Views.Merging, state.GetConflictMiddle()) + gui.centerYPos(gui.Views.MergeConflicts, state.GetConflictMiddle()) return nil }) } @@ -203,8 +203,8 @@ func (gui *Gui) onLastConflictResolved() error { } func (gui *Gui) resetMergeState() { - gui.takeOverMergeConflictScrolling() - gui.State.Panels.Merging.Reset() + gui.State.Contexts.MergeConflicts.SetUserScrolling(false) + gui.State.Contexts.MergeConflicts.State().Reset() } func (gui *Gui) setMergeState(path string) (bool, error) { @@ -213,21 +213,21 @@ func (gui *Gui) setMergeState(path string) (bool, error) { return false, err } - gui.State.Panels.Merging.SetContent(content, path) + gui.State.Contexts.MergeConflicts.State().SetContent(content, path) - return !gui.State.Panels.Merging.NoConflicts(), nil + return !gui.State.Contexts.MergeConflicts.State().NoConflicts(), nil } func (gui *Gui) setMergeStateWithLock(path string) (bool, error) { - gui.State.Panels.Merging.Lock() - defer gui.State.Panels.Merging.Unlock() + gui.State.Contexts.MergeConflicts.State().Lock() + defer gui.State.Contexts.MergeConflicts.State().Unlock() return gui.setMergeState(path) } func (gui *Gui) resetMergeStateWithLock() { - gui.State.Panels.Merging.Lock() - defer gui.State.Panels.Merging.Unlock() + gui.State.Contexts.MergeConflicts.State().Lock() + defer gui.State.Contexts.MergeConflicts.State().Unlock() gui.resetMergeState() } @@ -244,24 +244,20 @@ func (gui *Gui) escapeMerge() error { func (gui *Gui) renderingConflicts() bool { currentView := gui.g.CurrentView() - if currentView != gui.Views.Merging && currentView != gui.Views.Files { + if currentView != gui.Views.MergeConflicts && currentView != gui.Views.Files { return false } - return gui.State.Panels.Merging.Active() + return gui.State.Contexts.MergeConflicts.State().Active() } func (gui *Gui) withMergeConflictLock(f func() error) error { - gui.State.Panels.Merging.Lock() - defer gui.State.Panels.Merging.Unlock() + gui.State.Contexts.MergeConflicts.State().Lock() + defer gui.State.Contexts.MergeConflicts.State().Unlock() return f() } -func (gui *Gui) takeOverMergeConflictScrolling() { - gui.State.Panels.Merging.UserVerticalScrolling = false -} - func (gui *Gui) setConflictsAndRender(path string, hasFocus bool) (bool, error) { hasConflicts, err := gui.setMergeState(path) if err != nil { @@ -276,16 +272,16 @@ func (gui *Gui) setConflictsAndRender(path string, hasFocus bool) (bool, error) } func (gui *Gui) setConflictsAndRenderWithLock(path string, hasFocus bool) (bool, error) { - gui.State.Panels.Merging.Lock() - defer gui.State.Panels.Merging.Unlock() + gui.State.Contexts.MergeConflicts.State().Lock() + defer gui.State.Contexts.MergeConflicts.State().Unlock() return gui.setConflictsAndRender(path, hasFocus) } func (gui *Gui) switchToMerge(path string) error { - gui.takeOverMergeConflictScrolling() + gui.State.Contexts.MergeConflicts.SetUserScrolling(false) - if gui.State.Panels.Merging.GetPath() != path { + if gui.State.Contexts.MergeConflicts.State().GetPath() != path { hasConflicts, err := gui.setMergeStateWithLock(path) if err != nil { return err @@ -295,7 +291,7 @@ func (gui *Gui) switchToMerge(path string) error { } } - return gui.c.PushContext(gui.State.Contexts.Merging) + return gui.c.PushContext(gui.State.Contexts.MergeConflicts) |