Prevent right click from updating cursor position

Prevented right click from updating cursor position using
CodeMirror's "contextmenu" event.

Fixed overflow-x for file comments.

Change-Id: If285f4f64a6d3e796b2f814cd806b3d5d7b0f5cc
This commit is contained in:
Michael Zhou 2013-08-15 16:15:40 -07:00
parent d0856f5979
commit 022fdb5c7b
4 changed files with 44 additions and 6 deletions

View File

@ -21,6 +21,10 @@ import com.google.gerrit.client.diff.SideBySide2.DiffChunkInfo;
import com.google.gerrit.client.diff.SidePanel.GutterWrapper;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.event.dom.client.MouseOutEvent;
import com.google.gwt.event.dom.client.MouseOutHandler;
import com.google.gwt.event.dom.client.MouseOverEvent;
import com.google.gwt.event.dom.client.MouseOverHandler;
import com.google.gwt.user.client.ui.Composite;
import net.codemirror.lib.CodeMirror;
@ -57,6 +61,18 @@ abstract class CommentBox extends Composite {
Configuration.create()
.set("className", DiffTable.style.range()));
}
addDomHandler(new MouseOverHandler() {
@Override
public void onMouseOver(MouseOverEvent event) {
setRangeHighlight(true);
}
}, MouseOverEvent.getType());
addDomHandler(new MouseOutHandler() {
@Override
public void onMouseOut(MouseOutEvent event) {
setRangeHighlight(isOpen());
}
}, MouseOutEvent.getType());
}
@Override

View File

@ -60,12 +60,15 @@ limitations under the License.
.b .diff .CodeMirror-linenumber {
background-color: #9f9;
}
.padding, .fileComment {
.padding, .fileCommentRow {
background-color: #eee;
}
.fileComment {
.fileCommentRow {
line-height: 1;
}
.fileCommentCell {
overflow-x: auto;
}
.a .CodeMirror-vscrollbar {
display: none !important;
}
@ -119,11 +122,11 @@ limitations under the License.
<d:PatchSelectBox2 ui:field='patchSelectBoxB' />
</td>
</tr>
<tr ui:field='fileCommentRow' class='{style.fileComment}'>
<td ui:field='fileCommentCellA'>
<tr ui:field='fileCommentRow' class='{style.fileCommentRow}'>
<td ui:field='fileCommentCellA' class='{style.fileCommentCell}'>
<d:FileCommentPanel ui:field='fileCommentPanelA' />
</td>
<td ui:field='fileCommentCellB'>
<td ui:field='fileCommentCellB' class='{style.fileCommentCell}'>
<d:FileCommentPanel ui:field='fileCommentPanelB' />
</td>
</tr>

View File

@ -68,6 +68,7 @@ import com.google.gwtexpui.user.client.DialogVisibleHandler;
import com.google.gwtexpui.user.client.UserAgent;
import net.codemirror.lib.CodeMirror;
import net.codemirror.lib.CodeMirror.EventHandler;
import net.codemirror.lib.CodeMirror.GutterClickHandler;
import net.codemirror.lib.CodeMirror.LineClassWhere;
import net.codemirror.lib.CodeMirror.LineHandle;
@ -111,6 +112,7 @@ public class SideBySide2 extends Screen {
private CodeMirror cmA;
private CodeMirror cmB;
private CodeMirror lastFocused;
private Timer scrollTimerA;
private Timer scrollTimerB;
private HandlerRegistration resizeHandler;
@ -270,7 +272,19 @@ public class SideBySide2 extends Screen {
};
cm.on("renderLine", resizeLinePadding(getSideFromCm(cm)));
cm.on("viewportChange", adjustGutters(cm));
// TODO: Prevent right click from updating the cursor.
cm.on("focus", new Runnable() {
@Override
public void run() {
lastFocused = cm;
}
});
cm.on("contextmenu", new EventHandler() {
@Override
public void handle(CodeMirror instance, NativeEvent event) {
CodeMirror.setObjectProperty(event, "codemirrorIgnore", true);
lastFocused.focus();
}
});
cm.addKeyMap(KeyMap.create()
.on("'j'", moveCursorDown(cm, 1))
.on("'k'", moveCursorDown(cm, -1))

View File

@ -295,6 +295,11 @@ public class CodeMirror extends JavaScriptObject {
return this.display.scrollbarV;
}-*/;
public static final native void setObjectProperty(JavaScriptObject obj,
String name, boolean value) /*-{
obj[name] = value;
}-*/;
protected CodeMirror() {
}