Wednesday, February 17, 2010

Split Diff Blocks

Sometimes diff blocks that are labeled as "changed" between two files can be better expressed as an "added" block followed by a "deleted" block. For example, in the diff block shown below, the part in the left file and the part in the right file are entirely different pieces of code:

It can be unsightly and confusing to have such blocks be labeled as "changed", and for this reason we're introducing a Split Block command in the upcoming version 5.0. Here's how it works: right-click within a changed block and select Split Block from the context menu, and the block is split into two separate diff blocks, as shown below.

Note that the order of the resulting blocks depends on whether you select the command from the left pane or the right pane, so right-clicking on the right side and selecting Split Block will result in the deleted block coming first:

Splitting blocks can be especially helpful when you are preparing an HTMLdiff report for somebody else and you want the differences to be displayed as clearly as possible. In this situation, you may also want to fine-tune fuzzy matching settings and/or use manualsynchronization to ensure that all lines within changed blocks are aligned precisely.

In addition to making the difference clearer to see, this feature is useful if you need to copy a changed block while keeping the destination block intact: you can split the block, and then use synchronization buttons to copy a newly created deleted or added block. Note that this is equivalent to using the Add Block from First/Second File to Second/First commands.