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

Function _delete

packages/models/src/transforms/delete.ts:10–106  ·  view source on GitHub ↗
(editor: Editor, options: TextDeleteOptions = {})

Source from the content-addressed store, hash-verified

8const { delete: defaultDelete } = Transforms
9
10export const _delete = (editor: Editor, options: TextDeleteOptions = {}) => {
11 const { at = editor.selection } = options
12 const { grid, start, end } = findGridOfEdges(editor, at)
13
14 // anchor 与 focus 在同一grid内
15 if (grid) {
16 const sel = Grid.getSelection(editor, grid)
17 const selected = Grid.getSelected(editor, grid, sel)
18 if (sel && selected) {
19 const { allFull, rowFull, colFull, rows, cols } = selected
20 if (allFull) {
21 Grid.remove(editor, grid)
22 } else if (rowFull) {
23 for (let r = rows.length - 1; r >= 0; r--) {
24 Grid.removeRow(editor, grid[1], rows[r])
25 }
26 } else if (colFull) {
27 for (let c = cols.length - 1; c >= 0; c--) {
28 Grid.removeCol(editor, grid[1], cols[c])
29 }
30 } else {
31 // 设置 selection 到 anchor
32 const { start, end } = Grid.edges(editor, grid, sel)
33 const cells = Grid.cells(editor, grid, {
34 startRow: start[0],
35 startCol: start[1],
36 endRow: end[0],
37 endCol: end[1],
38 })
39 // 删除单元格内内容
40 for (const [cell, row, col] of cells) {
41 const path = grid[1].concat([row, col])
42 Transforms.removeNodes(editor, {
43 at: {
44 anchor: {
45 path: path.concat(0),
46 offset: 0,
47 },
48 focus: {
49 path: path.concat(cell.children.length - 1),
50 offset: 0,
51 },
52 },
53 match(node, path) {
54 return !Editor.isGridCell(editor, node)
55 },
56 })
57 }
58 Grid.focus(editor, {
59 at: grid,
60 point: start,
61 })
62 }
63 return
64 }
65 // 设置 selection 到 anchor
66 Transforms.collapse(editor, { edge: 'anchor' })
67 } else {

Callers

nothing calls this directly

Calls 3

findGridOfEdgesFunction · 0.90
removeRowFunction · 0.85
focusMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…