jsondiffpatch icon indicating copy to clipboard operation
jsondiffpatch copied to clipboard

Context Lines

Open hungerburg opened this issue 8 years ago • 10 comments

How to get context lines in the visual html output? Rather than just line-number based, probably very nice was, to see the full object or parent node of where the change is…

Peter, with a big thank You for sharing!

hungerburg avatar Oct 04 '15 11:10 hungerburg

In my case, a css selector does it in full-data view: div > ul > li.jsondiffpatch-unchanged { display: none; } Anyhow, an option might be of use some times

hungerburg avatar Oct 04 '15 12:10 hungerburg

hi Peter, thanks for you feedback! I don't understand the proposal, the way it's done in the demo is as you mention, with the jsondiffpatch-unchanged class, that wraps all context (unchanged) data. can you provide an example of an expected behavior? cheers.

benjamine avatar Oct 04 '15 22:10 benjamine

@benjamine My proposal is based on the command-line (gnu) diff utility and the html example "visual diff" from readme.md: when I omit the "left" argument from format, I get only the changed lines, not the full data. This is too little to know, where the change happened. Command line diff (just like in git here) has a -c option to also print surrounding lines. Yet, it is just processing text and does not know about the structure. It is not very useful with json formatted objects.

The proposal also is based on my data: an object containing of objects with text properties. First level is an object because sequence does not matter and json seems to be like that; keys are random strings. The css above hides all unchanged top-level objects, a perfect fit in my case.

Probably, I imagined something lke --show-c-function in command-line diff, just smarter, and more verbose: show the whole function body, like that, the whole object, not just the line that changed. Hope that makes it more clear.

hungerburg avatar Oct 04 '15 22:10 hungerburg

ah, the command line, yes makes sense.

benjamine avatar Oct 05 '15 15:10 benjamine

@benjamine Just like, when you look at https://github.com/benjamine/jsondiffpatch/commit/d3f454497fbf4fc91ced6631aa718047fe983c04 - then you see not only the changes lines red and green, but you also see some "context lines" (actually this looks like diff -u, whitch defaults to 3 lines of context) Probably a little more cleverness in css could achieve that for the general case…

hungerburg avatar Oct 05 '15 18:10 hungerburg

sorry, I thought you were actually talking of jsondiffpatch CLI, but it seems you're talking about the html formatted diff, I don't get it, isn't this the same as the "show unchanged values" checkbox in the demo page: http://benjamine.github.io/jsondiffpatch/demo/index.html ? the difference is you would like to limit it, like 3 lines aroound changes values?

benjamine avatar Feb 14 '16 06:02 benjamine

@benjamine I made a sample screenshot - left, only shows that some capitol changed its name; right also shows, which country its in ;) I.e. there is some context and still hidden most of what did not change.

context-lines-patch

The css is not a generic solution; it has to account for the current stacking depth of the data and might show too much in some or most configurations; Its just something, that works for me.

Hopefully you can now get the idea and see where it might be useful; Otherwise, feel free to close the issue! Thank you again for the valuable piece of software

hungerburg avatar Feb 14 '16 11:02 hungerburg

+1

patricksheehan avatar Nov 16 '16 22:11 patricksheehan

+10086

HyperSimon avatar Feb 22 '17 06:02 HyperSimon

.jsondiffpatch-child-node-type-object .jsondiffpatch-unchanged {
    max-height: none;
}

image

Kamahl19 avatar Aug 25 '19 13:08 Kamahl19