From 5b95a692ab1d6a909b865aad0f62fc0389fcc929 Mon Sep 17 00:00:00 2001 From: Mickael Istria Date: Tue, 18 Sep 2018 21:53:27 +0200 Subject: Bug 539199 - All proposal filtered triggers new completion request Change-Id: I2a70986d1a3cbc261d24682cbedf61537d8d9589 Signed-off-by: Mickael Istria --- .../contentassist/CompletionProposalPopup.java | 16 +++++++++-- .../jface/text/contentassist/ContentAssistant.java | 32 ++++++++++++---------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposalPopup.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposalPopup.java index 7d077f2bb07..c60a3ec6f16 100644 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposalPopup.java +++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposalPopup.java @@ -355,9 +355,10 @@ class CompletionProposalPopup implements IContentAssistListener { int offset= fContentAssistSubjectControlAdapter.getSelectedRange().x; List proposals= null; + DocumentEvent event= null; try { if (offset > -1) { - DocumentEvent event= TextUtilities.mergeProcessedDocumentEvents(fDocumentEvents); + event= TextUtilities.mergeProcessedDocumentEvents(fDocumentEvents); proposals= computeFilteredProposals(offset, event); } } catch (BadLocationException x) { @@ -368,8 +369,19 @@ class CompletionProposalPopup implements IContentAssistListener { if (proposals != null && proposals.size() > 0) setProposals(proposals, fIsFilteredSubset); - else + else { hide(); + if (fContentAssistant.isAutoActivation() && offset > 0 && event != null) { + try { + char charBeforeOffset= event.getDocument().getChar(offset - 1); + if (fContentAssistant.isAutoActivationTriggerChar(charBeforeOffset)) { + fContentAssistant.fireSessionBeginEvent(true); + showProposals(true); + } + } catch (BadLocationException e) { + } + } + } } }; /** diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistant.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistant.java index 7c614d561d2..2e3ed84a799 100644 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistant.java +++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistant.java @@ -323,7 +323,7 @@ public class ContentAssistant implements IContentAssistant, IContentAssistantExt // Only act on characters that are trigger candidates. This // avoids computing the model selection on every keystroke - if (computeAllAutoActivationTriggers().indexOf(e.character) < 0) { + if (!isAutoActivationTriggerChar(e.character)) { stop(); return; } @@ -935,7 +935,8 @@ public class ContentAssistant implements IContentAssistant, IContentAssistantExt private Closer fCloser; LayoutManager fLayoutManager; - private AutoAssistListener fAutoAssistListener; + + AutoAssistListener fAutoAssistListener; private InternalListener fInternalListener; private CompletionProposalPopup fProposalPopup; private ContextInformationPopup fContextInfoPopup; @@ -1183,27 +1184,26 @@ public class ContentAssistant implements IContentAssistant, IContentAssistantExt } /** - * Computes the sorted set of all auto activation trigger characters. - * - * @return the sorted set of all auto activation trigger characters - * @since 3.1 + * @return whether the given char is an auto-activation trigger char + * @since 3.15 */ - private String computeAllAutoActivationTriggers() { + boolean isAutoActivationTriggerChar(char c) { if (fProcessors == null) - return ""; //$NON-NLS-1$ + return false; - StringBuilder buf= new StringBuilder(5); for (Set processorsForContentType : fProcessors.values()) { for (IContentAssistProcessor processor : processorsForContentType) { char[] triggers= processor.getCompletionProposalAutoActivationCharacters(); - if (triggers != null) - buf.append(triggers); + if (triggers != null && new String(triggers).indexOf(c) >= 0) { + return true; + } triggers= processor.getContextInformationAutoActivationCharacters(); - if (triggers != null) - buf.append(triggers); + if (triggers != null && new String(triggers).indexOf(c) >= 0) { + return true; + } } } - return buf.toString(); + return false; } /** @@ -2783,4 +2783,8 @@ public class ContentAssistant implements IContentAssistant, IContentAssistantExt public void enableCompletionProposalTriggerChars(boolean enable) { fCompletionProposalTriggerCharsEnabled= enable; } + + boolean isAutoActivation() { + return fIsAutoActivated; + } } -- cgit v1.2.3