@Override
	protected DataTypeComponent replace(int rowIndex, DataType dataType, int length, String name,
			String comment) throws InvalidDataTypeException {
		checkIsAllowableDataType(dataType);
		try {
			DataTypeComponent dtc = null;
			boolean isSelected = selection.containsEntirely(BigInteger.valueOf(rowIndex));
			int diffLen = 0;
			int componentOrdinal = convertRowToOrdinal(rowIndex);

			// FreeForm editing mode (showing Undefined Bytes).
			if (!isPackingEnabled() && !isAtEnd(rowIndex)) {
				int origLen = getComponent(rowIndex).getLength();
				dtc = viewDTM.withTransaction("Replace Component", () -> {
					return viewComposite.replace(componentOrdinal, dataType, length, name, comment);
				});
				diffLen = origLen - dtc.getLength();
				int nextRowIndex = rowIndex + 1;
				if (diffLen < 0) {
					selection.removeRange(nextRowIndex, nextRowIndex - diffLen);
					adjustSelection(nextRowIndex, diffLen);
				}
				else if (diffLen > 0) {
					adjustSelection(nextRowIndex, diffLen);
					if (isSelected) {
						selection.addRange(nextRowIndex, nextRowIndex + diffLen);
					}
				}
				if (rowIndex < currentEditRow) {
					currentEditRow += diffLen;
				}
			}
			else {
				dtc = viewDTM.withTransaction("Replace Component", () -> {
					DataTypeComponent comp = getComponent(rowIndex);
					if (!isPackingEnabled()) {
						// We are at end with packing disabled - grow structure if needed
						int avail = comp.getLength() + getNumUndefinedBytesAfter(comp);
						if (length > avail) {
							viewComposite.growStructure(length - avail);
						}
					}
					return viewComposite.replace(componentOrdinal, dataType, length, name, comment);
				});
			}
			return dtc;
		}
		catch (IllegalArgumentException exc) {
			// NOTE: Use of exception may cause transaction rollback
			throw new InvalidDataTypeException(exc.getMessage());
		}
	}
Returns the number of bytes that are included in the current selection
range.

@param range the range of indices for the component's whose sizes should
be added together.
Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/StructureEditorModel.java