From 0fbbbd8ab855cc4ab0ec9cfb5b4f858496304c2d Mon Sep 17 00:00:00 2001 From: Artem Zatsarynnyi Date: Tue, 17 Nov 2015 16:21:33 +0200 Subject: [PATCH] IDEX-3485: hide JS content assist box after switching to another file --- .../orion/client/OrionEditorWidget.java | 13 +++++++ .../client/jso/OrionContentAssistOverlay.java | 34 +++++++++++++++++++ .../orion/client/jso/OrionEditorOverlay.java | 5 +++ 3 files changed, 52 insertions(+) create mode 100644 plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/jso/OrionContentAssistOverlay.java diff --git a/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/OrionEditorWidget.java b/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/OrionEditorWidget.java index 6a159f96d..748ed22cd 100644 --- a/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/OrionEditorWidget.java +++ b/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/OrionEditorWidget.java @@ -39,10 +39,13 @@ import org.eclipse.che.api.promises.client.Operation; import org.eclipse.che.api.promises.client.OperationException; import org.eclipse.che.ide.api.app.AppContext; +import org.eclipse.che.ide.api.event.SelectionChangedEvent; +import org.eclipse.che.ide.api.event.SelectionChangedHandler; import org.eclipse.che.ide.api.text.Region; import org.eclipse.che.ide.api.text.RegionImpl; import org.eclipse.che.ide.api.texteditor.HandlesUndoRedo; import org.eclipse.che.ide.editor.orion.client.jso.OrionCodeEditWidgetOverlay; +import org.eclipse.che.ide.editor.orion.client.jso.OrionContentAssistOverlay; import org.eclipse.che.ide.editor.orion.client.jso.OrionEditorOverlay; import org.eclipse.che.ide.editor.orion.client.jso.OrionEditorViewOverlay; import org.eclipse.che.ide.editor.orion.client.jso.OrionSelectionOverlay; @@ -522,6 +525,16 @@ public void apply(OrionEditorViewOverlay arg) throws OperationException { editorViewOverlay = arg; editorOverlay = arg.getEditor(); + final OrionContentAssistOverlay contentAssist = editorOverlay.getContentAssist(); + eventBus.addHandler(SelectionChangedEvent.TYPE, new SelectionChangedHandler() { + @Override + public void onSelectionChanged(SelectionChangedEvent event) { + if (contentAssist.isActive()) { + contentAssist.deactivate(); + } + } + }); + final OrionTextViewOverlay textView = editorOverlay.getTextView(); keyModeInstances.add(VI, getViKeyMode(moduleHolder.getModule("OrionVi"), textView)); keyModeInstances.add(EMACS, getEmacsKeyMode(moduleHolder.getModule("OrionEmacs"), textView)); diff --git a/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/jso/OrionContentAssistOverlay.java b/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/jso/OrionContentAssistOverlay.java new file mode 100644 index 000000000..91b1cd3d1 --- /dev/null +++ b/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/jso/OrionContentAssistOverlay.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2014-2015 Codenvy, S.A. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Codenvy, S.A. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.ide.editor.orion.client.jso; + +import com.google.gwt.core.client.JavaScriptObject; + +/** + * JavaScript overlay over Orion ContentAssist object. + * + * @author Artem Zatsarynnyy + */ +public class OrionContentAssistOverlay extends JavaScriptObject { + + protected OrionContentAssistOverlay() { + } + + /** Checks whether the content assist is active or not. */ + public final native boolean isActive() /*-{ + return this.isActive(); + }-*/; + + /** Deactivates the content assist. */ + public final native void deactivate() /*-{ + this.deactivate(); + }-*/; +} diff --git a/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/jso/OrionEditorOverlay.java b/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/jso/OrionEditorOverlay.java index 694851f4c..bf4f9e661 100644 --- a/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/jso/OrionEditorOverlay.java +++ b/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/jso/OrionEditorOverlay.java @@ -29,6 +29,11 @@ public final native OrionTextViewOverlay getTextView() /*-{ return this.getTextView(); }-*/; + /** Returns the content assist of the editor. */ + public final native OrionContentAssistOverlay getContentAssist() /*-{ + return this.getContentAssist(); + }-*/; + public final native void focus() /*-{ this.focus(); }-*/;