Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/editor/RepositoryCompletionProcessorTest.java48
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/RepositoryCompletionProcessor.java23
2 files changed, 65 insertions, 6 deletions
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/editor/RepositoryCompletionProcessorTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/editor/RepositoryCompletionProcessorTest.java
index 606ab82bf..646edac84 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/editor/RepositoryCompletionProcessorTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/editor/RepositoryCompletionProcessorTest.java
@@ -114,6 +114,54 @@ public class RepositoryCompletionProcessorTest extends TestCase {
assertEquals(new Point(7, 0), proposal.getSelection(doc));
}
+ public void testComputeCompletionProposalsStar() {
+ TaskTask task1 = addTask("1", "mylyn foo");
+ TaskTask task2 = addTask("2", "mylyn bar");
+
+ RepositoryCompletionProcessor processor = new RepositoryCompletionProcessor(repository);
+ MockTextViewer viewer = new MockTextViewer("my*foo");
+ ICompletionProposal[] proposals = processor.computeCompletionProposals(viewer, 6);
+ assertEquals(1, proposals.length);
+ TaskCompletionProposal proposal = (TaskCompletionProposal) proposals[0];
+ assertEquals(task1, proposal.getTask());
+
+ IDocument doc = viewer.getDocument();
+ proposal.apply(doc);
+ assertEquals("task 1", doc.get());
+ assertEquals(new Point(6, 0), proposal.getSelection(doc));
+
+ viewer = new MockTextViewer("my*bar");
+ proposals = processor.computeCompletionProposals(viewer, 6);
+ assertEquals(1, proposals.length);
+ proposal = (TaskCompletionProposal) proposals[0];
+ assertEquals(task2, proposal.getTask());
+
+ doc = viewer.getDocument();
+ proposal.apply(doc);
+ assertEquals("task 2", doc.get());
+ assertEquals(new Point(6, 0), proposal.getSelection(doc));
+
+ viewer = new MockTextViewer("bar*my");
+ proposals = processor.computeCompletionProposals(viewer, 6);
+ assertEquals(1, proposals.length);
+ proposal = (TaskCompletionProposal) proposals[0];
+ assertEquals(task2, proposal.getTask());
+
+ doc = viewer.getDocument();
+ proposal.apply(doc);
+ assertEquals("task 2", doc.get());
+ assertEquals(new Point(6, 0), proposal.getSelection(doc));
+
+ proposals = processor.computeCompletionProposals(new MockTextViewer("my*"), 3);
+ assertEquals(2, proposals.length);
+
+ proposals = processor.computeCompletionProposals(new MockTextViewer("my*none"), 7);
+ assertEquals(0, proposals.length);
+
+ proposals = processor.computeCompletionProposals(new MockTextViewer("foo*bar"), 7);
+ assertEquals(0, proposals.length);
+ }
+
private TaskTask addTask(String taskId, String summary) {
TaskTask task = TaskTestUtil.createMockTask(taskId);
task.setSummary(summary);
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/RepositoryCompletionProcessor.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/RepositoryCompletionProcessor.java
index 31ecf508e..8fffb96e7 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/RepositoryCompletionProcessor.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/RepositoryCompletionProcessor.java
@@ -204,16 +204,27 @@ public class RepositoryCompletionProcessor implements IContentAssistProcessor {
}
private boolean containsPrefix(ITask task) {
- String needle = prefix.trim();
String haystack = TasksUiInternal.getTaskPrefix(task.getConnectorKind())
+ " " + labelProvider.getText(task); //$NON-NLS-1$
- String[] tokens = haystack.split("\\s"); //$NON-NLS-1$
- for (String token : tokens) {
- if (token.toLowerCase().startsWith(needle)) {
- return true;
+ String[] haystackTokens = haystack.split("\\s"); //$NON-NLS-1$
+ String[] needles = prefix.trim().split("\\*"); //$NON-NLS-1$
+ if (haystackTokens.length == 0 || needles.length == 0) {
+ return false;
+ }
+ // check if all needles are contained in haystack
+ for (String needle : needles) {
+ boolean matched = false;
+ haystack: for (String haystackToken : haystackTokens) {
+ if (haystackToken.toLowerCase().startsWith(needle)) {
+ matched = true;
+ break haystack;
+ }
+ }
+ if (!matched) {
+ return false;
}
}
- return false;
+ return true;
}
private CompletionProposal createSeparator() {

Back to the top