mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-11-02 08:59:57 -06:00
Route the editing of a diff's files through DiffHelper
Three places open a file of a diff in the editor: `e` and alt-click in the main view, the lazygit-edit:// hyperlinks of a diff renderer, and `e` in the commit files panel. The first two also each carry a line of the diff forward to the file's current line before opening it. Give them one pair of methods to call. The next commit changes where these files are opened from, and can then do so in one place. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
283bd590f3
commit
64fd7d8686
5 files changed
+25
-12
No files matched your search
@@ -16,12 +16,14 @@ import (
|
||||
type DiffHelper struct {
|
||||
c *HelperCommon
|
||||
diffLineHelper *DiffLineHelper
|
||||
filesHelper *FilesHelper
|
||||
}
|
||||
|
||||
func NewDiffHelper(c *HelperCommon, diffLineHelper *DiffLineHelper) *DiffHelper {
|
||||
func NewDiffHelper(c *HelperCommon, diffLineHelper *DiffLineHelper, filesHelper *FilesHelper) *DiffHelper {
|
||||
return &DiffHelper{
|
||||
c: c,
|
||||
diffLineHelper: diffLineHelper,
|
||||
filesHelper: filesHelper,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,6 +226,20 @@ func (self *DiffHelper) OpenDiffToolForRef(selectedRef models.Ref) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// EditFilesOfDiff opens files of the diff that the current side panel shows in the
|
||||
// editor.
|
||||
func (self *DiffHelper) EditFilesOfDiff(paths []string) error {
|
||||
return self.filesHelper.EditFiles(paths)
|
||||
}
|
||||
|
||||
// EditFileOfDiffAtLine opens a file of the diff shown in the given view in the editor,
|
||||
// at a line of that diff. The line is carried forward to where it is in the file now
|
||||
// (see AdjustLineNumber).
|
||||
func (self *DiffHelper) EditFileOfDiffAtLine(path string, lineNumber int, viewName string) error {
|
||||
lineNumber = self.AdjustLineNumber(path, lineNumber, viewName)
|
||||
return self.filesHelper.EditFileAtLine(path, lineNumber)
|
||||
}
|
||||
|
||||
// AdjustLineNumber is used to adjust a line number in the diff that's currently
|
||||
// being viewed, so that it corresponds to the line number in the actual working
|
||||
// copy state of the file. It is used when clicking on a delta hyperlink in a
|
||||
|
||||
Reference in new issue
Block a user