preserve selection & caret position when switching between goto popups

This commit is contained in:
peter
2012-07-04 17:49:10 +02:00
parent e2655d5593
commit c03ae530da
2 changed files with 10 additions and 12 deletions
@@ -182,14 +182,6 @@ public abstract class ChooseByNameBase {
mySearchInAnyPlace = Registry.is("ide.goto.middle.matching");
}
public boolean isPreselectInitialText() {
return myPreselectInitialText;
}
public void setPreselectInitialText(boolean preselectInitialText) {
myPreselectInitialText = preselectInitialText;
}
public void setShowListAfterCompletionKeyStroke(boolean showListAfterCompletionKeyStroke) {
myShowListAfterCompletionKeyStroke = showListAfterCompletionKeyStroke;
}
@@ -46,13 +46,12 @@ public class ChooseByNamePopup extends ChooseByNameBase implements ChooseByNameP
private Component myOldFocusOwner = null;
private boolean myShowListForEmptyPattern = false;
private final boolean myMayRequestCurrentWindow;
private final ChooseByNamePopup myOldPopup;
protected ChooseByNamePopup(@Nullable final Project project, final ChooseByNameModel model, ChooseByNameItemProvider provider, final ChooseByNamePopup oldPopup,
@Nullable final String predefinedText, boolean mayRequestOpenInCurrentWindow, int initialIndex) {
super(project, model, provider, oldPopup != null ? oldPopup.getEnteredText() : predefinedText, initialIndex);
if (oldPopup == null && predefinedText != null) {
setPreselectInitialText(true);
}
myOldPopup = oldPopup;
if (oldPopup != null) { //inherit old focus owner
myOldFocusOwner = oldPopup.myPreviouslyFocusedComponent;
}
@@ -69,8 +68,15 @@ public class ChooseByNamePopup extends ChooseByNameBase implements ChooseByNameP
protected void initUI(final Callback callback, final ModalityState modalityState, boolean allowMultipleSelection) {
super.initUI(callback, modalityState, allowMultipleSelection);
//LaterInvocator.enterModal(myTextFieldPanel);
if (myOldPopup != null) {
myTextField.setCaretPosition(myOldPopup.myTextField.getCaretPosition());
}
if (myInitialText != null) {
int selStart = myOldPopup == null ? 0 : myOldPopup.myTextField.getSelectionStart();
int selEnd = myOldPopup == null ? myInitialText.length() : myOldPopup.myTextField.getSelectionEnd();
if (selEnd > selStart) {
myTextField.select(selStart, selEnd);
}
rebuildList(myInitialIndex, 0, null, ModalityState.current(), null);
}
if (myOldFocusOwner != null){