mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
autocompletion lookups should be non-focused and not insert items if the user hasn't focused them explicitly
This commit is contained in:
+1
-1
@@ -25,7 +25,7 @@ import com.intellij.openapi.editor.Editor;
|
||||
*/
|
||||
public class JavadocAutoLookupHandler extends CodeCompletionHandlerBase {
|
||||
public JavadocAutoLookupHandler() {
|
||||
super(CompletionType.BASIC, false);
|
||||
super(CompletionType.BASIC, false, false);
|
||||
}
|
||||
|
||||
protected void doComplete(final int offset1, final int offset2, final CompletionContext context, final FileCopyPatcher dummyIdentifier,
|
||||
|
||||
@@ -93,7 +93,7 @@ public class AutoPopupController implements Disposable {
|
||||
|
||||
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
|
||||
if (condition != null && !condition.value(editor)) return;
|
||||
new CodeCompletionHandlerBase(CompletionType.BASIC, false).invoke(myProject, editor, file);
|
||||
new CodeCompletionHandlerBase(CompletionType.BASIC, false, false).invoke(myProject, editor, file);
|
||||
}
|
||||
};
|
||||
// invoke later prevents cancelling request by keyPressed from the same action
|
||||
|
||||
+4
-2
@@ -75,14 +75,16 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.completion.CodeCompletionHandlerBase");
|
||||
private final CompletionType myCompletionType;
|
||||
private final boolean myInvokedExplicitly;
|
||||
final boolean focusLookup;
|
||||
|
||||
public CodeCompletionHandlerBase(final CompletionType completionType) {
|
||||
this(completionType, true);
|
||||
this(completionType, true, true);
|
||||
}
|
||||
|
||||
public CodeCompletionHandlerBase(CompletionType completionType, boolean invokedExplicitly) {
|
||||
public CodeCompletionHandlerBase(CompletionType completionType, boolean invokedExplicitly, boolean focusLookup) {
|
||||
myCompletionType = completionType;
|
||||
myInvokedExplicitly = invokedExplicitly;
|
||||
this.focusLookup = focusLookup;
|
||||
}
|
||||
|
||||
public final void invoke(final Project project, final Editor editor) {
|
||||
|
||||
+1
@@ -97,6 +97,7 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
|
||||
myLookup.setResizable(false);
|
||||
myLookup.setForceLightweightPopup(false);
|
||||
}
|
||||
myLookup.setFocused(handler.focusLookup);
|
||||
|
||||
myLookup.addLookupListener(new LookupAdapter() {
|
||||
public void itemSelected(LookupEvent event) {
|
||||
|
||||
@@ -26,6 +26,11 @@ public class DownHandler extends LookupActionHandler {
|
||||
}
|
||||
|
||||
protected void executeInLookup(final LookupImpl lookup) {
|
||||
ListScrollingUtil.moveDown(lookup.getList(), 0);
|
||||
if (!lookup.isFocused()) {
|
||||
lookup.setFocused(true);
|
||||
lookup.getList().setSelectedIndex(0);
|
||||
} else {
|
||||
ListScrollingUtil.moveDown(lookup.getList(), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,6 +115,10 @@ public class LookupCellRenderer implements ListCellRenderer {
|
||||
boolean isSelected,
|
||||
boolean hasFocus) {
|
||||
|
||||
if (!myLookup.isFocused()) {
|
||||
isSelected = false;
|
||||
}
|
||||
|
||||
final LookupElement item = (LookupElement)value;
|
||||
final Color foreground = isSelected ? SELECTED_FOREGROUND_COLOR : FOREGROUND_COLOR;
|
||||
final Color background = getItemBackground(list, index, isSelected);
|
||||
|
||||
@@ -100,6 +100,7 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable {
|
||||
private boolean myHidden = false;
|
||||
private LookupElement myPreselectedItem = EMPTY_LOOKUP_ITEM;
|
||||
private boolean myDirty;
|
||||
private boolean myFocused;
|
||||
private String myAdditionalPrefix = "";
|
||||
private final AsyncProcessIcon myProcessIcon;
|
||||
private volatile boolean myCalculating;
|
||||
@@ -147,6 +148,14 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable {
|
||||
updateListHeight(model);
|
||||
}
|
||||
|
||||
public boolean isFocused() {
|
||||
return myFocused;
|
||||
}
|
||||
|
||||
public void setFocused(boolean focused) {
|
||||
myFocused = focused;
|
||||
}
|
||||
|
||||
public AsyncProcessIcon getProcessIcon() {
|
||||
return myProcessIcon;
|
||||
}
|
||||
@@ -583,6 +592,8 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable {
|
||||
|
||||
myList.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e){
|
||||
setFocused(true);
|
||||
|
||||
final Point point = e.getPoint();
|
||||
final int i = myList.locationToIndex(point);
|
||||
if (i >= 0) {
|
||||
|
||||
@@ -25,6 +25,8 @@ public class PageDownHandler extends LookupActionHandler {
|
||||
}
|
||||
|
||||
protected void executeInLookup(final LookupImpl lookup) {
|
||||
if (!lookup.isFocused()) return;
|
||||
|
||||
ListScrollingUtil.movePageDown(lookup.getList());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@ public class PageUpHandler extends LookupActionHandler {
|
||||
}
|
||||
|
||||
protected void executeInLookup(final LookupImpl lookup) {
|
||||
if (!lookup.isFocused()) return;
|
||||
|
||||
ListScrollingUtil.movePageUp(lookup.getList());
|
||||
}
|
||||
}
|
||||
|
||||
+2
@@ -39,6 +39,8 @@ public class ShowLookupActionsHandler extends LookupActionHandler {
|
||||
}
|
||||
|
||||
protected void executeInLookup(final LookupImpl lookup) {
|
||||
if (!lookup.isFocused()) return;
|
||||
|
||||
final LookupElement element = lookup.getCurrentItem();
|
||||
if (element == null) {
|
||||
return;
|
||||
|
||||
@@ -64,7 +64,7 @@ public class TypedHandler implements TypedActionHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
if (result == CharFilter.Result.SELECT_ITEM_AND_FINISH_LOOKUP){
|
||||
if (result == CharFilter.Result.SELECT_ITEM_AND_FINISH_LOOKUP && lookup.isFocused()) {
|
||||
LookupElement item = lookup.getCurrentItem();
|
||||
if (item != null){
|
||||
FeatureUsageTracker.getInstance().triggerFeatureUsed(CodeCompletionFeatures.EDITING_COMPLETION_FINISH_BY_DOT_ETC);
|
||||
|
||||
@@ -25,6 +25,8 @@ public class UpHandler extends LookupActionHandler {
|
||||
}
|
||||
|
||||
protected void executeInLookup(final LookupImpl lookup) {
|
||||
if (!lookup.isFocused()) return;
|
||||
|
||||
ListScrollingUtil.moveUp(lookup.getList(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-3
@@ -21,11 +21,9 @@ import com.intellij.codeInsight.lookup.LookupManager;
|
||||
import com.intellij.codeInsight.lookup.impl.LookupImpl;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.actionSystem.Presentation;
|
||||
import com.intellij.openapi.actionSystem.ex.DataConstantsEx;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.actionSystem.EditorAction;
|
||||
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
|
||||
import com.intellij.openapi.project.Project;
|
||||
|
||||
public class ChooseItemAction extends EditorAction {
|
||||
public ChooseItemAction(){
|
||||
@@ -41,6 +39,6 @@ public class ChooseItemAction extends EditorAction {
|
||||
|
||||
public void update(Editor editor, Presentation presentation, DataContext dataContext){
|
||||
LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor);
|
||||
presentation.setEnabled(lookup != null);
|
||||
presentation.setEnabled(lookup != null && lookup.isFocused());
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -43,6 +43,6 @@ public class ChooseItemCompleteStatementAction extends EditorAction {
|
||||
|
||||
public void update(Editor editor, Presentation presentation, DataContext dataContext){
|
||||
LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor);
|
||||
presentation.setEnabled(lookup != null);
|
||||
presentation.setEnabled(lookup != null && lookup.isFocused());
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -42,6 +42,6 @@ public class ChooseItemReplaceAction extends EditorAction {
|
||||
|
||||
public void update(Editor editor, Presentation presentation, DataContext dataContext){
|
||||
LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor);
|
||||
presentation.setEnabled(lookup != null);
|
||||
presentation.setEnabled(lookup != null && lookup.isFocused());
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -25,6 +25,6 @@ public class ClassNameCompleteMacro extends BaseCompleteMacro {
|
||||
}
|
||||
|
||||
CodeInsightActionHandler getCompletionHandler() {
|
||||
return new CodeCompletionHandlerBase(CompletionType.CLASS_NAME, false);
|
||||
return new CodeCompletionHandlerBase(CompletionType.CLASS_NAME, false, true);
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,6 @@ public class CompleteMacro extends BaseCompleteMacro {
|
||||
}
|
||||
|
||||
CodeInsightActionHandler getCompletionHandler() {
|
||||
return new CodeCompletionHandlerBase(CompletionType.BASIC, false);
|
||||
return new CodeCompletionHandlerBase(CompletionType.BASIC, false, true);
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ import com.intellij.xml.util.XmlUtil;
|
||||
*/
|
||||
public class XmlAutoLookupHandler extends CodeCompletionHandlerBase {
|
||||
public XmlAutoLookupHandler() {
|
||||
super(CompletionType.BASIC, false);
|
||||
super(CompletionType.BASIC, false, false);
|
||||
}
|
||||
|
||||
protected void doComplete(final int offset1, final int offset2, final CompletionContext context, final FileCopyPatcher dummyIdentifier, Editor editor,
|
||||
|
||||
Reference in New Issue
Block a user