diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateListPanel.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateListPanel.java index f134d2caf74a..395eb3341066 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateListPanel.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateListPanel.java @@ -614,6 +614,9 @@ public class TemplateListPanel extends JPanel implements Disposable { .setBeanProvider(new NullableFunction() { @Override public DnDDragStartBean fun(DnDActionInfo dnDActionInfo) { + Point point = dnDActionInfo.getPoint(); + if (myTree.getPathForLocation(point.x, point.y) == null) return null; + int selectedIndex = getSelectedIndex(); TemplateImpl template = getTemplate(selectedIndex); return template != null ? new DnDDragStartBean(Pair.create(template, getNode(selectedIndex))) : null; @@ -640,11 +643,12 @@ public class TemplateListPanel extends JPanel implements Disposable { moveTemplate(pair.first, ObjectUtils.assertNotNull(getDropGroup(event)).getName(), pair.second); } }) - .setImageProvider(new Function() { + .setImageProvider(new NullableFunction() { @Override public DnDImage fun(DnDActionInfo dnDActionInfo) { Point point = dnDActionInfo.getPoint(); - return new DnDImage(DnDAwareTree.getDragImage(myTree, myTree.getPathForLocation(point.x, point.y), point).first); + TreePath path = myTree.getPathForLocation(point.x, point.y); + return path == null ? null : new DnDImage(DnDAwareTree.getDragImage(myTree, path, point).first); } }) .install(); diff --git a/platform/platform-impl/src/com/intellij/ide/dnd/aware/DnDAwareTree.java b/platform/platform-impl/src/com/intellij/ide/dnd/aware/DnDAwareTree.java index 7a977d06af11..3957149b1967 100644 --- a/platform/platform-impl/src/com/intellij/ide/dnd/aware/DnDAwareTree.java +++ b/platform/platform-impl/src/com/intellij/ide/dnd/aware/DnDAwareTree.java @@ -66,7 +66,7 @@ public class DnDAwareTree extends Tree implements DnDAware { return this; } - public static Pair getDragImage(Tree dndAwareTree, TreePath path, Point dragOrigin) { + public static Pair getDragImage(Tree dndAwareTree, @NotNull TreePath path, Point dragOrigin) { int row = dndAwareTree.getRowForPath(path); Component comp = dndAwareTree.getCellRenderer().getTreeCellRendererComponent(dndAwareTree, path.getLastPathComponent(), false, true, true, row, false); return createDragImage(dndAwareTree, comp, dragOrigin, true);