Skip to content

Commit 4316bc7

Browse files
committed
Autocompletion: enable autocompleting "from" and "import".
1 parent b1b4c64 commit 4316bc7

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/main/java/org/scijava/ui/swing/script/autocompletion/AutocompletionProvider.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public boolean isValidChar(final char c) {
5050
}
5151

5252
static private final Pattern
53-
fromImport = Pattern.compile("^(from[ \\t]+)([a-zA-Z][a-zA-Z0-9._]*)$"),
53+
fromImport = Pattern.compile("^((from|import)[ \\t]+)([a-zA-Z][a-zA-Z0-9._]*)$"),
5454
fastImport = Pattern.compile("^(from[ \\t]+)([a-zA-Z][a-zA-Z0-9._]*)[ \\t]+$"),
5555
importStatement = Pattern.compile("^((from[ \\t]+([a-zA-Z0-9._]+)[ \\t]+|[ \\t]*)import(Class\\(|[ \\t]+))([a-zA-Z0-9_., \\t]*)$"),
5656
simpleClassName = Pattern.compile("^(.*[ \\t]+|)([A-Z_][a-zA-Z0-9_]+)$"),
@@ -72,15 +72,15 @@ public List<Completion> getCompletionsImpl(final JTextComponent comp) {
7272
// E.g. "from ij" to expand to a package name and class like ij or ij.gui or ij.plugin
7373
final Matcher m1 = fromImport.matcher(text);
7474
if (m1.find())
75-
return asCompletionList(ClassUtil.findClassNamesContaining(m1.group(2))
75+
return asCompletionList(ClassUtil.findClassNamesContaining(m1.group(3))
7676
.map(new Function<String, String>() {
7777
@Override
7878
public final String apply(final String s) {
7979
final int idot = s.lastIndexOf('.');
80-
return s.substring(0, Math.max(0, idot)) + " import " + s.substring(idot +1);
80+
return "from " + s.substring(0, Math.max(0, idot)) + " import " + s.substring(idot +1);
8181
}
8282
}),
83-
m1.group(1));
83+
"");
8484

8585
final Matcher m1f = fastImport.matcher(text);
8686
if (m1f.find())

0 commit comments

Comments
 (0)