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

Combined vs SideBySide #85

Open
stekky81 opened this issue Jul 2, 2024 · 1 comment
Open

Combined vs SideBySide #85

stekky81 opened this issue Jul 2, 2024 · 1 comment
Labels
question Just asking some questions

Comments

@stekky81
Copy link

stekky81 commented Jul 2, 2024

Hi, first of all thanks for the great library, I'm finding strange differences in some paragraphs between SideBySide mode and Combined mode. Given that I am using the same configuration parameters, in Combined mode the texts are aligned in the correct way ('detailLevel' => 'word'); while in SideBySide mode no. The strange thing is that this only happens in some blocks of lines (like the one in the example below), while in others it works correctly.
The problem can be seen clearly in the third to last and penultimate lines which are not even placed side by side; however, more generally, in the rest of the paragraph the words that differ are not marked.
I'm using the last version of the library.

Screenshot 2024-07-03 at 00-32-54 Dan 001 - Dan 002

// options
$diffOptions = [
    'context' => 1,
    'ignoreCase' => true,
    'ignoreLineEnding' => true,
    'ignoreWhitespace' => true,
    'lengthLimit' => 2000,
    'fullContextIfIdentical' => true,
];

$rendererOptions = [
    'detailLevel' => 'word',
    'language' => 'eng',
    'lineNumbers' => false,
    'separateBlock' => true,
    'showHeader' => false,
    'spaceToHtmlTag' => false,
    'spacesToNbsp' => false,
    'tabSize' => 4,
    'mergeThreshold' => 0.8,
    'cliColorization' => RendererConstant::CLI_COLOR_AUTO,
    'outputTagAsString' => false,
    'jsonEncodeFlags' => \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE,
    'wordGlues' => [' ', '-'],
    'resultForIdenticals' => null,
    'wrapperClasses' => ['diff-wrapper'],
];

== Text 1 ==
Reduc’d vnto th’extreameſt miſery.
Am I the woman, whoſe inuentiue pride,
(Adorn’d like Isis,) ſcornd mortalitie?
Iſt I that left my ſence ſo without guide,
That flattery would not let him know twas I?
Ah, now I ſee, they ſcarce tell truth, that praiſe vs,
Crownes are beguild, proſperity betraies vs.
What is become of all that ſtatelie traine,
Thoſe troopes that wont attend proſperitie?
See what is left, what number doth remaine,
A tombe, two maydes, and miſerable I.
And I t’adorne their tryumphes, am reſeru’d
A captiue kept to beautifie their ſpoyles:
Whom Cæſar labours, ſo to haue preſeru’d,
And ſeekes to entertaine my life with wiles.

== Text 2 ==
Reduc’d vnto th’extreameſt miſerie?
Am I the woman whoſe inuentiue pride,
Adorn’d like Iſis, skornd mortalitie?
Is’t I would haue my frailty ſo belide
That flattery could perſwade I was not I?
Well now I ſee they but delude that praiſe vs,
Greatneſſe is mockt, proſperity betraies vs.
And we are but our ſelues, although this clowd
Of interpoſed ſmokes make vs ſeeme more:
Witneſſe theſe gallant fortune-followng traines,
Theſe Summer Swallowes of felicitie
Gone with the heate, of all see what remaines,
This monument, two maydes, and wretched I.
And I t’adorne their triumphs, am reſeru’d
A captiue kept to honor others ſpoyles,
Whom Cæſar labors ſo to haue preſeru’d,
And ſeekes to entertaine my life with wiles.

@jfcherng
Copy link
Owner

jfcherng commented Jul 3, 2024

The detailed renderer (word) only works when a hunk's old/new lines counts are the same. And then it calculates detailed diff by assuming the N-th line in the old hunk maps to the N-th line in the new hunk.

// if there are same amount of lines replaced
// we can render the inner detailed changes with corresponding lines
// @todo or use LineRenderer to do the job regardless different line counts?
if ($op === SequenceMatcher::OP_REP && $i2 - $i1 === $j2 - $j1) {
for ($k = $i2 - $i1 - 1; $k >= 0; --$k) {
$this->renderChangedExtent($lineRenderer, $old[$i1 + $k], $new[$j1 + $k]);
}
}


In your case, the new hunk has 2 more lines than the old one has. So currently, this is the expected behavior.

@jfcherng jfcherng added the question Just asking some questions label Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Just asking some questions
Projects
None yet
Development

No branches or pull requests

2 participants