Index: /trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java	(revision 2338)
+++ /trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java	(revision 2339)
@@ -127,13 +127,13 @@
                         return;
                     switch(c) {
-                        case way:
-                            Main.map.mapView.setCursor(cursorJoinWay);
-                            break;
-                        case node:
-                            Main.map.mapView.setCursor(cursorJoinNode);
-                            break;
-                        default:
-                            Main.map.mapView.setCursor(cursorCrosshair);
-                            break;
+                    case way:
+                        Main.map.mapView.setCursor(cursorJoinWay);
+                        break;
+                    case node:
+                        Main.map.mapView.setCursor(cursorJoinNode);
+                        break;
+                    default:
+                        Main.map.mapView.setCursor(cursorCrosshair);
+                        break;
                     }
                 }
@@ -328,4 +328,5 @@
         Collection<OsmPrimitive> selection = ds.getSelected();
         Collection<Command> cmds = new LinkedList<Command>();
+        Collection<OsmPrimitive> newSelection = ds.getSelected();
 
         ArrayList<Way> reuseWays = new ArrayList<Way>(),
@@ -344,7 +345,6 @@
                 // (this is just a convenience option so that people don't
                 // have to switch modes)
-                getCurrentDataSet().setSelected(n);
-                DataSet.fireSelectionChanged(getCurrentDataSet().getSelected());
-                selection = getCurrentDataSet().getSelected();
+                newSelection.clear();
+                newSelection.add(n);
                 // The user explicitly selected a node, so let him continue drawing
                 wayIsFinished = false;
@@ -406,5 +406,5 @@
                     // here so /only/ the new way will be selected after this method finishes.
                     if(alt) {
-                        ds.addSelected(wnew);
+                        newSelection.add(insertPoint.getKey());
                     }
 
@@ -477,4 +477,5 @@
                 // user wants a new way.
                 Way way = alt ? null : (selectedWay != null) ? selectedWay : getWayForNode(n0);
+                Way wayToSelect;
 
                 // Don't allow creation of self-overlapping ways
@@ -494,9 +495,12 @@
                     way.addNode(n0);
                     cmds.add(new AddCommand(way));
+                    wayToSelect = way;
                 } else {
                     int i;
                     if ((i = replacedWays.indexOf(way)) != -1) {
                         way = reuseWays.get(i);
+                        wayToSelect = way;
                     } else {
+                        wayToSelect = way;
                         Way wnew = new Way(way);
                         cmds.add(new ChangeCommand(way, wnew));
@@ -519,6 +523,6 @@
 
                 extendedWay = true;
-                getCurrentDataSet().setSelected(way);
-                DataSet.fireSelectionChanged(ds.getSelected());
+                newSelection.clear();
+                newSelection.add(wayToSelect);
             }
         }
@@ -533,9 +537,8 @@
                 title = tr("Add node into way");
                 for (Way w : reuseWays) {
-                    ds.clearSelection(w);
-                }
-            }
-            getCurrentDataSet().setSelected(n);
-            DataSet.fireSelectionChanged(getCurrentDataSet().getSelected());
+                    newSelection.remove(w);
+                }
+            }
+            newSelection.add(n);
         } else if (!newNode) {
             title = tr("Connect existing way to node");
@@ -552,4 +555,6 @@
             lastUsedNode = n;
         }
+
+        getCurrentDataSet().setSelected(newSelection);
 
         computeHelperLine();
