MCPcopy Create free account
hub / github.com/editablejs/editable / toggleListIndent

Function toggleListIndent

packages/plugins/indent/src/plugin/with-indent.tsx:47–129  ·  view source on GitHub ↗
(
  editor: Editor,
  entry: NodeEntry<List>,
  size: number,
  mode: IndentMode = 'auto',
)

Source from the content-addressed store, hash-verified

45}
46
47const toggleListIndent = (
48 editor: Editor,
49 entry: NodeEntry<List>,
50 size: number,
51 mode: IndentMode = 'auto',
52) => {
53 if (!IndentEditor.isIndentEditor(editor)) return
54 if (!IndentEditor.canSetIndent(editor, 'line')) {
55 IndentEditor.insertIndent(editor)
56 return
57 }
58 const isSub = size < 0
59 let [list, path] = entry
60 const { key, type } = list
61 const isTop = List.isFirstList(editor, {
62 path,
63 key,
64 type,
65 })
66 // 如果是列表的开头,则更新所有后代的缩进
67 if (isTop) {
68 IndentEditor.addLineIndent(editor, path, isSub)
69 let next: NodeEntry<List> | undefined = undefined
70 while (true) {
71 next = Editor.next(editor, {
72 at: path,
73 match: n => editor.isList(n) && n.type === type && n.key === key,
74 })
75 if (!next) break
76 path = next[1]
77 IndentEditor.addLineIndent(editor, path, isSub)
78 if (isSub) {
79 const level = List.getLevel(editor, { path, key: key, type, node: next[0] })
80 Transforms.setNodes<List>(
81 editor,
82 { level },
83 {
84 at: path,
85 },
86 )
87 }
88 }
89 if (isSub) {
90 List.updateStart(editor, {
91 path,
92 key,
93 type,
94 })
95 }
96 }
97 // 非开头缩进
98 else {
99 // 减去缩进
100 if (isSub) {
101 toggleNormalIndent(editor, size, mode)
102 } else {
103 toggleNormalIndent(editor, size, 'line')
104 }

Callers 1

toggleIndentFunction · 0.85

Calls 1

toggleNormalIndentFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…