1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-10 04:07:18 +02:00

add mergeConflict#hasAncestor

This commit is contained in:
Ryooooooga 2021-08-23 18:28:20 +09:00 committed by Jesse Duffield
parent 73548fa15f
commit cf8ded0b79
2 changed files with 9 additions and 5 deletions

View File

@ -20,7 +20,7 @@ func ColoredConflictFile(content string, state *State, hasFocus bool) string {
textStyle = style.FgRed textStyle = style.FgRed
} }
if hasFocus && state.conflictIndex < len(state.conflicts) && *state.conflicts[state.conflictIndex] == *conflict && shouldHighlightLine(i, conflict, state.conflictSelection) { if hasFocus && state.conflictIndex < len(state.conflicts) && *state.conflicts[state.conflictIndex] == *conflict && shouldHighlightLine(i, conflict, state.Selection()) {
textStyle = textStyle.MergeStyle(theme.SelectedRangeBgColor).SetBold() textStyle = textStyle.MergeStyle(theme.SelectedRangeBgColor).SetBold()
} }
if i == conflict.end && len(remainingConflicts) > 0 { if i == conflict.end && len(remainingConflicts) > 0 {
@ -38,7 +38,7 @@ func shiftConflict(conflicts []*mergeConflict) (*mergeConflict, []*mergeConflict
func shouldHighlightLine(index int, conflict *mergeConflict, selection Selection) bool { func shouldHighlightLine(index int, conflict *mergeConflict, selection Selection) bool {
switch selection { switch selection {
case TOP: case TOP:
if conflict.ancestor >= 0 { if conflict.hasAncestor() {
return index >= conflict.start && index <= conflict.ancestor return index >= conflict.start && index <= conflict.ancestor
} else { } else {
return index >= conflict.start && index <= conflict.target return index >= conflict.start && index <= conflict.target

View File

@ -25,6 +25,10 @@ type mergeConflict struct {
end int end int
} }
func (c *mergeConflict) hasAncestor() bool {
return c.ancestor >= 0
}
type State struct { type State struct {
sync.Mutex sync.Mutex
conflictIndex int conflictIndex int
@ -48,7 +52,7 @@ func (s *State) SelectPrevConflictHunk() {
case MIDDLE: case MIDDLE:
s.conflictSelection = TOP s.conflictSelection = TOP
case BOTTOM: case BOTTOM:
if s.currentConflict().ancestor >= 0 { if s.currentConflict().hasAncestor() {
s.conflictSelection = MIDDLE s.conflictSelection = MIDDLE
} else { } else {
s.conflictSelection = TOP s.conflictSelection = TOP
@ -59,7 +63,7 @@ func (s *State) SelectPrevConflictHunk() {
func (s *State) SelectNextConflictHunk() { func (s *State) SelectNextConflictHunk() {
switch s.conflictSelection { switch s.conflictSelection {
case TOP: case TOP:
if s.currentConflict().ancestor >= 0 { if s.currentConflict().hasAncestor() {
s.conflictSelection = MIDDLE s.conflictSelection = MIDDLE
} else { } else {
s.conflictSelection = BOTTOM s.conflictSelection = BOTTOM
@ -163,7 +167,7 @@ func isIndexToDelete(i int, conflict *mergeConflict, selection Selection) bool {
var isWantedContent bool var isWantedContent bool
switch selection { switch selection {
case TOP: case TOP:
if conflict.ancestor >= 0 { if conflict.hasAncestor() {
isWantedContent = conflict.start < i && i < conflict.ancestor isWantedContent = conflict.start < i && i < conflict.ancestor
} else { } else {
isWantedContent = conflict.start < i && i < conflict.target isWantedContent = conflict.start < i && i < conflict.target