summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyooooooga <eial5q265e5@gmail.com>2021-08-23 18:28:20 +0900
committerJesse Duffield <jessedduffield@gmail.com>2021-08-25 22:23:55 +1000
commitcf8ded0b7994dd1775511d75dcc93779f38d2ba7 (patch)
treebb6e363a29472864b58ac81857ca4700300c42b6
parent73548fa15fe6f65b6a4c35c03402865145c0e107 (diff)
add mergeConflict#hasAncestor
-rw-r--r--pkg/gui/mergeconflicts/rendering.go4
-rw-r--r--pkg/gui/mergeconflicts/state.go10
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