SideBySide2: Fix wrong mode selection after JS loading

Rapid selection of two different modes may cause the wrong one to be
applied in the UI.  Add an additional check after the JavaScript is
loaded to ensure the same mode is still selected.

Change-Id: Iccdf1c05113720893dbfe6b7817ed87d7a1008da
This commit is contained in:
Shawn Pearce
2014-12-31 14:13:15 -05:00
parent a2346d1f0a
commit 0cc1f0551d

View File

@@ -58,6 +58,8 @@ import net.codemirror.mode.ModeInfo;
import net.codemirror.mode.ModeInjector;
import net.codemirror.theme.ThemeLoader;
import java.util.Objects;
/** Displays current diff preferences. */
class PreferencesBox extends Composite {
interface Binder extends UiBinder<HTMLPanel, PreferencesBox> {}
@@ -345,15 +347,15 @@ class PreferencesBox extends Composite {
@UiHandler("mode")
void onMode(@SuppressWarnings("unused") ChangeEvent e) {
String m = mode.getValue(mode.getSelectedIndex());
final String mode = m != null && !m.isEmpty() ? m : null;
final String mode = getSelectedMode();
prefs.syntaxHighlighting(true);
syntaxHighlighting.setValue(true, false);
new ModeInjector().add(mode).inject(new GerritCallback<Void>() {
@Override
public void onSuccess(Void result) {
if (prefs.syntaxHighlighting() && view.isAttached()) {
if (prefs.syntaxHighlighting()
&& Objects.equals(mode, getSelectedMode())
&& view.isAttached()) {
view.operation(new Runnable() {
@Override
public void run() {
@@ -366,6 +368,11 @@ class PreferencesBox extends Composite {
});
}
private String getSelectedMode() {
String m = mode.getValue(mode.getSelectedIndex());
return m != null && !m.isEmpty() ? m : null;
}
@UiHandler("whitespaceErrors")
void onWhitespaceErrors(ValueChangeEvent<Boolean> e) {
prefs.showWhitespaceErrors(e.getValue());