Announcement

Collapse
No announcement yet.

Unable to align similar lines

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unable to align similar lines

    I believe there is a problem in the comparison algorithm that keeps the two following chunks from aligning on line 2

    Code:
    this.GetSelection=function(element){var range=document.selection.createRange();var length=range.text.length;range.moveStart('textedit',-1);cursorPos=range.text.length;return{start:cursorPos-length,end:cursorPos};};this.SetSelection=function(element,start,end){var range=element.createTextRange();range.collapse(true);range.moveStart('character',start);range.moveEnd('character',end-start);range.select();};var OnFocusChanged=(function(thisObj){return function(e){(function(){this.OnFocusChanged(e);}).call(thisObj);};})(this);this.InitializeOnFocusHandler=function(elem){elem.attachEvent("onfocus",OnFocusChanged);};this.OnFocusChanged=function(e){if(this.CanHaveFocus(e.srcElement)){this.CurrentFocusedElement=e.srcElement;OsStartOnChangeChecking(this.CurrentFocusedElement);}
    else{OsStopOnChangeChecking();this.CurrentFocusedElement=null;}};};var OsFocusBackendGecko=function(){OsFocusBaseBackend.call(this);this.base={Initialize:(function(thisObj,oldInitialize){return function(){return oldInitialize.call(thisObj);};})(this,this.Initialize)};this.GetSelection=function(element){return{start:element.selectionStart,end:element.selectionEnd};};this.SetSelection=function(element,start,end){element.setSelectionRange(start,end);};this.Initialize=function(){this.base.Initialize();var OnFocusChanged=(function(thisObj){return function(e){(function(){this.OnFocusChanged(e);}).call(thisObj);};})(this);var OnFocusLost=(function(thisObj){return function(){(function(){this.OnFocusLost();}).call(thisObj);};})(this);var OnDragDrop=(function(thisObj){return function(e){(function(){if(e.target.attributes["onosChange"]!=null)
    e.target.focus();}).call(thisObj);};})(this);document.addEventListener('focus',OnFocusChanged,true);document.addEventListener('blur',OnFocusLost,true);document.addEventListener('dragdrop',OnDragDrop,true);};this.CurrentFocusedElement=null;this.GetCurrentFocusedElement=function(){return this.CurrentFocusedElement;};this.OnFocusChanged=function(e){if(this.CanHaveFocus(e.target)){this.CurrentFocusedElement=e.target;OsStartOnChangeChecking(e.target);}
    else{OsStopOnChangeChecking();this.CurrentFocusedElement=null;}};this.OnFocusLost=function(){OsStopOnChangeChecking();this.CurrentFocusedElement=null;}};osjs(document).ready(function(){if(OsIsIE()){osAjaxBackend=new OsAjaxBackendIFrame();osFocusBackend=new OsFocusBackendIE();}else{osAjaxBackend=new OsAjaxBackendXHR();osFocusBackend=new OsFocusBackendGecko();}
    and

    Code:
    this.GetSelection=function(element){var range=document.selection.createRange();var length=range.text.length;range.moveStart('textedit',-1);cursorPos=range.text.length;return{start:cursorPos-length,end:cursorPos};};this.SetSelection=function(element,start,end){var range=element.createTextRange();range.collapse(true);range.moveStart('character',start);range.moveEnd('character',end-start);range.select();};var OnFocusChanged=(function(thisObj){return function(e){(function(){this.OnFocusChanged(e);}).call(thisObj);};})(this);this.InitializeOnFocusHandler=function(elem){elem.attachEvent("onfocus",OnFocusChanged);};this.OnFocusChanged=function(e){if(this.CanHaveFocus(e.srcElement)){this.CurrentFocusedElement=e.srcElement;OsStartOnChangeChecking(this.CurrentFocusedElement);}
    else{OsStopOnChangeChecking();this.CurrentFocusedElement=null;}};};var OsFocusBackendGecko=function(){OsFocusBaseBackend.call(this);this.base={Initialize:(function(thisObj,oldInitialize){return function(){return oldInitialize.call(thisObj);};})(this,this.Initialize)};this.CurrentFocusedElement=null;this.GetCurrentFocusedElement=function(){return this.CurrentFocusedElement;};this.ClearFocusedElement=function(){this.CurrentFocusedElement=null;}
    this.GetSelection=function(element){return{start:element.selectionStart,end:element.selectionEnd};};this.SetSelection=function(element,start,end){element.setSelectionRange(start,end);};this.Initialize=function(){this.base.Initialize();var OnFocusChanged=(function(thisObj){return function(e){(function(){this.OnFocusChanged(e);}).call(thisObj);};})(this);var OnFocusLost=(function(thisObj){return function(){(function(){this.OnFocusLost();}).call(thisObj);};})(this);var OnDragDrop=(function(thisObj){return function(e){(function(){if(e.target.attributes["onosChange"]!=null)
    e.target.focus();}).call(thisObj);};})(this);document.addEventListener('focus',OnFocusChanged,true);document.addEventListener('blur',OnFocusLost,true);document.addEventListener('dragdrop',OnDragDrop,true);};this.OnFocusChanged=function(e){if(this.CanHaveFocus(e.target)){this.CurrentFocusedElement=e.target;OsStartOnChangeChecking(e.target);}
    else{OsStopOnChangeChecking();this.CurrentFocusedElement=null;}};this.OnFocusLost=function(){OsStopOnChangeChecking();this.CurrentFocusedElement=null;}};osjs(document).ready(function(){if(OsIsIE()){osAjaxBackend=new OsAjaxBackendIFrame();osFocusBackend=new OsFocusBackendIE();}else{osAjaxBackend=new OsAjaxBackendXHR();osFocusBackend=new OsFocusBackendGecko();}
    The change on that line starts only on column 274 so it should align (it does in Araxis, for example).

    Any thoughts? Many thanks in advance.

  • #2
    Those code snippets align on line 2 for me.

    Ensure that the View\File Info pane is visible. Ensure that the detected file format is the same on both sides of the compare. If they are not, you can use the file format dropdown in the File Info pane to make them the same.
    Last edited by Michael Bulgrien; 04-Jan-2010, 01:46 PM.
    BC v4.0.7 build 19761
    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

    Comment


    • #3
      Hi!

      I've checked and they both have the same type, but on my machine they don't line up... I even tried changing them both to Java but to no avail. My version is 3.1.9 build 11282. Have a look at what get when comparing in attach.

      Any guess what else I may be missing, anyone? Cheers.

      Comment


      • #4
        The behavior you're seeing is intentional; I'm not sure why Michael doesn't get the same results. BC detects line similarity, and line 2 to line 3 is a better match than line 2 to line 2 (less different characters). It's been a while since I checked, but I don't think Araxis does the same thing. Can you post a screenshot showing how it handles this?
        Zoë P Scooter Software

        Comment


        • #5
          Sure... here goes (I scrolled the change into view). This is Araxis 2008.3626 so it's not the latest (when our Araxis subscription lapsed I got my company to order BC3 instead ).

          Comment


          • #6
            Thanks. I'm going to stick with my original answer that the behavior is intentional. We look at the overall number of differences in the lines, without giving extra weight to matches at the beginning. Having looked at the comparison myself, I agree with BC's behavior, since it shows an orphan line and a large insert at the beginning. Araxis's behavior shows an orphan line and large mix of adds/deletes/edits between the two line #2's.

            Neither is correct, but since we both do line-by-line comparisons, it has to be one or the other. The best approach would be to compare both difference blocks as a single stream of characters, which would handle differences in line wrapping. That's something we want to do, but we won't have anything soon.
            Zoë P Scooter Software

            Comment


            • #7
              Thanks for the reply.
              I can see what you're saying and I understand that it is a either/or situation. I personally feel that Araxis' match is more natural in this case, but I'll readly admit that the same algorithms may wield better results by BC on other cases.

              Not to hijack my own thread with a totally different subject but this comparison reminded me of another request I've harboured for a while: any chance you could make the "Compare Colors" dialog more flexible? I find the approach of strictly red-on-red and blue-on-blue (albeit with configurable intensities) quite limiting and sometimes I really have to squint on long lines to spot changed characters. I find Araxis ability to mix colours (for example red on green/baby blue) a really great usability enhancement. I'm not one but I would assume that colour-blind people would welcome the flexibility too.

              Comment


              • #8
                Originally posted by Miguel Melo View Post
                I even tried changing them both to Java but to no avail.
                Try Visual Basic Source instead of Java... and use the "Alternate method" of alignment under your session settings.

                I am guessing that you have a grammar rule set up under your default text type. Without any grammar rules defined, line two aligns on my PC with the current version of BC3... however the last two lines on each side of the compare do not align. The Visual Basic file format has well-defined syntax rules that can often improve alignment in script files...especially when the "Alternate method" of alignment is being used. It should work for these files.

                Correction: When I re-tested this compare, I find that BC3 auto aligned line 2 and 3 as originally reported. My apologies for any confusion my posts may have caused.
                Last edited by Michael Bulgrien; 06-Jan-2010, 10:04 AM. Reason: Correction
                BC v4.0.7 build 19761
                ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

                Comment


                • #9
                  Michael:

                  Out of the box, v3.1.9 matches line 2 to line 3. I don't know what custom settings you have, but Miguel is seeing expected behavior, and I've verified that with a fresh install. Also, Visual Basic is definitely not the correct format for these snippets. It's marking everything after the first apostrophe as a comment, which does produce the desired results, but only because the second half of the relevant lines is marked as unimportant.

                  Miguel:

                  Can you use a source code beautifier on your files before comparing them? I tried this one and it did a good job of adding line breaks and tabs, and BC shows a proper comparison of the results. You can create a file format that runs a beautifier before comparing the files, so it will do it automatically, and won't modify your original files. You can even disable it by default so it will only be used if you select it from the file format dropdown. Take a look at the Java source tidied or XML tidied formats on our Add-on formats page for examples.
                  Zoë P Scooter Software

                  Comment


                  • #10
                    Originally posted by Craig View Post
                    Can you use a source code beautifier on your files before comparing them? I tried this one and it did a good job of adding line breaks and tabs, and BC shows a proper comparison of the results. You can create a file format that runs a beautifier before comparing the files, so it will do it automatically, and won't modify your original files.
                    Thanks for the tip! I will certainly look into it as these sorts of things so come in handy (I used to have a xml canonicalizer that I used in Araxis to great effect).

                    However mine really was a more general request (that Javascript was actually explicitly minified by our build procedure - I really could not work like that without going insane ). Sometimes I do get genuinely long lines (XML attributes, generated C# code by our platform etc) and when that happens, the lack of chromatic contrast on the "changed characters inside changes lines" does make eyeballing the differences needlessly harder (even if one can Shift+Ctrl+N through the changes).

                    It would be cool if the changed characters could be set to a totally different colour to their background, rather than just being luminance variations on the same colour hue i.e. have different colour pickers rather than one+2 sliders.

                    Comment


                    • #11
                      Yes, I know that Visual Basic is not the correct format for these files... but sometimes I do try other formats when the "correct" format doesn't seem to be doing a good job. I have to agree with Miguel that it is debateable whether BC3's "intentional" functionality actually results in a "better match" as you've suggested above.

                      The way that BC3 orders these files, if you find the spot in line 2 of the left file where the similarities begin (column 269) and enter a line break to isolate the portion of the line that is the "same" as the other side, you end up with a compare that spans 4 lines with nothing significant matching.

                      On the other hand, if BC3 were to match line 2 with line 2 and you were to remove the line break on the right side to bring in the isolated line, you end up with a much more accurate 3-line compare where everything is aligned correctly with no need for any manual re-alignment.

                      In the English world, we work from top-to-bottom, left-to-right. I strongly believe that there should be an option (session setting) to give heavier weight to matches that occur in that order...
                      Last edited by Michael Bulgrien; 06-Jan-2010, 10:09 AM.
                      BC v4.0.7 build 19761
                      ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

                      Comment


                      • #12
                        Originally posted by Michael Bulgrien View Post
                        In the English world, we work from top-to-bottom, left-to-right. I strongly believe that there should be an option (session setting) to give heavier weight to matches that occur in that order...
                        Other than expanding the statement to "Western world" I fully subscribe Michael's opinion and comments above.

                        Comment


                        • #13
                          In attach is another example (albeit quite simple) of a comparison that would be best served by a weightier top-down algorithm, as discussed on this thread. "this.OnFocusLost" would be better off as a single insertion, rather than the current state of "slicing" stuff from it.
                          Last edited by Miguel Melo; 11-Jan-2010, 11:29 AM.

                          Comment

                          Working...
                          X