SideBySide2: Allow CM3 to buffer all updates when rendering
While styling lines with diff markers and inserting comment widgets avoid reflow by running the work inside of an operation() method on each CM3 instance. Change-Id: Ib90dd4a679b74d30c63b51a7e7623babf0a942d7
This commit is contained in:
committed by
Michael Zhou
parent
9e45db10c4
commit
546b3fb2d0
@@ -424,55 +424,72 @@ public class SideBySide2 extends Screen {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private void display(DiffInfo diffInfo) {
|
private void display(final DiffInfo diffInfo) {
|
||||||
cmA = displaySide(diffInfo.meta_a(), diffInfo.text_a(), diffTable.cmA);
|
|
||||||
cmB = displaySide(diffInfo.meta_b(), diffInfo.text_b(), diffTable.cmB);
|
|
||||||
|
|
||||||
skips = new ArrayList<SkippedLine>();
|
skips = new ArrayList<SkippedLine>();
|
||||||
linePaddingOnOtherSideMap = new HashMap<LineHandle, LinePaddingWidgetWrapper>();
|
linePaddingOnOtherSideMap = new HashMap<LineHandle, LinePaddingWidgetWrapper>();
|
||||||
diffChunks = new ArrayList<DiffChunkInfo>();
|
diffChunks = new ArrayList<DiffChunkInfo>();
|
||||||
render(diffInfo);
|
|
||||||
lineActiveBoxMap = new HashMap<LineHandle, CommentBox>();
|
lineActiveBoxMap = new HashMap<LineHandle, CommentBox>();
|
||||||
linePublishedBoxesMap = new HashMap<LineHandle, List<PublishedBox>>();
|
linePublishedBoxesMap = new HashMap<LineHandle, List<PublishedBox>>();
|
||||||
linePaddingManagerMap = new HashMap<LineHandle, PaddingManager>();
|
linePaddingManagerMap = new HashMap<LineHandle, PaddingManager>();
|
||||||
if (publishedBase != null || publishedRevision != null) {
|
if (publishedBase != null || publishedRevision != null) {
|
||||||
publishedMap = new HashMap<String, PublishedBox>();
|
publishedMap = new HashMap<String, PublishedBox>();
|
||||||
}
|
}
|
||||||
if (publishedBase != null) {
|
|
||||||
renderPublished(publishedBase);
|
if (pref.isShowTabs()) {
|
||||||
|
diffTable.addStyleName(DiffTable.style.showtabs());
|
||||||
}
|
}
|
||||||
if (publishedRevision != null) {
|
|
||||||
renderPublished(publishedRevision);
|
cmA = createCodeMirror(diffInfo.meta_a(), diffInfo.text_a(), diffTable.cmA);
|
||||||
}
|
cmB = createCodeMirror(diffInfo.meta_b(), diffInfo.text_b(), diffTable.cmB);
|
||||||
if (draftsBase != null) {
|
|
||||||
renderDrafts(draftsBase);
|
cmA.operation(new Runnable() {
|
||||||
}
|
@Override
|
||||||
if (draftsRevision != null) {
|
public void run() {
|
||||||
renderDrafts(draftsRevision);
|
cmB.operation(new Runnable() {
|
||||||
}
|
@Override
|
||||||
renderSkips();
|
public void run() {
|
||||||
|
// Estimate initial CM3 height, fixed up in onShowView.
|
||||||
|
int height = Window.getClientHeight()
|
||||||
|
- (Gerrit.getHeaderFooterHeight() + 18);
|
||||||
|
cmA.setHeight(height);
|
||||||
|
cmB.setHeight(height);
|
||||||
|
|
||||||
|
render(diffInfo);
|
||||||
|
if (publishedBase != null) {
|
||||||
|
renderPublished(publishedBase);
|
||||||
|
}
|
||||||
|
if (publishedRevision != null) {
|
||||||
|
renderPublished(publishedRevision);
|
||||||
|
}
|
||||||
|
if (draftsBase != null) {
|
||||||
|
renderDrafts(draftsBase);
|
||||||
|
}
|
||||||
|
if (draftsRevision != null) {
|
||||||
|
renderDrafts(draftsRevision);
|
||||||
|
}
|
||||||
|
renderSkips();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
registerCmEvents(cmA);
|
registerCmEvents(cmA);
|
||||||
registerCmEvents(cmB);
|
registerCmEvents(cmB);
|
||||||
|
|
||||||
scrollingGlue = GWT.create(ScrollSynchronizer.class);
|
scrollingGlue = GWT.create(ScrollSynchronizer.class);
|
||||||
scrollingGlue.init(diffTable, cmA, cmB, mapper);
|
scrollingGlue.init(diffTable, cmA, cmB, mapper);
|
||||||
|
|
||||||
resizeHandler = Window.addResizeHandler(new ResizeHandler() {
|
resizeHandler = Window.addResizeHandler(new ResizeHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void onResize(ResizeEvent event) {
|
public void onResize(ResizeEvent event) {
|
||||||
resizeCodeMirror();
|
resizeCodeMirror();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (pref.isShowTabs()) {
|
|
||||||
diffTable.addStyleName(DiffTable.style.showtabs());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private CodeMirror displaySide(DiffInfo.FileMeta meta, String contents,
|
private CodeMirror createCodeMirror(
|
||||||
Element ele) {
|
DiffInfo.FileMeta meta,
|
||||||
if (meta == null) {
|
String contents,
|
||||||
contents = "";
|
Element parent) {
|
||||||
}
|
|
||||||
Configuration cfg = Configuration.create()
|
Configuration cfg = Configuration.create()
|
||||||
.set("readOnly", true)
|
.set("readOnly", true)
|
||||||
.set("cursorBlinkRate", 0)
|
.set("cursorBlinkRate", 0)
|
||||||
@@ -484,17 +501,12 @@ public class SideBySide2 extends Screen {
|
|||||||
.set("styleSelectedText", true)
|
.set("styleSelectedText", true)
|
||||||
.set("showTrailingSpace", pref.isShowWhitespaceErrors())
|
.set("showTrailingSpace", pref.isShowWhitespaceErrors())
|
||||||
.set("keyMap", "vim_ro")
|
.set("keyMap", "vim_ro")
|
||||||
.set("value", contents)
|
.set("value", meta != null ? contents : "");
|
||||||
/**
|
// Without this, CM will put line widgets too far down in the right spot,
|
||||||
* Without this, CM won't put line widgets too far down in the right spot,
|
// and padding widgets will be informed of wrong offset height. Reset to
|
||||||
* and padding widgets will be informed of wrong offset height. Reset to
|
// 10 (default) after initial rendering.
|
||||||
* 10 (default) after initial rendering.
|
cfg.setInfinity("viewportMargin");
|
||||||
*/
|
return CodeMirror.create(parent, cfg);
|
||||||
.setInfinity("viewportMargin");
|
|
||||||
int h = Gerrit.getHeaderFooterHeight() + 18 /* reviewed estimate */;
|
|
||||||
CodeMirror cm = CodeMirror.create(ele, cfg);
|
|
||||||
cm.setHeight(Window.getClientHeight() - h);
|
|
||||||
return cm;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void render(DiffInfo diff) {
|
private void render(DiffInfo diff) {
|
||||||
|
|||||||
Reference in New Issue
Block a user