Menu

#102 Context Lines Display Discrepancy

v4.4.5
closed
v4.4.7 (10)
4
2019-04-05
2017-08-20
linknet
No

There is a slight error with the number of preceding context lines shown and with the inclusion of the blank line between matches:

Grep.cs
SearchFileContents(FileInfo file)

// this line
if (match.Matches.Count > 0 && _lastHit < -_maxContextLines)
// should be
if (match.Matches.Count > 0 && _lastHit <= -_maxContextLines)

// and this line
if(_lastHit >= -_maxContextLines)
// should be
if (_lastHit > -_maxContextLines)

This gives the following:

 // Display context lines if applicable.
 if (SearchSpec.ContextLines > 0 && _lastHit <= 0)
 {
    if (match.Matches.Count > 0 && _lastHit <= -_maxContextLines)
    {
       // Insert a blank space before the context lines.
       var matchLine = new MatchResultLine() { Line = string.Empty, LineNumber = -1 };

       match.Matches.Add(matchLine);
       int _pos = match.Matches.Count - 1;

       if (DoesPassHitCountCheck(match))
       {
          OnLineHit(match, _pos);
       }
    }

    // Display preceding n context lines before the hit.
    int tempContextLines = SearchSpec.ContextLines;

    // But only output the context lines which are not part of the previous context
    if (_lastHit > -_maxContextLines)
    {
       tempContextLines = -_lastHit;
    }

This text file allows this to be tested by searching for "aa" and checking the context lines and spaces displayed for various values of "Context Lines".

1 Attachments

Discussion

  • Jackslade

    Jackslade - 2017-08-21

    Thanks, will take a look at verifying and fixing this with your changes.

     
  • Jackslade

    Jackslade - 2017-08-21
    • status: open --> accepted
    • assigned_to: Jackslade
    • Priority: 1 --> 4
     
  • Jackslade

    Jackslade - 2019-04-05
    • Labels: --> v4.4.7
    • Status: accepted --> closed
     

Anonymous
Anonymous

Add attachments
Cancel





MongoDB Logo MongoDB