switchTextType (tx, data) {
    const sel = tx.selection
    /* istanbul ignore next */
    if (!sel.isPropertySelection()) {
      throw new Error('Selection must be a PropertySelection.')
    }
    const containerPath = sel.containerPath
    /* istanbul ignore next */
    if (!containerPath) {
      throw new Error('Selection must be within a container.')
    }
    const path = sel.path
    const nodeId = path[0]
    const node = tx.get(nodeId)
    /* istanbul ignore next */
    if (!(node.isText())) {
      throw new Error('Trying to use switchTextType on a non text node.')
    }
    const newId = uuid(data.type)
    // Note: a TextNode is allowed to have its own way to store the plain-text
    const oldPath = node.getPath()
    console.assert(oldPath.length === 2, 'Currently we assume that TextNodes store the plain-text on the first level')
    const textProp = oldPath[1]
    const newPath = [newId, textProp]
    // create a new node and transfer annotations
    const newNodeData = Object.assign({
      id: newId,
      type: data.type,
      direction: node.direction
    }, data)
    newNodeData[textProp] = node.getText()

    const newNode = tx.create(newNodeData)
    annotationHelpers.transferAnnotations(tx, path, 0, newPath, 0)

    // hide and delete the old one, show the new node
    const pos = getContainerPosition(tx, containerPath, nodeId)
    removeAt(tx, containerPath, pos)
    deepDeleteNode(tx, node)
    insertAt(tx, containerPath, pos, newNode.id)

    tx.setSelection({
      type: 'property',
      path: newPath,
      startOffset: sel.start.offset,
      endOffset: sel.end.offset,
      containerPath
    })

    return newNode
  }
Switch text type for a given node. E.g. from `paragraph` to `heading`.

@param {Object} args object with `selection`, `containerPath` and `data` with new node data
@return {Object} object with updated `selection`

@example

```js
switchTextType(tx, {
  selection: bodyEditor.getSelection(),
 containerPath: bodyEditor.getContainerPath(),
  data: {
    type: 'heading',
    level: 2
 }
})
```