Merge "Implementing event-based scrolling."
This commit is contained in:
commit
60878e7cf1
@ -139,6 +139,9 @@ public class CodeMirrorDemo extends Screen {
|
||||
}
|
||||
}
|
||||
});
|
||||
cmA.on("scroll", doScroll(cmB));
|
||||
cmB.on("scroll", doScroll(cmA));
|
||||
Window.enableScrolling(false);
|
||||
}
|
||||
|
||||
private CodeMirror displaySide(DiffInfo.FileMeta meta, String contents,
|
||||
@ -147,12 +150,12 @@ public class CodeMirrorDemo extends Screen {
|
||||
contents = "";
|
||||
}
|
||||
Configuration cfg = Configuration.create()
|
||||
.set("readOnly", true)
|
||||
.set("readOnly", "nocursor")
|
||||
.set("lineNumbers", true)
|
||||
.set("tabSize", 2)
|
||||
.set("mode", getContentType(meta))
|
||||
.set("value", contents)
|
||||
.setInfinity("viewportMargin");
|
||||
.set("styleSelectedText", true)
|
||||
.set("value", contents);
|
||||
final CodeMirror cm = CodeMirror.create(ele, cfg);
|
||||
cm.setWidth("100%");
|
||||
cm.setHeight(Window.getClientHeight() - HEADER_FOOTER);
|
||||
@ -243,6 +246,15 @@ public class CodeMirrorDemo extends Screen {
|
||||
}
|
||||
}
|
||||
|
||||
public Runnable doScroll(final CodeMirror cm) {
|
||||
final CodeMirror other = cm == cmA ? cmB : cmA;
|
||||
return new Runnable() {
|
||||
public void run() {
|
||||
cm.scrollToY(other.getScrollInfo().getTop());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static String getContentType(DiffInfo.FileMeta meta) {
|
||||
return meta != null && meta.content_type() != null
|
||||
? ModeInjector.getContentType(meta.content_type())
|
||||
|
@ -17,25 +17,13 @@ limitations under the License.
|
||||
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
|
||||
xmlns:g='urn:import:com.google.gwt.user.client.ui'>
|
||||
<ui:style type='com.google.gerrit.client.diff.DiffTable.LineStyle'>
|
||||
@external .CodeMirror, .CodeMirror-selectedtext, .CodeMirror-scroll;
|
||||
@external .CodeMirror-linenumber;
|
||||
|
||||
.difftable .CodeMirror {
|
||||
border: 1px solid #eee;
|
||||
height: auto;
|
||||
}
|
||||
@external .CodeMirror, .CodeMirror-selectedtext;
|
||||
@external .CodeMirror-linenumber, .CodeMirror-vscrollbar;
|
||||
@external .CodeMirror-hscrollbar;
|
||||
.difftable .CodeMirror pre {
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
.difftable .CodeMirror-selectedtext.intraline,
|
||||
.difftable .CodeMirror-selectedtext.insert {
|
||||
opacity: 0.5;
|
||||
}
|
||||
.difftable .CodeMirror-scroll {
|
||||
overflow-x: hidden;
|
||||
overflow-y: hidden;
|
||||
}
|
||||
.a .diff,
|
||||
.a .diff .CodeMirror-linenumber {
|
||||
background-color: #fee;
|
||||
@ -50,9 +38,18 @@ limitations under the License.
|
||||
.b .intraline {
|
||||
background-color: #9f9;
|
||||
}
|
||||
.CodeMirror-selectedtext.diff, .CodeMirror-selectedtext.intraline {
|
||||
background-color: inherit;
|
||||
}
|
||||
.padding {
|
||||
background-color: #eee;
|
||||
}
|
||||
.CodeMirror-hscrollbar {
|
||||
display: none !important;
|
||||
}
|
||||
.a .CodeMirror-vscrollbar {
|
||||
display: none !important;
|
||||
}
|
||||
</ui:style>
|
||||
<g:HTMLPanel styleName='{style.difftable}'>
|
||||
<table>
|
||||
|
@ -33,6 +33,10 @@ public class CodeMirror extends JavaScriptObject {
|
||||
return $wnd.CodeMirror(parent, cfg);
|
||||
}-*/;
|
||||
|
||||
public final native void setOption(String option, boolean value) /*-{
|
||||
this.setOption(option, value);
|
||||
}-*/;
|
||||
|
||||
public final native void setValue(String v) /*-{ this.setValue(v); }-*/;
|
||||
|
||||
public final native void setWidth(int w) /*-{ this.setSize(w, null); }-*/;
|
||||
@ -67,6 +71,24 @@ public class CodeMirror extends JavaScriptObject {
|
||||
this.addLineWidget(line, node, options);
|
||||
}-*/;
|
||||
|
||||
public final native void scrollTo(int x, int y) /*-{
|
||||
this.scrollTo(x, y);
|
||||
}-*/;
|
||||
|
||||
public final native void scrollToY(int y) /*-{
|
||||
this.scrollTo(null, y);
|
||||
}-*/;
|
||||
|
||||
public final native ScrollInfo getScrollInfo() /*-{
|
||||
return this.getScrollInfo();
|
||||
}-*/;
|
||||
|
||||
public final native void on(String event, Runnable thunk) /*-{
|
||||
this.on(event, function() {
|
||||
$entry(thunk.@java.lang.Runnable::run()());
|
||||
});
|
||||
}-*/;
|
||||
|
||||
protected CodeMirror() {
|
||||
}
|
||||
}
|
||||
|
@ -36,9 +36,6 @@ public class Configuration extends JavaScriptObject {
|
||||
public final native Configuration set(String name, boolean val)
|
||||
/*-{ this[name] = val; return this; }-*/;
|
||||
|
||||
public final native Configuration setInfinity(String name)
|
||||
/*-{ this[name] = Infinity; return this; }-*/;
|
||||
|
||||
protected Configuration() {
|
||||
}
|
||||
}
|
||||
|
36
gerrit-gwtui/src/main/java/net/codemirror/lib/ScrollInfo.java
vendored
Normal file
36
gerrit-gwtui/src/main/java/net/codemirror/lib/ScrollInfo.java
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
// Copyright (C) 2013 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package net.codemirror.lib;
|
||||
|
||||
import com.google.gwt.core.client.JavaScriptObject;
|
||||
|
||||
/** {left, top, width, height, clientWidth, clientHeight} objects returned by
|
||||
* getScrollInfo(). */
|
||||
public class ScrollInfo extends JavaScriptObject {
|
||||
public static ScrollInfo create() {
|
||||
return createObject().cast();
|
||||
}
|
||||
|
||||
public final native int getLeft() /*-{ return this.left; }-*/;
|
||||
public final native int getTop() /*-{ return this.top; }-*/;
|
||||
public final native int getWidth() /*-{ return this.width; }-*/;
|
||||
public final native int getHeight() /*-{ return this.height; }-*/;
|
||||
public final native int getClientWidth() /*-{ return this.clientWidth; }-*/;
|
||||
public final native int getClientHeight() /*-{ return this.clientHeight; }-*/;
|
||||
|
||||
|
||||
protected ScrollInfo() {
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user