Skip to content
This repository has been archived by the owner on Dec 7, 2018. It is now read-only.

Reverse diff opcode #17

Open
max13fr opened this issue Jun 9, 2014 · 2 comments
Open

Reverse diff opcode #17

max13fr opened this issue Jun 9, 2014 · 2 comments

Comments

@max13fr
Copy link

max13fr commented Jun 9, 2014

Hello, a very good feature would be to get reverse diff opcodes.
I would like to log all changes in my forum (on subject or responses). But I don't keep the old version, only the newer. So I would like to compute old versions from the last version, not the opposite.

I try to switch arguments when calling FineDiff::getDiffOpcodes($from, $to) :

$firstVersion = "Test 123 - Heloa";
$newVersion = "Test 124 - Hello";
$opdiff = FineDiff::getDiffOpcodes($newVersion, $firstVersion)

But when I display, the difference (FineDiff::renderDiffToHTMLFromOpcodes), the modification are reversed (ins & del). So I tried something like :

$result = FineDiff::renderDiffToHTMLFromOpcodes($text, $opdiff);
// Replace ins by del & del by ins
$result = strtr($result, array('<del>' => '<ins>', '</del>' => '</ins>', '<ins>' => '<del>', '</ins>' => '</del>'));
// Swap ins & del
$result = preg_replace('#(<ins>.+?</ins>)(\s*)(<del>.+?</del>)#s', '$3$2$1', $result);

But, it's very ugly...
Could you do function FineDiff::getReverseDiffOpcodes for this case?

Thanks in advance,
Best Regards, Max

@gorhill
Copy link
Owner

gorhill commented Jun 9, 2014

Why not just CSS-restyle <ins> and <del> to each other style? The <ins> and <del> are semantically correct even when you "reverse" the diff, you just want a different visual it seems.

@asleepwalker
Copy link

https://gist.github.com/asleepwalker/fb46883e88a3a44af786
Maybe it will be helpful for someone.

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

No branches or pull requests

3 participants