diff --git a/designer-base/src/main/java/com/fr/design/javascript/JSContentPane.java b/designer-base/src/main/java/com/fr/design/javascript/JSContentPane.java index da0910126e..2ca2d6e66a 100644 --- a/designer-base/src/main/java/com/fr/design/javascript/JSContentPane.java +++ b/designer-base/src/main/java/com/fr/design/javascript/JSContentPane.java @@ -87,22 +87,14 @@ public class JSContentPane extends BasicPane { contentTextArea.addFocusListener(new FocusListener() { @Override public void focusGained(FocusEvent e) { - if (ac == null) { - CompletionProvider provider = createCompletionProvider(); - ac = new AutoCompletion(provider); - String shortCuts = DesignerEnvManager.getEnvManager().getAutoCompleteShortcuts(); - - ac.setTriggerKey(convert2KeyStroke(shortCuts)); - ac.install(contentTextArea); - } + // 获得焦点时 安装 + installAutoCompletion(); } @Override public void focusLost(FocusEvent e) { - if (ac != null) { - ac.uninstall(); - ac = null; - } + // 失去焦点时 卸载 + uninstallAutoCompletion(); } }); @@ -115,6 +107,30 @@ public class JSContentPane extends BasicPane { return KeyStroke.getKeyStroke(ks.replace("+", "pressed")); } + /** + * 注册安装 自动补全监听 + */ + private void installAutoCompletion() { + if (ac == null) { + CompletionProvider provider = createCompletionProvider(); + ac = new AutoCompletion(provider); + String shortCuts = DesignerEnvManager.getEnvManager().getAutoCompleteShortcuts(); + + ac.setTriggerKey(convert2KeyStroke(shortCuts)); + ac.install(contentTextArea); + } + } + + /** + * 卸载移除 自动补全监听 + */ + private void uninstallAutoCompletion() { + if (ac != null) { + ac.uninstall(); + ac = null; + } + } + @Override protected String title4PopupWindow() { return "JS";