MCPcopy Index your code
hub / github.com/jesseduffield/lazygit / AdjustLineNumber

Method AdjustLineNumber

pkg/commands/patch/patch.go:183–198  ·  view source on GitHub ↗

Adjust the given line number (one-based) according to the current patch. The patch is supposed to be a diff of an old file state against the working directory; the line number is a line number in that old file, and the function returns the corresponding line number in the working directory file.

(lineNumber int)

Source from the content-addressed store, hash-verified

181// directory; the line number is a line number in that old file, and the
182// function returns the corresponding line number in the working directory file.
183func (self *Patch) AdjustLineNumber(lineNumber int) int {
184 adjustedLineNumber := lineNumber
185 for _, hunk := range self.hunks {
186 if hunk.oldStart >= lineNumber {
187 break
188 }
189
190 if hunk.oldStart+hunk.oldLength() > lineNumber {
191 return hunk.newStart
192 }
193
194 adjustedLineNumber += hunk.newLength() - hunk.oldLength()
195 }
196
197 return adjustedLineNumber
198}
199
200func (self *Patch) IsSingleHunkForWholeFile() bool {
201 if len(self.hunks) != 1 {

Callers 1

TestAdjustLineNumberFunction · 0.45

Calls 2

oldLengthMethod · 0.80
newLengthMethod · 0.80

Tested by 1

TestAdjustLineNumberFunction · 0.36