void setProgram2Selection(ProgramSelection newP2Selection) {
		if (primaryProgram == null || primaryProgram != currentProgram || !showingSecondProgram) {
			return;
		}

		// Make sure that the Diff selection is to the code unit boundary.
		ProgramSelection p2CodeUnitSelection =
			new ProgramSelection(DiffUtility.getCodeUnitSet(newP2Selection, secondaryDiffProgram));
		AddressFactory p1AddressFactory =
			(primaryProgram != null) ? primaryProgram.getAddressFactory() : null;
		ProgramSelection intersection =
			new ProgramSelection(p2AddressFactory, p2CodeUnitSelection.intersect(p2DiffHighlight));

		p2Selection = intersection;
		AddressSet p2SelectionAsP1Set =
			DiffUtility.getCompatibleAddressSet(p2Selection, primaryProgram);

		///////////////////////////////////////////
		// Note: the AddressIndexMap in the diff listing wants a P1 selection, because
		// of the MultiListing Layout being used.
		///////////////////////////////////////////

		ProgramSelection p2SelectionAsP1 =
			new ProgramSelection(p1AddressFactory, p2SelectionAsP1Set);
		runSwing(() -> {
			MarkerSet selectionMarkers = getSelectionMarkers();
			selectionMarkers.clearAll();
			selectionMarkers.add(p2Selection);
		});

		diffListingPanel.setSelection(p2SelectionAsP1);
		updatePgm2Enablement();

		if (!SystemUtilities.isEqual(p2SelectionAsP1, currentSelection)) {
			currentSelection = p2SelectionAsP1;
			actionManager.setP1SelectToP2ActionEnabled(
				(secondaryDiffProgram != null) && !currentSelection.isEmpty());
			firePluginEvent(new ProgramSelectionPluginEvent(this.getName(),
				new ProgramSelection(p1AddressFactory, currentSelection), primaryProgram));
		}
	}
Callback when user changes selection in the program2 diff panel.

Note: A P2 selection is handed to this method when a selection is made in the diff listing
which displays P2.
Ghidra/Features/ProgramDiff/src/main/java/ghidra/app/plugin/core/diff/ProgramDiffPlugin.java