Hack to fix scrolling
Essentially doing a setTimeout() to prevent feedback loops. This seems to work fine on Firefox, and has less side effect on Chrome than the previous hack. Change-Id: I2a8d7b910edbbd757479d7b0917c42f0c2155246
This commit is contained in:
@@ -39,6 +39,7 @@ import com.google.gwt.core.client.JavaScriptObject;
|
||||
import com.google.gwt.core.client.JsArray;
|
||||
import com.google.gwt.core.client.JsArrayString;
|
||||
import com.google.gwt.core.client.Scheduler;
|
||||
import com.google.gwt.core.client.Scheduler.RepeatingCommand;
|
||||
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
|
||||
import com.google.gwt.dom.client.Element;
|
||||
import com.google.gwt.dom.client.Style.Unit;
|
||||
@@ -77,7 +78,7 @@ public class SideBySide2 extends Screen {
|
||||
interface Binder extends UiBinder<HTMLPanel, SideBySide2> {}
|
||||
private static Binder uiBinder = GWT.create(Binder.class);
|
||||
|
||||
private static final int HEADER_FOOTER = 60 + 15 * 2 + 38 + 26 * 2;
|
||||
private static final int HEADER_FOOTER = 60 + 15 * 2 + 16 + 26 * 2;
|
||||
private static final JsArrayString EMPTY =
|
||||
JavaScriptObject.createArray().cast();
|
||||
|
||||
@@ -705,18 +706,19 @@ public class SideBySide2 extends Screen {
|
||||
final CodeMirror other = otherCm(cm);
|
||||
return new Runnable() {
|
||||
public void run() {
|
||||
/**
|
||||
* Prevent feedback loop, Chrome seems fine but Firefox chokes.
|
||||
* However on Chrome this may cause scrolling to be out of sync
|
||||
* if scrolled too fast.
|
||||
*/
|
||||
double now = (double) System.currentTimeMillis();
|
||||
if (cm.getScrollSetBy() == other && cm.getScrollSetAt() + 30 > now) {
|
||||
// Hack to prevent feedback loop, Chrome seems fine but Firefox chokes.
|
||||
if (cm.isScrollSetByOther()) {
|
||||
return;
|
||||
}
|
||||
other.scrollToY(cm.getScrollInfo().getTop());
|
||||
other.setScrollSetBy(cm);
|
||||
other.setScrollSetAt(now);
|
||||
other.setScrollSetByOther(true);
|
||||
Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {
|
||||
@Override
|
||||
public boolean execute() {
|
||||
other.setScrollSetByOther(false);
|
||||
return false;
|
||||
}
|
||||
}, 0);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -140,20 +140,12 @@ public class CodeMirror extends JavaScriptObject {
|
||||
return this.getScrollInfo();
|
||||
}-*/;
|
||||
|
||||
public final native CodeMirror getScrollSetBy() /*-{
|
||||
return this.state.scrollSetBy;
|
||||
public final native boolean isScrollSetByOther() /*-{
|
||||
return this.state.scrollSetByOther == true;
|
||||
}-*/;
|
||||
|
||||
public final native void setScrollSetBy(CodeMirror cm) /*-{
|
||||
this.state.scrollSetBy = cm;
|
||||
}-*/;
|
||||
|
||||
public final native double getScrollSetAt() /*-{
|
||||
return this.state.scrollSetAt;
|
||||
}-*/;
|
||||
|
||||
public final native void setScrollSetAt(double when) /*-{
|
||||
this.state.scrollSetAt = when;
|
||||
public final native void setScrollSetByOther(boolean setByOther) /*-{
|
||||
this.state.scrollSetByOther = setByOther;
|
||||
}-*/;
|
||||
|
||||
public final native void on(String event, Runnable thunk) /*-{
|
||||
|
||||
Reference in New Issue
Block a user