SideBySide2: Fix starting comment by clicking on line number

A race condition surfaced with the CM4 upgrade; clicks on the
line number were moving the cursor out of order with the creation
of the comment box... and the comment box creation depended on
the (new) cursor position to place the box on the line the user
clicked on.

Capture the line number of the click and pass that into the
comment creation, ensuring the comment box always matches up
with the line the user clicked on.

Change-Id: I1a9bdcabc8902d756611b0d6ddd792f94d28fe00
This commit is contained in:
Shawn Pearce
2015-01-07 13:24:05 -08:00
parent 8f180733d8
commit 02ef3f8d74
2 changed files with 5 additions and 9 deletions

View File

@@ -341,14 +341,13 @@ class CommentManager {
@Override
public void run() {
if (cm.extras().hasActiveLine()) {
newDraft(cm);
newDraft(cm, cm.getLineNumber(cm.extras().activeLine()) + 1);
}
}
};
}
private void newDraft(CodeMirror cm) {
int line = cm.getLineNumber(cm.extras().activeLine()) + 1;
void newDraft(CodeMirror cm, int line) {
if (cm.somethingSelected()) {
FromTo fromTo = cm.getSelectedRange();
Pos end = fromTo.to();

View File

@@ -817,21 +817,18 @@ public class SideBySide2 extends Screen {
private GutterClickHandler onGutterClick(final CodeMirror cm) {
return new GutterClickHandler() {
@Override
public void handle(CodeMirror instance, int line, String gutter,
public void handle(CodeMirror instance, final int line, String gutter,
NativeEvent clickEvent) {
if (clickEvent.getButton() == NativeEvent.BUTTON_LEFT
&& !clickEvent.getMetaKey()
&& !clickEvent.getAltKey()
&& !clickEvent.getCtrlKey()
&& !clickEvent.getShiftKey()) {
if (!(cm.extras().hasActiveLine() &&
cm.getLineNumber(cm.extras().activeLine()) == line)) {
cm.setCursor(Pos.create(line));
}
cm.setCursor(Pos.create(line));
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
commentManager.insertNewDraft(cm).run();
commentManager.newDraft(cm, line + 1);
}
});
}