@@ -815,54 +820,54 @@
 
         switch (segs.size()) {
-            case 0:
+        case 0:
+            return;
+        case 2:
+            // This computes the intersection between
+            // the two segments and adjusts the node position.
+            Iterator<Pair<Node,Node>> i = segs.iterator();
+            Pair<Node,Node> seg = i.next();
+            EastNorth A = seg.a.getEastNorth();
+            EastNorth B = seg.b.getEastNorth();
+            seg = i.next();
+            EastNorth C = seg.a.getEastNorth();
+            EastNorth D = seg.b.getEastNorth();
+
+            double u=det(B.east() - A.east(), B.north() - A.north(), C.east() - D.east(), C.north() - D.north());
+
+            // Check for parallel segments and do nothing if they are
+            // In practice this will probably only happen when a way has been duplicated
+
+            if (u == 0) return;
+
+            // q is a number between 0 and 1
+            // It is the point in the segment where the intersection occurs
+            // if the segment is scaled to lenght 1
+
+            double q = det(B.north() - C.north(), B.east() - C.east(), D.north() - C.north(), D.east() - C.east()) / u;
+            EastNorth intersection = new EastNorth(
+                    B.east() + q * (A.east() - B.east()),
+                    B.north() + q * (A.north() - B.north()));
+
+            int snapToIntersectionThreshold
+            = Main.pref.getInteger("edit.snap-intersection-threshold",10);
+
+            // only adjust to intersection if within snapToIntersectionThreshold pixel of mouse click; otherwise
+            // fall through to default action.
+            // (for semi-parallel lines, intersection might be miles away!)
+            if (Main.map.mapView.getPoint(n).distance(Main.map.mapView.getPoint(intersection)) < snapToIntersectionThreshold) {
+                n.setEastNorth(intersection);
                 return;
-            case 2:
-                // This computes the intersection between
-                // the two segments and adjusts the node position.
-                Iterator<Pair<Node,Node>> i = segs.iterator();
-                Pair<Node,Node> seg = i.next();
-                EastNorth A = seg.a.getEastNorth();
-                EastNorth B = seg.b.getEastNorth();
-                seg = i.next();
-                EastNorth C = seg.a.getEastNorth();
-                EastNorth D = seg.b.getEastNorth();
-
-                double u=det(B.east() - A.east(), B.north() - A.north(), C.east() - D.east(), C.north() - D.north());
-
-                // Check for parallel segments and do nothing if they are
-                // In practice this will probably only happen when a way has been duplicated
-
-                if (u == 0) return;
-
-                // q is a number between 0 and 1
-                // It is the point in the segment where the intersection occurs
-                // if the segment is scaled to lenght 1
-
-                double q = det(B.north() - C.north(), B.east() - C.east(), D.north() - C.north(), D.east() - C.east()) / u;
-                EastNorth intersection = new EastNorth(
-                        B.east() + q * (A.east() - B.east()),
-                        B.north() + q * (A.north() - B.north()));
-
-                int snapToIntersectionThreshold
-                = Main.pref.getInteger("edit.snap-intersection-threshold",10);
-
-                // only adjust to intersection if within snapToIntersectionThreshold pixel of mouse click; otherwise
-                // fall through to default action.
-                // (for semi-parallel lines, intersection might be miles away!)
-                if (Main.map.mapView.getPoint(n).distance(Main.map.mapView.getPoint(intersection)) < snapToIntersectionThreshold) {
-                    n.setEastNorth(intersection);
-                    return;
-                }
-
-            default:
-                EastNorth P = n.getEastNorth();
-                seg = segs.iterator().next();
-                A = seg.a.getEastNorth();
-                B = seg.b.getEastNorth();
-                double a = P.distanceSq(B);
-                double b = P.distanceSq(A);
-                double c = A.distanceSq(B);
-                q = (a - b + c) / (2*c);
-                n.setEastNorth(new EastNorth(B.east() + q * (A.east() - B.east()), B.north() + q * (A.north() - B.north())));
+            }
+
+        default:
+            EastNorth P = n.getEastNorth();
+            seg = segs.iterator().next();
+            A = seg.a.getEastNorth();
+            B = seg.b.getEastNorth();
+            double a = P.distanceSq(B);
+            double b = P.distanceSq(A);
+            double c = A.distanceSq(B);
+            q = (a - b + c) / (2*c);
+            n.setEastNorth(new EastNorth(B.east() + q * (A.east() - B.east()), B.north() + q * (A.north() - B.north())));
         }
     }
