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:
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user