Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve conflict highlighting #65

Closed
walles opened this issue May 19, 2024 · 0 comments
Closed

Improve conflict highlighting #65

walles opened this issue May 19, 2024 · 0 comments

Comments

@walles
Copy link
Owner

walles commented May 19, 2024

In the following conflict diff, the last section starting with ++// NOTE: When we search [...] should be colored as the context lines.

diff --cc m/search.go
index 5b67346,e5b580f..0000000
--- m/search.go
+++ m/search.go
@@@ -10,45 -6,9 +10,79 @@@ import 
  	"github.com/walles/moar/m/linenumbers"
  )
  
++<<<<<<< HEAD
 +func (p *Pager) scrollToSearchHits() {
 +	if p.searchPattern == nil {
 +		// This is not a search
 +		return
 +	}
 +
 +	lineNumber := p.scrollPosition.lineNumber(p)
 +	if lineNumber == nil {
 +		// No lines to search
 +		return
 +	}
 +
 +	firstHitPosition := p.findFirstHit(*lineNumber, nil, false)
 +	if firstHitPosition == nil && (*lineNumber != linenumbers.LineNumber{}) {
 +		// Try again from the top
 +		firstHitPosition = p.findFirstHit(linenumbers.LineNumber{}, lineNumber, false)
 +	}
 +	if firstHitPosition == nil {
 +		// No match, give up
 +		return
 +	}
 +
 +	if firstHitPosition.isVisible(p) {
 +		// Already on-screen, never mind
 +		return
 +	}
 +
 +	p.scrollPosition = *firstHitPosition
 +}
 +
 +// NOTE: When we search, we do that by looping over the *input lines*, not the
 +// screen lines. That's why startPosition is a LineNumber rather than a
 +// scrollPosition.
 +//
 +// The `beforePosition` parameter is exclusive, meaning that line will not be
 +// searched.
 +//
 +// For the actual searching, this method will call _findFirstHit() in parallel
 +// on multiple cores, to help large file search performance.
++||||||| parent of b835e9a (Fix the warnings)
++func (p *Pager) scrollToSearchHits() {
++	if p.searchPattern == nil {
++		// This is not a search
++		return
++	}
++
++	firstHitPosition := p.findFirstHit(*p.scrollPosition.lineNumber(p), nil, false)
++	if firstHitPosition == nil {
++		// Try again from the top
++		firstHitPosition = p.findFirstHit(linenumbers.LineNumber{}, p.scrollPosition.lineNumber(p), false)
++	}
++	if firstHitPosition == nil {
++		// No match, give up
++		return
++	}
++
++	if firstHitPosition.isVisible(p) {
++		// Already on-screen, never mind
++		return
++	}
++
++	p.scrollPosition = *firstHitPosition
++}
++
+ // NOTE: When we search, we do that by looping over the *input lines*, not
+ // the screen lines. That's why we're using a line number rather than a
+ // scrollPosition for searching.
++=======
++// NOTE: When we search, we do that by looping over the *input lines*, not
++// the screen lines. That's why we're using a line number rather than a
++// scrollPosition for searching.
++>>>>>>> b835e9a (Fix the warnings)
  //
  // FIXME: We should take startPosition.deltaScreenLines into account as well!
  func (p *Pager) findFirstHit(startPosition linenumbers.LineNumber, beforePosition *linenumbers.LineNumber, backwards bool) *scrollPosition {
@walles walles closed this as completed in e04ac0b May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant