Skip to content

Collapsed block not shown at start of end of text. #24

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

Closed
DigiLive opened this issue Jan 28, 2020 · 7 comments
Closed

Collapsed block not shown at start of end of text. #24

DigiLive opened this issue Jan 28, 2020 · 7 comments
Assignees

Comments

@DigiLive
Copy link
Collaborator

As mentioned here...
A block that would normally collapse, but its position is at the start or end of the text, will not be shown as collapsed. Those lines are NOT rendered at all.

An indication for the block being collapsed from the start/to the end of the text should be visible or these blocks shouldn't be collapsed at all.
E.g.

LineNo LineContent
bof
... ...
10 Hello World!
... ...
eof
@DigiLive
Copy link
Collaborator Author

The sequenceMatchter is responsible for removing the blocks at the start and end of the text.

Line 554 > 562 removes the sequences at the start.

if ($opCodes['0']['0'] == 'equal') {
    $opCodes['0'] = array(
        $opCodes['0']['0'],
        max($opCodes['0']['1'], $opCodes['0']['2'] - $context),
        $opCodes['0']['2'],
        max($opCodes['0']['3'], $opCodes['0']['4'] - $context),
         $opCodes['0']['4']
    );
}

Line 564 > 574 removes the sequences at the end...

$lastItem = count($opCodes) - 1;
if ($opCodes[$lastItem]['0'] == 'equal') {
    list($tag, $i1, $i2, $j1, $j2) = $opCodes[$lastItem];
    $opCodes[$lastItem] = array(
        $tag,
        $i1,
        min($i2, $i1 + $context),
        $j1,
        min($j2, $j1 + $context)
    );
}

in combination with line 604 > 606.

if (!empty($group) && !(count($group) == 1 && $group[0][0] == 'equal')) {
    $groups[] = $group;
}

In order to show collapsed blocks at the start and end, the first 2 blocks of code should not be executed and the code at line 605 should.
Preferably (by me) create new option like trimEqual which strips equal blocks of text from the beginning and end.
TrimEqualFalse
TrimEqualTrue

@JBlond
Copy link
Owner

JBlond commented Jan 31, 2020

The original diff on a command line diff -u a.txt b.txt looks almost the same like now the sequence matcher. So I like your idea of having trimEqual as an option.

@DigiLive DigiLive self-assigned this Jan 31, 2020
@DigiLive
Copy link
Collaborator Author

Ok.
I will implement it as an option.

I've researched a lot of code, but many code still remains Hocus pocus. 😅
Therefor I suggest testing it well before making a new release.

I'll also re-add the long Chinese line to the same commit.

@DigiLive
Copy link
Collaborator Author

DigiLive commented Feb 1, 2020

Commit 98d993e also has some test added for sequenceMatcher::getGroupedOpcodes() to test the output with different options set.

@DigiLive
Copy link
Collaborator Author

@JBlond Any chance to test the collapsing feature yet?

@DigiLive DigiLive assigned JBlond and unassigned DigiLive Feb 27, 2020
@JBlond
Copy link
Owner

JBlond commented Feb 27, 2020

Yepp, for me it works great.

@JBlond
Copy link
Owner

JBlond commented Feb 27, 2020

@DigiLive If you are fine with all your changes open another pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants