final String foldSpec = Fold.encode(Fold.flatten(docDisplay_.getFolds()));
String oldFoldSpec = sourceDoc_.getFoldSpec();
//String patch = DiffMatchPatch.diff(oldContents, newContents);
SubstringDiff diff = new SubstringDiff(oldContents, newContents);
// Don't auto-save when there are no changes. In addition to being
// wasteful, it causes the server to think the document is dirty.
if (path == null && fileType == null && diff.isEmpty()
&& foldSpec.equals(oldFoldSpec))
{
changesPending_ = false;
return false;
}
if (path == null && fileType == null
&& oldContents.length() == 0
&& newContents.equals("\n"))
{
// This is necessary due to us adding an extra \n to empty
// documents, which we have to do or else CodeMirror starts
// acting funny. If we add the extra \n but don't do this
// check, then reloading the browser causes empty documents
// to appear dirty.
changesPending_ = false;
return false;
}
server_.saveDocumentDiff(
sourceDoc_.getId(),
path,
fileType,
encoding,
foldSpec,
diff.getReplacement(),
diff.getOffset(),
diff.getLength(),
hash,
new ServerRequestCallback<String>()
{
@Override
public void onError(ServerError error)