Inline Edit: Correctly handle browser resizing

Compute the height of CodeMirror based on the browser height,
and disable page level scrolling. This prevents duplicate
vertical scroll bars on the right hand side.

Change-Id: I6d77a3a6e88a6fc6490a7cb62cb00f52366af328
This commit is contained in:
Shawn Pearce
2015-01-01 20:34:43 -05:00
parent 4ef96edfdc
commit 520eec0938
4 changed files with 45 additions and 20 deletions

View File

@@ -268,12 +268,10 @@ public class SideBySide2 extends Screen {
}
});
final int height = getCodeMirrorHeight();
operation(new Runnable() {
@Override
public void run() {
cmA.setHeight(height);
cmB.setHeight(height);
resizeCodeMirror();
chunkManager.adjustPadding();
cmA.refresh();
cmB.refresh();
@@ -297,6 +295,7 @@ public class SideBySide2 extends Screen {
if (startSide != null && startLine > 0) {
int line = startLine - 1;
CodeMirror cm = getCmFromSide(startSide);
int height = cm.getHeight();
if (cm.lineAtHeight(height - 20) < line) {
cm.scrollToY(cm.heightAtLine(line, "local") - 0.5 * height);
}
@@ -977,17 +976,9 @@ public class SideBySide2 extends Screen {
}
void resizeCodeMirror() {
int height = getCodeMirrorHeight();
cmA.setHeight(height);
cmB.setHeight(height);
}
private int getCodeMirrorHeight() {
int rest = Gerrit.getHeaderFooterHeight()
+ header.getOffsetHeight()
+ diffTable.getHeaderHeight()
+ 5; // Estimate
return Window.getClientHeight() - rest;
int hdr = header.getOffsetHeight() + diffTable.getHeaderHeight();
cmA.adjustHeight(hdr);
cmB.adjustHeight(hdr);
}
void syncScroll(DisplaySide masterSide) {

View File

@@ -15,6 +15,7 @@
package com.google.gerrit.client.editor;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.JumpKeys;
import com.google.gerrit.client.VoidResult;
import com.google.gerrit.client.account.DiffPreferences;
import com.google.gerrit.client.changes.ChangeApi;
@@ -33,6 +34,9 @@ import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.KeyPressEvent;
import com.google.gwt.event.logical.shared.ResizeEvent;
import com.google.gwt.event.logical.shared.ResizeHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
@@ -58,12 +62,15 @@ public class EditScreen extends Screen {
private CodeMirror cm;
private String type;
@UiField Element header;
@UiField Element project;
@UiField Element filePath;
@UiField Button cancel;
@UiField Button save;
@UiField Element editor;
private HandlerRegistration resizeHandler;
public EditScreen(Patch.Key patch) {
this.revision = patch.getParentKey();
this.path = patch.get();
@@ -121,12 +128,19 @@ public class EditScreen extends Screen {
@Override
public void onShowView() {
super.onShowView();
Window.enableScrolling(false);
JumpKeys.enable(false);
if (prefs.hideTopMenu()) {
Gerrit.setHeaderVisible(false);
}
int rest = Gerrit.getHeaderFooterHeight()
+ 30; // Estimate
cm.setHeight(Window.getClientHeight() - rest);
resizeHandler = Window.addResizeHandler(new ResizeHandler() {
@Override
public void onResize(ResizeEvent event) {
cm.adjustHeight(header.getOffsetHeight());
}
});
cm.adjustHeight(header.getOffsetHeight());
cm.refresh();
cm.focus();
}
@@ -134,7 +148,15 @@ public class EditScreen extends Screen {
@Override
protected void onUnload() {
super.onUnload();
if (cm != null) {
cm.getWrapperElement().removeFromParent();
}
if (resizeHandler != null) {
resizeHandler.removeHandler();
}
Window.enableScrolling(true);
Gerrit.setHeaderVisible(true);
JumpKeys.enable(true);
}
@UiHandler("save")

View File

@@ -62,7 +62,7 @@ limitations under the License.
}
</ui:style>
<g:HTMLPanel>
<div class='{style.headerLine}'>
<div class='{style.headerLine}' ui:field='header'>
<div class='{style.headerButtons}'>
<g:Button ui:field='cancel'
styleName=''

View File

@@ -14,11 +14,13 @@
package net.codemirror.lib;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.diff.DisplaySide;
import com.google.gerrit.client.rpc.CallbackGroup;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import net.codemirror.lib.TextMarker.FromTo;
@@ -63,9 +65,19 @@ public class CodeMirror extends JavaScriptObject {
public final native void setValue(String v) /*-{ this.setValue(v) }-*/;
public final native void setWidth(double w) /*-{ this.setSize(w, null) }-*/;
public final native void setWidth(String w) /*-{ this.setSize(w, null) }-*/;
public final native void setHeight(double h) /*-{ this.setSize(null, h) }-*/;
public final native void setHeight(String h) /*-{ this.setSize(null, h) }-*/;
public final int getHeight() {
return getWrapperElement().getClientHeight();
}
public final void adjustHeight(int localHeader) {
int rest = Gerrit.getHeaderFooterHeight()
+ localHeader
+ 5; // Estimate
setHeight(Window.getClientHeight() - rest);
}
public final native String getLine(int n) /*-{ return this.getLine(n) }-*/;
public final native double barHeight() /*-{ return this.display.barHeight }-*/;
public final native double barWidth() /*-{ return this.display.barWidth }-*/;