list 列表
支持有序列表和无序列表的渲染,提供插入有序列表和无序列表的能力
Commands 命令
getList()
获取光标所在的有序列表或者无序列表
类型
tsgetList(options: ListOptionsType): KNode | null
详细信息
提供一个入参,类型为
ListOptionsType
,包含 2 个属性:- ordered boolean:是否有序列表
- listType OrderedListType | UnorderListType:列表序标类型,如果是有序列表,取值范围是
decimal
lower-alpha
upper-alpha
lower-roman
upper-roman
lower-greek
cjk-ideographic
,如果是无序列表,可取值是disc
circle
square
该方法可以获取光标所在的唯一指定的列表节点,如果光标不在一个该指定节点内,则返回
null
示例
ts//获取序标值为lower-alpha的有序列表 const listNode = editor.commands.getList({ ordered: true, listType: 'lower-alpha' })
hasList()
判断光标范围内是否有指定的列表
类型
tshasList(options: ListOptionsType): boolean
详细信息
提供一个入参,类型为
ListOptionsType
,包含 2 个属性:- ordered boolean:是否有序列表
- listType OrderedListType | UnorderListType:列表序标类型,如果是有序列表,取值范围是
decimal
lower-alpha
upper-alpha
lower-roman
upper-roman
lower-greek
cjk-ideographic
,如果是无序列表,可取值是disc
circle
square
该方法用来判断光标范围内是否有指定的列表节点,返回
boolean
值示例
ts//判断是否有序标值为lower-alpha的有序列表 const hasList = editor.commands.hasList({ ordered: true, listType: 'lower-alpha' })
allList()
光标范围内是否都是指定的列表节点
类型
tsallList(options: ListOptionsType): boolean
详细信息
提供一个入参,类型为
ListOptionsType
,包含 2 个属性:- ordered boolean:是否有序列表
- listType OrderedListType | UnorderListType:列表序标类型,如果是有序列表,取值范围是
decimal
lower-alpha
upper-alpha
lower-roman
upper-roman
lower-greek
cjk-ideographic
,如果是无序列表,可取值是disc
circle
square
该方法用来判断光标范围内都是指定的列表节点,返回
boolean
值示例
ts//判断是否都是序标值为lower-alpha的有序列表 const allList = editor.commands.allList({ ordered: true, listType: 'lower-alpha' })
setList()
设置列表
类型
tssetList(options: ListOptionsType): Promise<void>
详细信息
提供一个入参,类型为
ListOptionsType
,包含 2 个属性:- ordered boolean:是否有序列表
- listType OrderedListType | UnorderListType:列表序标类型,如果是有序列表,取值范围是
decimal
lower-alpha
upper-alpha
lower-roman
upper-roman
lower-greek
cjk-ideographic
,如果是无序列表,可取值是disc
circle
square
该方法会将光标所在的块节点都转为指定的列表节点,在设置完毕后会更新视图和光标的渲染,所以调用该命令你无需主动
updateView
如果通过
allList
判断光标范围内都是同样的列表节点,则不会继续执行示例
tsawait editor.commands.setList({ ordered: true, listType: 'lower-alpha' })
unsetList()
取消列表
类型
tsunsetList(options: ListOptionsType): Promise<void>
详细信息
提供一个入参,类型为
ListOptionsType
,包含 2 个属性:- ordered boolean:是否有序列表
- listType OrderedListType | UnorderListType:列表序标类型,如果是有序列表,取值范围是
decimal
lower-alpha
upper-alpha
lower-roman
upper-roman
lower-greek
cjk-ideographic
,如果是无序列表,可取值是disc
circle
square
该方法会将光标所在的指定的列表都转为段落,在设置完毕后会更新视图和光标的渲染,所以调用该命令你无需主动
updateView
如果通过
allList
判断光标范围内不全是该类型的列表节点,则不会继续执行示例
tsawait editor.commands.unsetList({ ordered: true, listType: 'lower-alpha' })
canCreateInnerList()
光标所在位置是否可以生成内嵌列表
类型
tscanCreateInnerList(): { node: KNode; previousNode: KNode } | null
详细信息
当光标在唯一的一个列表项节点上时,如果该列表项节点前一个节点也是列表项节点,则该节点可以生成一个新的内嵌列表
如果可以生成内嵌列表,该方法返回当前的列表项节点和前一个列表项节点,否则返回
null
示例
tsconst { node, previousNode } = editor.commands.canCreateInnerList()
createInnerList()
生成内嵌列表
类型
tscreateInnerList(): Promise<void>
详细信息
该方法用于在可以生成内嵌列表的情况下,生成一个新的内嵌列表,并更新编辑器视图
在可以生成内嵌列表时,按下
Tab
键会执行该方法示例
tsconst result = editor.commands.canCreateInnerList() if (!!result) { editor.commands.createInnerList() }