From 40ac2f92bf6a3f8e2c25b97dba56b80d62ad3c93 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 29 May 2013 00:30:41 +0200 Subject: [PATCH 1/4] don't cancel autopopup on every write actions that don't change current document (IDEA-100317) --- .../completion/JavaAutoPopupTest.groovy | 25 +++++++++-- .../codeInsight/AutoPopupController.java | 1 + .../completion/CompletionPhase.java | 43 ++++++++++++------- .../CompletionProgressIndicator.java | 17 ++------ .../CompletionAutoPopupHandler.java | 3 +- 5 files changed, 57 insertions(+), 32 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy index ba8f486f735a..226dbfbbc55f 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy @@ -531,7 +531,7 @@ public interface Test { @Override void fillCompletionVariants(CompletionParameters parameters, CompletionResultSet result) { result.runRemainingContributors(parameters, true) - Thread.sleep 1000 + Thread.sleep 500 } } @@ -809,7 +809,6 @@ class Foo { int actions = 4 for (a1 in 0..actions) { - println "a1 = $a1" for (a2 in 0..actions) { myFixture.configureByText("$a1 $a2 .java", src) myFixture.type 'i' @@ -1417,8 +1416,28 @@ class Foo { myFixture.configureByText "a.java", "class Foo {{ }}" myFixture.type('a') joinAutopopup() - type '\n' + type('\n') assert !lookup } + public void "test pressing enter and a letter while autopopup is calculating variants should restart autopopup"() { + registerContributor(LongContributor, LoadingOrder.FIRST) + myFixture.configureByText "a.java", "class Foo {{ }}" + myFixture.type('a') + joinAutopopup() + myFixture.type('\na') + joinCompletion() + assert lookup + } + + public void "test a random write action shouldn't cancel autopopup"() { + registerContributor(LongContributor, LoadingOrder.FIRST) + myFixture.configureByText "a.java", "class Foo {{ }}" + myFixture.type('a') + joinAutopopup() + edt { ApplicationManager.application.runWriteAction {} } + joinCompletion() + assert lookup + } + } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/AutoPopupController.java b/platform/lang-impl/src/com/intellij/codeInsight/AutoPopupController.java index 8cbe33d470dd..70997581164f 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/AutoPopupController.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/AutoPopupController.java @@ -110,6 +110,7 @@ public class AutoPopupController implements Disposable { final CompletionPhase.CommittingDocuments phase = new CompletionPhase.CommittingDocuments(null, editor); CompletionServiceImpl.setCompletionPhase(phase); + phase.ignoreCurrentDocumentChange(); CompletionAutoPopupHandler.runLaterWithCommitted(myProject, editor.getDocument(), new Runnable() { @Override diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionPhase.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionPhase.java index 767ab25e0e9c..afa0aa70f513 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionPhase.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionPhase.java @@ -25,6 +25,9 @@ import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.actionSystem.ex.AnActionListener; import com.intellij.openapi.application.ApplicationAdapter; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.command.CommandAdapter; +import com.intellij.openapi.command.CommandEvent; +import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.editor.*; import com.intellij.openapi.editor.actionSystem.TypedAction; import com.intellij.openapi.editor.event.*; @@ -79,6 +82,7 @@ public abstract class CompletionPhase implements Disposable { private final Editor myEditor; private final Expirable focusStamp; private final Project myProject; + private boolean ignoreDocumentChanges; public CommittingDocuments(@Nullable CompletionProgressIndicator prevIndicator, Editor editor) { super(prevIndicator); @@ -91,6 +95,29 @@ public abstract class CompletionPhase implements Disposable { actionsHappened = true; } }, this); + myEditor.getDocument().addDocumentListener(new DocumentAdapter() { + @Override + public void documentChanged(DocumentEvent e) { + if (!ignoreDocumentChanges) { + actionsHappened = true; + } + } + }, this); + } + + public void ignoreCurrentDocumentChange() { + ignoreDocumentChanges = true; + CommandProcessor.getInstance().addCommandListener(new CommandAdapter() { + @Override + public void commandFinished(CommandEvent event) { + CommandProcessor.getInstance().removeCommandListener(this); + ignoreDocumentChanges = false; + } + }); + } + + public boolean isRestartingCompletion() { + return indicator != null; } public boolean checkExpired() { @@ -108,16 +135,6 @@ public abstract class CompletionPhase implements Disposable { return false; } - public boolean restartCompletion() { - if (indicator != null) { - replaced = true; - indicator.scheduleRestart(); - assert this != CompletionServiceImpl.getCompletionPhase(); - CompletionServiceImpl.assertPhase(CommittingDocuments.class); - } - return replaced; - } - @Override public int newCompletionStarted(int time, boolean repeated) { return time; @@ -156,11 +173,7 @@ public abstract class CompletionPhase implements Disposable { @Override public void beforeWriteActionStart(Object action) { if (!indicator.getLookup().isLookupDisposed() && !indicator.isCanceled()) { - if (indicator.isAutopopupCompletion()) { - indicator.closeAndFinish(true); - } else { - indicator.scheduleRestart(); - } + indicator.scheduleRestart(); } } }, this); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java index 248e31ca685a..ab36b57cf3d4 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java @@ -16,7 +16,6 @@ package com.intellij.codeInsight.completion; -import com.intellij.codeInsight.AutoPopupController; import com.intellij.codeInsight.CodeInsightSettings; import com.intellij.codeInsight.completion.impl.CompletionServiceImpl; import com.intellij.codeInsight.completion.impl.CompletionSorterImpl; @@ -422,9 +421,10 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement CompletionServiceImpl .assertPhase(CompletionPhase.BgCalculation.class, CompletionPhase.ItemsCalculated.class, CompletionPhase.Synchronous.class, CompletionPhase.CommittingDocuments.class); - if (CompletionServiceImpl.getCompletionPhase() instanceof CompletionPhase.CommittingDocuments) { - LOG.assertTrue(CompletionServiceImpl.getCompletionPhase().indicator != null, CompletionServiceImpl.getCompletionPhase()); - ((CompletionPhase.CommittingDocuments)CompletionServiceImpl.getCompletionPhase()).replaced = true; + CompletionPhase oldPhase = CompletionServiceImpl.getCompletionPhase(); + if (oldPhase instanceof CompletionPhase.CommittingDocuments) { + LOG.assertTrue(((CompletionPhase.CommittingDocuments)oldPhase).isRestartingCompletion(), oldPhase); + ((CompletionPhase.CommittingDocuments)oldPhase).replaced = true; } CompletionServiceImpl.setCompletionPhase(CompletionPhase.NoCompletion); if (disposeOffsetMap) { @@ -626,15 +626,6 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement LOG.error(current + "!=" + this); } - if (isAutopopupCompletion() && !myLookup.isShown()) { - if (CompletionServiceImpl.getCompletionService().getCurrentCompletion() == this) { - closeAndFinish(true); - } - - AutoPopupController.getInstance(getProject()).scheduleAutoPopup(myEditor, null); - return; - } - hideAutopopupIfMeaningless(); CompletionPhase oldPhase = CompletionServiceImpl.getCompletionPhase(); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/CompletionAutoPopupHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/CompletionAutoPopupHandler.java index 695849dd173d..598212829633 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/CompletionAutoPopupHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/CompletionAutoPopupHandler.java @@ -50,7 +50,8 @@ public class CompletionAutoPopupHandler extends TypedHandlerDelegate { } - if (oldPhase instanceof CompletionPhase.CommittingDocuments && ((CompletionPhase.CommittingDocuments)oldPhase).restartCompletion()) { + if (oldPhase instanceof CompletionPhase.CommittingDocuments && ((CompletionPhase.CommittingDocuments)oldPhase).isRestartingCompletion()) { + ((CompletionPhase.CommittingDocuments)oldPhase).ignoreCurrentDocumentChange(); return Result.STOP; } From 47f9fe3f69d0e1e47559a5e266c40bc80fa7a13e Mon Sep 17 00:00:00 2001 From: "andrey.zaytsev" Date: Sun, 26 May 2013 18:01:06 +0400 Subject: [PATCH 2/4] registry key for destruction free mode --- .../impl/EditorGutterComponentImpl.java | 40 ++++++++++++++++++- .../src/misc/registry.properties | 1 + 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorGutterComponentImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorGutterComponentImpl.java index 3557df15e1aa..c53be8aa0c76 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorGutterComponentImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorGutterComponentImpl.java @@ -40,12 +40,15 @@ import com.intellij.openapi.editor.colors.EditorColors; import com.intellij.openapi.editor.colors.EditorFontType; import com.intellij.openapi.editor.event.EditorMouseEventArea; import com.intellij.openapi.editor.ex.*; +import com.intellij.openapi.editor.ex.util.EditorUtil; import com.intellij.openapi.editor.markup.*; import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.ui.popup.Balloon; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.SystemInfo; +import com.intellij.openapi.util.registry.Registry; +import com.intellij.openapi.wm.WindowManager; import com.intellij.ui.HintHint; import com.intellij.ui.JBColor; import com.intellij.ui.awt.RelativePoint; @@ -104,6 +107,14 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse installDnD(); } setOpaque(true); + if (Registry.is("editor.distraction.free.mode")) { + editor.getComponent().addComponentListener(new ComponentAdapter(){ + @Override + public void componentResized(ComponentEvent event) { + updateSize(); + } + }); + } } @SuppressWarnings({"ConstantConditions"}) @@ -261,7 +272,8 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse if (w == 0) return; - paintBackground(g, clip, getAnnotationsAreaOffset(), w); + final Color background = Registry.is("editor.distraction.free.mode") ? myEditor.getBackgroundColor() : getBackground(); + paintBackground(g, clip, getAnnotationsAreaOffset(), w, background); Color color = myEditor.getColorsScheme().getColor(EditorColors.ANNOTATIONS_COLOR); g.setColor(color != null ? color : JBColor.blue); @@ -320,7 +332,15 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse } private void paintBackground(final Graphics g, final Rectangle clip, final int x, final int width) { - g.setColor(getBackground()); + paintBackground(g, clip, x, width, getBackground()); + } + + private void paintBackground(final Graphics g, + final Rectangle clip, + final int x, + final int width, + Color background) { + g.setColor(background); g.fillRect(x, clip.y, width, clip.height); paintCaretRowBackground(g, x, width); @@ -527,6 +547,22 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse myTextAnnotationGutterSizes.set(j, gutterSize); myTextAnnotationGuttersSize += gutterSize; } + + if (myEditor.getComponent().isShowing() && Registry.is("editor.distraction.free.mode") && !isMirrored()) { + centerEditorByAnnotationArea(); + } + } + + private void centerEditorByAnnotationArea() { + EditorSettings settings = myEditor.getSettings(); + int editorLocation = (int)myEditor.getComponent().getLocationOnScreen().getX(); + int rightMargin = settings.getRightMargin(myEditor.getProject()); + int rightMarginX = rightMargin * EditorUtil.getSpaceWidth(Font.PLAIN, myEditor) + editorLocation; + + int width = (int)WindowManager.getInstance().getIdeFrame(myEditor.getProject()).getComponent().getSize().getWidth(); + if (rightMarginX < width && editorLocation < width - rightMarginX) { + myTextAnnotationGuttersSize = Math.max(myTextAnnotationGuttersSize, (width - rightMarginX - editorLocation)/2 - myIconsAreaWidth - 10); + } } private TIntObjectHashMap> myLineToGutterRenderers; diff --git a/platform/platform-resources-en/src/misc/registry.properties b/platform/platform-resources-en/src/misc/registry.properties index 828c35a30f45..256ca86a4354 100644 --- a/platform/platform-resources-en/src/misc/registry.properties +++ b/platform/platform-resources-en/src/misc/registry.properties @@ -114,6 +114,7 @@ editor.use.new.tabs=true editor.use.scrollable.tabs=true editor.smarterSelectionQuoting=true editor.skip.copy.and.cut.for.empty.selection=false +editor.distraction.free.mode=false ide.showIndexRebuildMessage=false From 1c6d3151679fc46a42cf7ab5bbfcbecde8523a38 Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Wed, 29 May 2013 00:56:00 +0200 Subject: [PATCH 3/4] Terminal plugin added to community. --- .idea/modules.xml | 1 + plugins/terminal/terminal.iml | 40 +++++++++++++++++++++++++++++++---- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/.idea/modules.xml b/.idea/modules.xml index 7bbc4b80075e..e4277f5195d2 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -134,6 +134,7 @@ + diff --git a/plugins/terminal/terminal.iml b/plugins/terminal/terminal.iml index 554812475d1a..7dc8b2c8f23c 100644 --- a/plugins/terminal/terminal.iml +++ b/plugins/terminal/terminal.iml @@ -9,11 +9,43 @@ - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 29897abd8c0bb8bc834e3319d9d8b16e67ac9ffb Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Wed, 29 May 2013 01:09:27 +0200 Subject: [PATCH 4/4] Names to match names in libLicenses --- plugins/terminal/terminal.iml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/terminal/terminal.iml b/plugins/terminal/terminal.iml index 7dc8b2c8f23c..06ce11afce2a 100644 --- a/plugins/terminal/terminal.iml +++ b/plugins/terminal/terminal.iml @@ -11,7 +11,7 @@ - + @@ -20,7 +20,7 @@ - + @@ -29,7 +29,7 @@ - + @@ -38,7 +38,7 @@ - +