diff --git a/src/main/java/org/gcube/portlets/widgets/pickitem/client/dialog/PickItemsDialog.java b/src/main/java/org/gcube/portlets/widgets/pickitem/client/dialog/PickItemsDialog.java index 11da690..bb9dcd0 100644 --- a/src/main/java/org/gcube/portlets/widgets/pickitem/client/dialog/PickItemsDialog.java +++ b/src/main/java/org/gcube/portlets/widgets/pickitem/client/dialog/PickItemsDialog.java @@ -36,7 +36,7 @@ import com.google.gwt.user.client.ui.Widget; * */ public class PickItemsDialog extends PopupPanel { - + public final static int ARROW_UP = 38; public final static int ARROW_DOWN = 40; @@ -108,15 +108,15 @@ public class PickItemsDialog extends PopupPanel { select(displayIndexSelected); } }); - + focusPanel.addMouseDownHandler(new MouseDownHandler() { @Override public void onMouseDown(MouseDownEvent event) { - handleMouseDown(); + handleMouseDown(); } }); } - + private void handleMouseDown() { SelectableItem ut = (SelectableItem) mainPanel.getWidget(displayIndexSelected); eventBus.fireEvent(new PickedItemEvent(new ItemBean("id", "username", ut.getItemName(), "thumb"), this.triggerChar)); @@ -132,15 +132,19 @@ public class PickItemsDialog extends PopupPanel { * @param currText */ public void onKeyUp(int keyCode, int x, int y, String currText) { - if (currText.endsWith(triggerChar)) { //the only way i found to intercept @ + if (currText.endsWith(triggerChar)) { //the only way i found to intercept the triggerChar setPopupPosition(x, y); hide(); - } else if (currText.contains(triggerChar)) { - if (pickingUser(currText)) { - handleNonCharKeys(keyCode); - } - } else if (!currText.contains(triggerChar)) - hide(); + } + else { + String last3 = (currText.length() > 3) ? currText.substring(currText.length()-3): currText; + if (last3.contains(triggerChar)) { + if (pickingUser(currText)) { + handleNonCharKeys(keyCode); + } + } else if (!last3.contains(triggerChar)) + hide(); + } } /** @@ -148,9 +152,12 @@ public class PickItemsDialog extends PopupPanel { * @param currText the text being typed */ private boolean pickingUser(String currText) { - String[] toSplit = currText.split(triggerChar); //get the interesting part - if (toSplit[1].trim().length() > 0) { - showSuggestions(toSplit[1]); + int tPos = currText.lastIndexOf(triggerChar); + String toSplit = currText.substring(tPos); + String[] splitted = toSplit.split(triggerChar); //get the interesting part + + if (splitted[1].trim().length() > 0) { + showSuggestions(splitted[1]); return true; } hide(); @@ -214,7 +221,7 @@ public class PickItemsDialog extends PopupPanel { }); } } - + private ItemBean getUserModelBySuggestion(Suggestion suggestion) { for (ItemBean user : users) { if (suggestion.getReplacementString().compareTo(user.getAlternativeName()) ==0) @@ -225,7 +232,7 @@ public class PickItemsDialog extends PopupPanel { private Widget getUserTemplate(ItemBean user, int displayIndex, boolean hasPhoto) { if (hasPhoto) - return new WithPhotoTemplate(this, user, displayIndex); + return new WithPhotoTemplate(this, user, displayIndex); return new NoPhotoTemplate(this, user, displayIndex); }