diff options
author | Ryooooooga <eial5q265e5@gmail.com> | 2021-08-03 21:38:03 +0900 |
---|---|---|
committer | Ryooooooga <eial5q265e5@gmail.com> | 2021-08-03 21:42:14 +0900 |
commit | 4f66093335e5a0d370cf43b3fc637c0795376334 (patch) | |
tree | 0f71e0ee748ff19133f5545492a4ddeb7f5f35b7 /pkg/gui | |
parent | d626bcac0029267d3f45223198902f5cb78d9dc1 (diff) |
introduce edit command template to open a specifig line of a file
Diffstat (limited to 'pkg/gui')
-rw-r--r-- | pkg/gui/files_panel.go | 8 | ||||
-rw-r--r-- | pkg/gui/keybindings.go | 2 | ||||
-rw-r--r-- | pkg/gui/line_by_line_panel.go | 11 |
3 files changed, 18 insertions, 3 deletions
diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index 48c0621cb..f652c3f05 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -474,13 +474,17 @@ func (gui *Gui) handleCommitEditorPress() error { } func (gui *Gui) editFile(filename string) error { - cmdStr, err := gui.GitCommand.EditFileCmdStr(filename) + return gui.editFileAtLine(filename, 1) +} + +func (gui *Gui) editFileAtLine(filename string, lineNumber int) error { + cmdStr, err := gui.GitCommand.EditFileCmdStr(filename, lineNumber) if err != nil { return gui.surfaceError(err) } return gui.runSubprocessWithSuspenseAndRefresh( - gui.OSCommand.WithSpan(gui.Tr.Spans.EditFile).PrepareShellSubProcess(cmdStr), + gui.OSCommand.WithSpan(gui.Tr.Spans.EditFile).ShellCommandFromString(cmdStr), ) } diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index f9537e755..4b20bab95 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -1301,7 +1301,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding { ViewName: "main", Contexts: []string{string(MAIN_STAGING_CONTEXT_KEY)}, Key: gui.getKey(config.Universal.Edit), - Handler: gui.handleFileEdit, + Handler: gui.handleLineByLineEdit, Description: gui.Tr.LcEditFile, }, { diff --git a/pkg/gui/line_by_line_panel.go b/pkg/gui/line_by_line_panel.go index d7a5380b2..7171864f4 100644 --- a/pkg/gui/line_by_line_panel.go +++ b/pkg/gui/line_by_line_panel.go @@ -272,3 +272,14 @@ func (gui *Gui) withLBLActiveCheck(f func(*LblPanelState) error) error { return f(state) } + +func (gui *Gui) handleLineByLineEdit() error { + file := gui.getSelectedFile() + if file == nil { + return nil + } + + lineNumber := gui.State.Panels.LineByLine.CurrentLineNumber() + + return gui.editFileAtLine(file.Name, lineNumber) +} |