summaryrefslogtreecommitdiffstats
path: root/pkg/gui
diff options
context:
space:
mode:
authorRyooooooga <eial5q265e5@gmail.com>2022-04-04 21:12:33 +0900
committerJesse Duffield <jessedduffield@gmail.com>2022-04-06 08:27:03 +1000
commit3b5a019e1a33bbb9b331d44956f98b2b8c4cd5a9 (patch)
tree8b4c129d57124441edee6a1d7d6734796498d1b6 /pkg/gui
parent53257db99d10bd533c134714b76965041c56cd19 (diff)
feat(merge_panel): Add open/edit files in merge conflict panel
Diffstat (limited to 'pkg/gui')
-rw-r--r--pkg/gui/keybindings.go14
-rw-r--r--pkg/gui/merge_panel.go20
-rw-r--r--pkg/gui/mergeconflicts/state.go10
3 files changed, 44 insertions, 0 deletions
diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go
index 7a2d5f757..8598502ef 100644
--- a/pkg/gui/keybindings.go
+++ b/pkg/gui/keybindings.go
@@ -674,6 +674,20 @@ func (self *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBi
{
ViewName: "main",
Contexts: []string{string(context.MAIN_MERGING_CONTEXT_KEY)},
+ Key: opts.GetKey(opts.Config.Universal.Edit),
+ Handler: self.handleMergeConflictEditFileAtLine,
+ Description: self.c.Tr.LcEditFile,
+ },
+ {
+ ViewName: "main",
+ Contexts: []string{string(context.MAIN_MERGING_CONTEXT_KEY)},
+ Key: opts.GetKey(opts.Config.Universal.OpenFile),
+ Handler: self.handleMergeConflictOpenFileAtLine,
+ Description: self.c.Tr.LcOpenFile,
+ },
+ {
+ ViewName: "main",
+ Contexts: []string{string(context.MAIN_MERGING_CONTEXT_KEY)},
Key: opts.GetKey(opts.Config.Universal.Undo),
Handler: self.handleMergeConflictUndo,
Description: self.c.Tr.LcUndo,
diff --git a/pkg/gui/merge_panel.go b/pkg/gui/merge_panel.go
index b9a00eaa2..4d9c7304b 100644
--- a/pkg/gui/merge_panel.go
+++ b/pkg/gui/merge_panel.go
@@ -299,3 +299,23 @@ func (gui *Gui) switchToMerge(path string) error {
return gui.c.PushContext(gui.State.Contexts.Merging)
}
+
+func (gui *Gui) handleMergeConflictEditFileAtLine() error {
+ file := gui.getSelectedFile()
+ if file == nil {
+ return nil
+ }
+
+ lineNumber := gui.State.Panels.Merging.GetSelectedLine()
+ return gui.helpers.Files.EditFileAtLine(file.GetPath(), lineNumber)
+}
+
+func (gui *Gui) handleMergeConflictOpenFileAtLine() error {
+ file := gui.getSelectedFile()
+ if file == nil {
+ return nil
+ }
+
+ lineNumber := gui.State.Panels.Merging.GetSelectedLine()
+ return gui.helpers.Files.OpenFileAtLine(file.GetPath(), lineNumber)
+}
diff --git a/pkg/gui/mergeconflicts/state.go b/pkg/gui/mergeconflicts/state.go
index 3d0254e15..41a072617 100644
--- a/pkg/gui/mergeconflicts/state.go
+++ b/pkg/gui/mergeconflicts/state.go
@@ -182,3 +182,13 @@ func (s *State) ContentAfterConflictResolve(selection Selection) (bool, string,
return true, content, nil
}
+
+func (s *State) GetSelectedLine() int {
+ conflict := s.currentConflict()
+ if conflict == nil {
+ return 1
+ }
+ selection := s.Selection()
+ startIndex, _ := selection.bounds(conflict)
+ return startIndex + 1
+}