Insert new text node at end of content

After the insertContent command runs, I’d like to add a new node below it

I’d like $anchor.depth to be 1 but currently it’s 0 and $anchor.parent.isTextBlock to be true, but currently it’s false

Any ideas how to fix this?

addCommands() {
		return {
			addEmbed: (options) => ({ chain }) => {
				return chain()
					.insertContent({ type: this.name, attrs: {src: options} })
					// .insertContent("")
					// set cursor after embed
					.command(({ tr, dispatch }) => {
						console.log("a")
						if (dispatch) {
							const { $to } = tr.selection
							const posAfter = $to.end()
							console.log("b")

							if ($to.nodeAfter) {
								console.log("c")
								tr.setSelection(TextSelection.create(tr.doc, $to.pos))
							} else {
								console.log("d")
								// add node after embed if it’s the end of the document
								const node = $to.parent.type.contentMatch.defaultType?.create()

								if (node) {
									console.log("e");
									tr.insert(posAfter, node)
									tr.setSelection(TextSelection.create(tr.doc, posAfter))
								}
							}

							
							tr.scrollIntoView()
						}


						const { $anchor, empty } = tr.selection

						console.log($anchor.depth === 1) // false, should be true
						console.log($anchor.parent.isTextblock) // false, should be true
						console.log(!$anchor.parent.type.spec.code) // true
						console.log(!$anchor.parent.textContent) // true


						return true
					})
					.focus()
					.run()
					
			},
		}
	},
})