From cf8ded0b7994dd1775511d75dcc93779f38d2ba7 Mon Sep 17 00:00:00 2001 From: Ryooooooga Date: Mon, 23 Aug 2021 18:28:20 +0900 Subject: [PATCH] add mergeConflict#hasAncestor --- pkg/gui/mergeconflicts/rendering.go | 4 ++-- pkg/gui/mergeconflicts/state.go | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/gui/mergeconflicts/rendering.go b/pkg/gui/mergeconflicts/rendering.go index 8255b6ce9..8f7fa3165 100644 --- a/pkg/gui/mergeconflicts/rendering.go +++ b/pkg/gui/mergeconflicts/rendering.go @@ -20,7 +20,7 @@ func ColoredConflictFile(content string, state *State, hasFocus bool) string { 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() } 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 { switch selection { case TOP: - if conflict.ancestor >= 0 { + if conflict.hasAncestor() { return index >= conflict.start && index <= conflict.ancestor } else { return index >= conflict.start && index <= conflict.target diff --git a/pkg/gui/mergeconflicts/state.go b/pkg/gui/mergeconflicts/state.go index 1eea08cb0..341a53e6a 100644 --- a/pkg/gui/mergeconflicts/state.go +++ b/pkg/gui/mergeconflicts/state.go @@ -25,6 +25,10 @@ type mergeConflict struct { end int } +func (c *mergeConflict) hasAncestor() bool { + return c.ancestor >= 0 +} + type State struct { sync.Mutex conflictIndex int @@ -48,7 +52,7 @@ func (s *State) SelectPrevConflictHunk() { case MIDDLE: s.conflictSelection = TOP case BOTTOM: - if s.currentConflict().ancestor >= 0 { + if s.currentConflict().hasAncestor() { s.conflictSelection = MIDDLE } else { s.conflictSelection = TOP @@ -59,7 +63,7 @@ func (s *State) SelectPrevConflictHunk() { func (s *State) SelectNextConflictHunk() { switch s.conflictSelection { case TOP: - if s.currentConflict().ancestor >= 0 { + if s.currentConflict().hasAncestor() { s.conflictSelection = MIDDLE } else { s.conflictSelection = BOTTOM @@ -163,7 +167,7 @@ func isIndexToDelete(i int, conflict *mergeConflict, selection Selection) bool { var isWantedContent bool switch selection { case TOP: - if conflict.ancestor >= 0 { + if conflict.hasAncestor() { isWantedContent = conflict.start < i && i < conflict.ancestor } else { isWantedContent = conflict.start < i && i < conflict.target