How to display diff manager in order to compare two strings


I would like to open diff manager to compare two string. However I do not know how to do that properly, as the package names differ:

For example:

DiffManager.getInstance().showDiff(openedProjects[0], new SimpleDiffRequest("XXX", new SimpleContent("SSS"), new SimpleContent("DDD"), "AA", "FFF"));
This does not work as SimpleContent extends fromcom.intellij.openapi.diff and SimpleDiffRequest needs com.intellij.diff.contents. Is it a bug?

Comment actions Permalink


There are two diff API in intellij atm. The old one (com.intellij.openapi.diff.*) and the new one (com.intellij.diff.* - IDEA 14.1+, builds 141.*+ ).

Using new API:

import com.intellij.diff.DiffContentFactory;
import com.intellij.diff.DiffManager;
import com.intellij.diff.contents.DocumentContent;
import com.intellij.diff.requests.SimpleDiffRequest;

DocumentContent content1 = DiffContentFactory.getInstance().create(text1);
DocumentContent content2 = DiffContentFactory.getInstance().create(text2);
SimpleDiffRequest request = new SimpleDiffRequest("Window Title", content1, content2, "Title 1", "Title 2");
DiffManager.getInstance().showDiff(project, request);

Using old API:
import com.intellij.openapi.diff.DiffManager;
import com.intellij.openapi.diff.SimpleContent;
import com.intellij.openapi.diff.SimpleDiffRequest;

SimpleDiffRequest request = new SimpleDiffRequest(project, "Window Title");
request.setContents(new SimpleContent(text1), new SimpleContent(text2));
request.setContentTitles("Title 1", "Title 2");
Comment actions Permalink

Is there a way to do this without coding and without creating a file? I want to open diff, copy string 1 on one side, the copy string 2 on other side, without needing to create a new scratch.


Please sign in to leave a comment.