Index: applications/editors/josm/plugins/wayselector/build.xml
===================================================================
--- applications/editors/josm/plugins/wayselector/build.xml	(revision 20774)
+++ applications/editors/josm/plugins/wayselector/build.xml	(revision 20784)
@@ -31,5 +31,5 @@
 
 	<!-- enter the SVN commit message -->
-	<property name="commit.message" value="Initial release of the Way Selector plugin" />
+	<property name="commit.message" value="Adjust to read-only JOSM selection object" />
 	<!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
 	<property name="plugin.main.version" value="3095" />
Index: applications/editors/josm/plugins/wayselector/src/org/openstreetmap/josm/plugins/wayselector/WaySelection.java
===================================================================
--- applications/editors/josm/plugins/wayselector/src/org/openstreetmap/josm/plugins/wayselector/WaySelection.java	(revision 20774)
+++ applications/editors/josm/plugins/wayselector/src/org/openstreetmap/josm/plugins/wayselector/WaySelection.java	(revision 20784)
@@ -3,4 +3,5 @@
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.TreeSet;
@@ -103,5 +104,6 @@
      @param data the data set in which to extend the selection */
     void extend(DataSet data) {
-        Collection<OsmPrimitive> selection = data.getSelected();
+	Collection<OsmPrimitive> currentSelection;
+	LinkedList<OsmPrimitive> selection;
 	boolean selectionChanged = false;
         Way way;
@@ -110,5 +112,16 @@
 	    return;
 
-	while ((way = findWay(selection)) != null) {
+	currentSelection = data.getSelected();
+
+	way = findWay(currentSelection);
+
+	if (way == null)
+	    return;
+
+	selection = new LinkedList<OsmPrimitive>();
+	for (OsmPrimitive primitive : currentSelection)
+	    selection.add(primitive);
+
+	do {
 	    if (!selection.add(way))
 	        break;
@@ -117,5 +130,7 @@
 	    ways.add(way);
 	    addNodes(way);
-	}
+
+	    way = findWay(selection);
+	} while (way != null);
 
 	if (selectionChanged)
