Skip to content
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

Diff navigation #48

Open
jmls opened this issue Jul 6, 2018 · 8 comments
Open

Diff navigation #48

jmls opened this issue Jul 6, 2018 · 8 comments

Comments

@jmls
Copy link

jmls commented Jul 6, 2018

I was demoing ace-diff when a developer asked if there was any way of navigating the diffs. The example that was loaded had 2 one-line diffs in a 1000 line file - and having to scroll up and down to find it was rather challenging :)

Is there any way of going to "the next diff", or only showing the previous / next lines of code relative to a diff (ie in this case hiding 990 lines of identical code)

@JackuB
Copy link
Collaborator

JackuB commented Jul 31, 2018

Yup, was also thinking about collapsing unchanged parts (~like GitHub does it with PRs). I think that it will have 2 parts:

  1. add a public API to scroll changes in view (with next/prev support)
  2. add an optional UI layer on top with some basic navigation

@JackuB JackuB mentioned this issue Oct 8, 2018
@schweini
Copy link

schweini commented Nov 28, 2018

I just added this to my so-called UI, and it works well:

function scrollToDiff(diffNum)
{
    console.log(differ.diffs);
    var diffs = differ.diffs;

    if ( diffs.length <= diffNum )
    {
        return;
    }
    var lrow = diffs[diffNum].leftStartLine;
    var rrow = diffs[diffNum].rightStartLine;
    
    if ( lrow > 5 )
    {
        lrow -= 5;
    }

    if ( rrow > 5 )
    {
        rrow -= 5;
    }

    differ.getEditors().left.scrollToLine( lrow );
    differ.getEditors().right.scrollToLine( rrow);
}

@moshfeu
Copy link
Collaborator

moshfeu commented Nov 21, 2019

@schweini where did you put this function?
Did you add a ui for the navigation? If so, how the ui knows about the diffNum?

@schweini
Copy link

schweini commented Nov 21, 2019 via email

@knvpkishore
Copy link

Yup, was also thinking about collapsing unchanged parts (~like GitHub does it with PRs). I think that it will have 2 parts:

  1. add a public API to scroll changes in view (with next/prev support)
  2. add an optional UI layer on top with some basic navigation

Could you please suggest me which API need to use to scroll the changes with next & prev buttons.

@knvpkishore
Copy link

Yup, was also thinking about collapsing unchanged parts (~like GitHub does it with PRs). I think that it will have 2 parts:

  1. add a public API to scroll changes in view (with next/prev support)
  2. add an optional UI layer on top with some basic navigation

Could you please suggest me which API need to use to scroll the changes with next & prev buttons.
i am trying to use acediff.getNumDiffs() method, but its giving error as cannot read property length of undefined.

could someone please help me on this.

@moshfeu
Copy link
Collaborator

moshfeu commented Mar 23, 2020

@knvpkishore here is a basic example using @schweini's code

https://codesandbox.io/s/ace-diff-navigate-diffs-ixmw8

@knvpkishore
Copy link

@knvpkishore here is a basic example using @schweini's code

https://codesandbox.io/s/ace-diff-navigate-diffs-ixmw8

Thanks much

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

No branches or pull requests

5 participants