public Address getNextAddress(Direction direction, List<InstructionMetadata> searchResults) {

		Address currentAddress = searchPlugin.getProgramLocation().getByteAddress();

		// If forward-searching, just find the first address in the given result set that is
		// greater than the current address.  
		//
		// The reason for the getting the CodeUnit is that the instruction might be an off-cut, 
		// and if that's the case, then we can't navigate directly to it.  What we have to do 
		// is find the CodeUnit containing the instruction and navigate to that.
		Program currentProgram = searchPlugin.getCurrentProgram();
		Listing listing = currentProgram.getListing();
		if (direction == Direction.FORWARD) {
			for (InstructionMetadata instr : searchResults) {
				CodeUnit cu = listing.getCodeUnitContaining(instr.getAddr());
				if (cu.getMinAddress().compareTo(currentAddress) > 0) {
					return cu.getMinAddress();
				}
			}
		}

		// If backwards, iterate over the list in reverse order and find the first address in
		// the result set that is one less than the current address. 
		//
		// See above for an explanation for why we need to get the CodeUnit in this block.
		if (direction == Direction.BACKWARD) {
			ListIterator<InstructionMetadata> it = searchResults.listIterator(searchResults.size());
			while (it.hasPrevious()) {
				InstructionMetadata instr = it.previous();
				CodeUnit cu = listing.getCodeUnitContaining(instr.getAddr());
				if (cu.getMinAddress().compareTo(currentAddress) < 0) {
					return cu.getMinAddress();
				}
			}
		}

		return null;
	}
Moves the cursor in the listing to the next search result past, or before (depending on 
the given direction) the current address.

@param direction the direction to search (forward/backward)
@param searchResults the list of instructions to search
@return the address of the next result found
Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/instructionsearch/ui/SearchInstructionsTask.java