A more generic "splitListItem"

The current implementation checks to see if the grantParent is a specific itemType:

I’ve added a new “checkbox” list type and I found it a little awkward having to create a separate command for splitting checkbox lists (or any other kind of list, also indentation commands, etc.). Foreseeing that others may have run into this, I thought I’d explain my solution:

I fiddled with the code a little bit:

  1. I added list to the node-spec.
declare module "prosemirror-model" {
	interface NodeSpec {
		list?: boolean | null
  1. I simply check that the greatGrandParent is a list and derive the itemType from the grandParent.
		let greatGrandParent = $from.node(-2)
		if (!greatGrandParent.type.spec.list) return false

		let grandParent = $from.node(-1)
		let itemType = grandParent.type
		// if (listItem.type != itemType) return false

I’m curious what you think of this approach @marijn. I think it might make sense for the list concept to be a bit generalized.

Since binding a separate command isn’t all that hard, and most list types can share item types, I don’t think this is a big enough issue to warrant adding another field to node specs for.

Yeah, a good workaround would be to make your own custom nodespecs with list defined, and then re-write some custom commands to take advantage of that.

A notable example of something similar is in prosemirror-tables, which defines a tableRole as part of its table nodespecs, and then uses that internally in commands and utils.